diff --git a/player/db/update.c b/player/db/update.c index cb5b1116332cd04ad0a85136b7941fa509c54067..e96f3a9a49910f703d00e315a2eee15c5a8e4e98 100644 --- a/player/db/update.c +++ b/player/db/update.c @@ -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; } diff --git a/player/db/utils.c b/player/db/utils.c new file mode 100644 index 0000000000000000000000000000000000000000..0683fd22b0483b31b677577f84d50687613f0240 --- /dev/null +++ b/player/db/utils.c @@ -0,0 +1,7 @@ +#include "utils.h" + +void +serror(sqlite3 *db, const char *msg) +{ + fprintf(stderr, "%s: %s\n", msg, sqlite3_errmsg(db)); +} diff --git a/player/db/utils.h b/player/db/utils.h new file mode 100644 index 0000000000000000000000000000000000000000..40563bb1d671bff14147bcd09978cb56d1c6cbc3 --- /dev/null +++ b/player/db/utils.h @@ -0,0 +1,7 @@ +#pragma once + +#include <sqlite3.h> +#include <stdio.h> + +void +serror(sqlite3 *db, const char *msg);