Skip to content
Extraits de code Groupes Projets

update db

1 fil de conversation non résolu
Fermé a demandé de fusionner dbupdate vers master
1 fil de conversation non résolu
3 fichiers
+ 23
26
Comparer les modifications
  • Côte à côte
  • En ligne
Fichiers
3
+ 9
26
@@ -7,6 +7,8 @@
#include <string.h>
#include <sys/stat.h>
#include "utils.h"
static const char SQL_LAST_UPDATE[] = "SELECT last_update FROM misc;";
static const char SQL_INSERT_OLD_KARA[] =
"INSERT INTO "
@@ -18,16 +20,6 @@ static const char SQL_INSERT_NEW_KARA[] =
" is_new, author_name) "
"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 *
mallocf(size_t n)
{
@@ -53,13 +45,6 @@ directories_and_files(const struct dirent *entry)
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
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
const char *file_path = filename + prefix;
const char *f = file_path;
category_len = strcspn(f, "/");
if (!strncmp(f, "nouveaux", category_len)) {
if (!strncmp(f, "nouveau", category_len)) {
// "Nouveau" kara, in nouveaux/{pseudo}/{category}/...
f += category_len + 1; // Skip "nouveaux/"
pseudo_len = strcspn(f, "/");
@@ -108,8 +93,6 @@ update_legacy_file(sqlite3 *db, const char *filename, size_t prefix, time_t last
return -1;
}
convert_legacy_category_type(category, category_len, type, type_len);
int status_code = -1;
sqlite3_stmt *stmt = 0;
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
}
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;
}
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;
}
if (sqlite3_bind_text(stmt, 0, category, -1, 0) != SQLITE_OK) {
serror("Failed to bind category");
serror(db, "Failed to bind category");
goto error;
}
if (sqlite3_bind_text(stmt, 0, type, -1, 0) != SQLITE_OK) {
serror("Failed to bind language");
serror(db, "Failed to bind type");
goto error;
}
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;
}
if (sqlite3_step(stmt) != SQLITE_DONE) {
// TODO handle SQLITE_BUSY (should rollback)
serror("Failed to execute insert statement");
serror(db, "Failed to execute insert statement");
goto error;
}
Chargement en cours