aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c182
1 files changed, 91 insertions, 91 deletions
diff --git a/src/data.c b/src/data.c
index e3c0703..55fea88 100644
--- a/src/data.c
+++ b/src/data.c
@@ -6,41 +6,41 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
-#include "collections.h"
+#include "eom.h"
-static gboolean data_check_and_create_database(gchar *data_file);
-static gint data_create_new_database(const gchar *filename);
-static struct collection *data_get_collection_from_stmt(sqlite3_stmt *stmt);
+static gboolean data_check_and_create_database(gchar *data_file);
+static gint data_create_new_database(const gchar *filename);
+static Manga *data_get_manga_from_statement(sqlite3_stmt *stmt);
-GList *data_get_series(void)
+GList *data_get_manga(void)
{
- sqlite3 *database;
+ sqlite3 *database;
sqlite3_stmt *statement;
- gchar *data_file;
- GList *list = NULL;
+ gchar *data_file;
+ GList *list = NULL;
- data_file = collections_get_data_file();
+ data_file = eom_get_data_file();
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
- int res;
- const char *sqlStatement =
- " SELECT id, "
- " name, "
+ int res;
+ const char *sql =
+ " SELECT id, "
+ " name, "
" current_qty, "
- " total_qty "
- " FROM collection "
- " ORDER BY name "
- " COLLATE NOCASE ";
+ " total_qty "
+ " FROM manga "
+ " ORDER BY name "
+ " COLLATE NOCASE ";
res = sqlite3_prepare_v2(database,
- sqlStatement,
- strlen(sqlStatement),
+ sql,
+ strlen(sql),
&statement, NULL);
if (res == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
- struct collection *col = data_get_collection_from_stmt(statement);
- list = g_list_append(list, (gpointer)col);
+ Manga *manga = data_get_manga_from_statement(statement);
+ list = g_list_append(list, (gpointer)manga);
}
}
else
@@ -54,30 +54,30 @@ GList *data_get_series(void)
return list;
}
-struct collection *data_get_series_by_id(gint collection_id)
+Manga *data_get_manga_by_id(gint manga_id)
{
- sqlite3 *database;
- sqlite3_stmt *statement;
- gchar *data_file;
- struct collection *col = NULL;
+ sqlite3 *database;
+ sqlite3_stmt *statement;
+ gchar *data_file;
+ Manga *manga = NULL;
- data_file = collections_get_data_file();
+ data_file = eom_get_data_file();
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
- int res;
+ int res;
const char *sql = g_strdup_printf(
- " SELECT id, "
- " name, "
+ " SELECT id, "
+ " name, "
" current_qty, "
- " total_qty "
- " FROM collection "
- " WHERE id = %d ", collection_id);
+ " total_qty "
+ " FROM manga "
+ " WHERE id = %d ", manga_id);
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
if (res == SQLITE_OK) {
if (sqlite3_step(statement) == SQLITE_ROW) {
- col = data_get_collection_from_stmt(statement);
+ manga = data_get_manga_from_statement(statement);
}
}
sqlite3_finalize(statement);
@@ -85,27 +85,27 @@ struct collection *data_get_series_by_id(gint collection_id)
sqlite3_close(database);
}
- return col;
+ return manga;
}
-gint *data_get_items_by_collection_id(gint collection_id)
+gint *data_get_volumes_by_manga_id(gint manga_id)
{
- gint count;
- gint *volumes;
- sqlite3 *database;
+ gint count;
+ gint *volumes;
+ sqlite3 *database;
sqlite3_stmt *statement;
- gchar *data_file;
+ gchar *data_file;
- data_file = collections_get_data_file();
+ data_file = eom_get_data_file();
count = 0;
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
int res;
const char *sql = g_strdup_printf(
- " SELECT COUNT(id) "
- " FROM items "
- " WHERE collection_id = %d ", collection_id);
+ " SELECT COUNT(number) "
+ " FROM volume "
+ " WHERE collection_id = %d ", manga_id);
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
if (res == SQLITE_OK) {
@@ -117,9 +117,9 @@ gint *data_get_items_by_collection_id(gint collection_id)
if (count > 0) {
sql = g_strdup_printf(
- " SELECT id "
- " FROM items "
- " WHERE collection_id = %d ", collection_id);
+ " SELECT number "
+ " FROM volume "
+ " WHERE collection_id = %d ", manga_id);
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
if (res == SQLITE_OK) {
@@ -136,26 +136,26 @@ gint *data_get_items_by_collection_id(gint collection_id)
return volumes;
}
-gboolean data_add_series(gchar *name, gint total_qty)
+gboolean data_add_manga(gchar *name, gint total_qty)
{
- sqlite3 *database;
+ sqlite3 *database;
sqlite3_stmt *statement;
- gchar *data_file;
- gboolean result;
+ gchar *data_file;
+ gboolean result;
result = FALSE;
- data_file = collections_get_data_file();
+ data_file = eom_get_data_file();
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
- int res;
- const char *sqlStatement =
- g_strdup_printf("INSERT INTO collection (name, current_qty, total_qty) "
- " VALUES ('%s', 0, %d)", name, total_qty);
+ int res;
+ const char *sql = g_strdup_printf(
+ " INSERT INTO manga (name, current_qty, total_qty) "
+ " VALUES ('%s', 0, %d)", name, total_qty);
res = sqlite3_prepare_v2(database,
- sqlStatement,
- strlen(sqlStatement),
+ sql,
+ strlen(sql),
&statement, NULL);
if (res == SQLITE_OK) {
if (sqlite3_step(statement) == SQLITE_DONE)
@@ -169,27 +169,27 @@ gboolean data_add_series(gchar *name, gint total_qty)
return result;
}
-gboolean data_add_to_series(gint collection_id, gint count)
+gboolean data_add_to_manga(gint manga_id, gint count)
{
- sqlite3 *database;
+ sqlite3 *database;
sqlite3_stmt *statement;
- gchar *data_file;
- gboolean result;
+ gchar *data_file;
+ gboolean result;
- data_file = collections_get_data_file();
+ data_file = eom_get_data_file();
result = FALSE;
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
- int res;
- const char *sqlStatement =
- g_strdup_printf("UPDATE collection "
- " SET current_qty = current_qty + %d "
- " WHERE id = %d", count, collection_id);
+ int res;
+ const char *sql = g_strdup_printf(
+ " UPDATE manga "
+ " SET current_qty = current_qty + %d "
+ " WHERE id = %d", count, manga_id);
res = sqlite3_prepare_v2(database,
- sqlStatement,
- strlen(sqlStatement),
+ sql,
+ strlen(sql),
&statement, NULL);
if (res == SQLITE_OK) {
if (sqlite3_step(statement) == SQLITE_DONE)
@@ -220,8 +220,8 @@ static gint data_create_new_database(const gchar *filename)
char *zErrMsg = 0;
int rc;
- if (access(collections_get_config_dir(), R_OK) == -1) {
- if (mkdir(collections_get_config_dir(), S_IRWXU) == -1)
+ if (access(eom_get_config_dir(), R_OK) == -1) {
+ if (mkdir(eom_get_config_dir(), S_IRWXU) == -1)
g_printerr("Can't create directory: %s\n", strerror(errno));
}
@@ -235,30 +235,30 @@ static gint data_create_new_database(const gchar *filename)
}
/* Create collections table */
- rc = sqlite3_exec(db, "CREATE TABLE collection("
+ rc = sqlite3_exec(db, "CREATE TABLE manga("
"id INTEGER PRIMARY KEY,"
"name VARCHAR(100),"
"current_qty INTEGER,"
"total_qty INTEGER"
")", NULL, NULL, &zErrMsg);
if (rc != SQLITE_OK) {
- g_printerr("Can't create collection table: %s\n", zErrMsg);
+ g_printerr("Can't create manga table: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
sqlite3_close(db);
return -1;
}
/* Create items table */
- rc = sqlite3_exec(db, "CREATE TABLE item("
- "collection_id INTEGER,"
- "id INTEGER,"
- "title VARCHAR(100),"
- "PRIMARY KEY(collection_id, id),"
- "FOREIGN KEY(collection_id)"
- " REFERENCES collection(id)"
- ")", NULL, NULL, &zErrMsg);
+ rc = sqlite3_exec(db,
+ " CREATE TABLE volume( "
+ " collection_id INTEGER, "
+ " id INTEGER, "
+ " PRIMARY KEY(collection_id, id), "
+ " FOREIGN KEY(collection_id) "
+ " REFERENCES collection(id)) ",
+ NULL, NULL, &zErrMsg);
if (rc != SQLITE_OK) {
- g_printerr("Can't create item table: %s\n", zErrMsg);
+ g_printerr("Can't create volume table: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
sqlite3_close(db);
return -1;
@@ -268,15 +268,15 @@ static gint data_create_new_database(const gchar *filename)
return 0;
}
-static struct collection *data_get_collection_from_stmt(sqlite3_stmt *stmt)
+static Manga *data_get_manga_from_statement(sqlite3_stmt *stmt)
{
- struct collection *collection =
- (struct collection *)malloc(sizeof(struct collection));
+ Manga *manga =
+ (Manga *)malloc(sizeof(Manga));
- collection->id = sqlite3_column_int(stmt, 0);
- collection->name = g_strdup(sqlite3_column_text(stmt, 1));
- collection->current_qty = sqlite3_column_int(stmt, 2);
- collection->total_qty = sqlite3_column_int(stmt, 3);
+ manga->id = sqlite3_column_int(stmt, 0);
+ manga->name = g_strdup(sqlite3_column_text(stmt, 1));
+ manga->current_qty = sqlite3_column_int(stmt, 2);
+ manga->total_qty = sqlite3_column_int(stmt, 3);
- return collection;
+ return manga;
}