Skip to content
Extraits de code Groupes Projets
Valider b14cc1c2 rédigé par ‮'s avatar :moyai:
Parcourir les fichiers

nouveaux -> nouveau

parent f95a63a3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion!6Resolve "Liste des commandes",!2update db
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "utils.h"
static const char SQL_LAST_UPDATE[] = "SELECT last_update FROM misc;"; static const char SQL_LAST_UPDATE[] = "SELECT last_update FROM misc;";
static const char SQL_INSERT_OLD_KARA[] = static const char SQL_INSERT_OLD_KARA[] =
"INSERT INTO " "INSERT INTO "
...@@ -18,16 +20,6 @@ static const char SQL_INSERT_NEW_KARA[] = ...@@ -18,16 +20,6 @@ static const char SQL_INSERT_NEW_KARA[] =
" is_new, author_name) " " is_new, author_name) "
"VALUES (?, ?, ?, ?, ?, 1, ?)"; "VALUES (?, ?, ?, ?, ?, 1, ?)";
static void
convert_legacy_category_type(const char *category, size_t category_len,
const char *type, size_t type_len);
static void
serror(sqlite3 *db, const char *msg)
{
fprintf(stderr, "%s: %s\n", msg, sqlite3_errmsg(db));
}
static inline void * static inline void *
mallocf(size_t n) mallocf(size_t n)
{ {
...@@ -53,13 +45,6 @@ directories_and_files(const struct dirent *entry) ...@@ -53,13 +45,6 @@ directories_and_files(const struct dirent *entry)
entry->d_name[0] != '.'; entry->d_name[0] != '.';
} }
static void
convert_legacy_category_type(const char *category, size_t category_len,
const char *type, size_t type_len)
{
// TODO convert category and type -> category and language
}
static int static int
update_legacy_file(sqlite3 *db, const char *filename, size_t prefix, time_t last_update) update_legacy_file(sqlite3 *db, const char *filename, size_t prefix, time_t last_update)
{ {
...@@ -83,7 +68,7 @@ update_legacy_file(sqlite3 *db, const char *filename, size_t prefix, time_t last ...@@ -83,7 +68,7 @@ update_legacy_file(sqlite3 *db, const char *filename, size_t prefix, time_t last
const char *file_path = filename + prefix; const char *file_path = filename + prefix;
const char *f = file_path; const char *f = file_path;
category_len = strcspn(f, "/"); category_len = strcspn(f, "/");
if (!strncmp(f, "nouveaux", category_len)) { if (!strncmp(f, "nouveau", category_len)) {
// "Nouveau" kara, in nouveaux/{pseudo}/{category}/... // "Nouveau" kara, in nouveaux/{pseudo}/{category}/...
f += category_len + 1; // Skip "nouveaux/" f += category_len + 1; // Skip "nouveaux/"
pseudo_len = strcspn(f, "/"); pseudo_len = strcspn(f, "/");
...@@ -108,8 +93,6 @@ update_legacy_file(sqlite3 *db, const char *filename, size_t prefix, time_t last ...@@ -108,8 +93,6 @@ update_legacy_file(sqlite3 *db, const char *filename, size_t prefix, time_t last
return -1; return -1;
} }
convert_legacy_category_type(category, category_len, type, type_len);
int status_code = -1; int status_code = -1;
sqlite3_stmt *stmt = 0; sqlite3_stmt *stmt = 0;
const char *sql = pseudo ? SQL_INSERT_NEW_KARA : SQL_INSERT_OLD_KARA; const char *sql = pseudo ? SQL_INSERT_NEW_KARA : SQL_INSERT_OLD_KARA;
...@@ -120,33 +103,33 @@ update_legacy_file(sqlite3 *db, const char *filename, size_t prefix, time_t last ...@@ -120,33 +103,33 @@ update_legacy_file(sqlite3 *db, const char *filename, size_t prefix, time_t last
} }
if (sqlite3_bind_text(stmt, 0, name, name_len, 0) != SQLITE_OK) { if (sqlite3_bind_text(stmt, 0, name, name_len, 0) != SQLITE_OK) {
serror("Failed to bind song_name"); serror(db, "Failed to bind song_name");
goto error; goto error;
} }
if (sqlite3_bind_text(stmt, 0, title, title_len, 0) != SQLITE_OK) { if (sqlite3_bind_text(stmt, 0, title, title_len, 0) != SQLITE_OK) {
serror("Failed to bind song_source"); serror(db, "Failed to bind song_source");
goto error; goto error;
} }
if (sqlite3_bind_text(stmt, 0, category, -1, 0) != SQLITE_OK) { if (sqlite3_bind_text(stmt, 0, category, -1, 0) != SQLITE_OK) {
serror("Failed to bind category"); serror(db, "Failed to bind category");
goto error; goto error;
} }
if (sqlite3_bind_text(stmt, 0, type, -1, 0) != SQLITE_OK) { if (sqlite3_bind_text(stmt, 0, type, -1, 0) != SQLITE_OK) {
serror("Failed to bind language"); serror(db, "Failed to bind type");
goto error; goto error;
} }
if (sqlite3_bind_text(stmt, 0, file_path, -1, 0) != SQLITE_OK) { if (sqlite3_bind_text(stmt, 0, file_path, -1, 0) != SQLITE_OK) {
serror("Failed to bind file_path"); serror(db, "Failed to bind file_path");
goto error; goto error;
} }
if (sqlite3_step(stmt) != SQLITE_DONE) { if (sqlite3_step(stmt) != SQLITE_DONE) {
// TODO handle SQLITE_BUSY (should rollback) // TODO handle SQLITE_BUSY (should rollback)
serror("Failed to execute insert statement"); serror(db, "Failed to execute insert statement");
goto error; goto error;
} }
......
#include "utils.h"
void
serror(sqlite3 *db, const char *msg)
{
fprintf(stderr, "%s: %s\n", msg, sqlite3_errmsg(db));
}
#pragma once
#include <sqlite3.h>
#include <stdio.h>
void
serror(sqlite3 *db, const char *msg);
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter