kill orderdb.[hc] files

This commit is contained in:
Enno Rehling 2018-10-24 09:02:19 +02:00
parent 6738962d73
commit 83959c375f
13 changed files with 39 additions and 154 deletions

View File

@ -117,7 +117,6 @@ set (ERESSEA_SRC
morale.c
move.c
names.c
orderdb.c
orderfile.c
piracy.c
prefix.c
@ -230,7 +229,6 @@ set(TESTS_SRC
monsters.test.c
move.test.c
names.test.c
orderdb.test.c
orderfile.test.c
piracy.test.c
prefix.test.c

View File

@ -28,7 +28,6 @@
#include "creport.h"
#include "report.h"
#include "names.h"
#include "orderdb.h"
#include "reports.h"
#include "spells.h"
#include "vortex.h"

View File

@ -14,15 +14,16 @@ void swapdb_close(void)
db_driver_close(DB_SWAP);
}
dbstring_id db_string_save(const char *s) {
dbrow_id db_string_save(const char *s) {
(void)s;
return 0;
}
dbstring_id dbstring_save(const char *s) {
dbrow_id dbstring_save(const char *s) {
return db_driver_string_save(s);
}
const char *dbstring_load(dbstring_id id, size_t *size) {
const char *dbstring_load(dbrow_id id, size_t *size) {
return db_driver_string_load(id, size);
}

View File

@ -1,11 +1,11 @@
#pragma once
#include <stddef.h>
#include "db/driver.h"
typedef unsigned int dbstring_id;
#include <stddef.h>
void swapdb_open(void);
void swapdb_close(void);
dbstring_id dbstring_save(const char *s);
const char *dbstring_load(dbstring_id id, size_t *size);
dbrow_id dbstring_save(const char *s);
const char *dbstring_load(dbrow_id id, size_t *size);

View File

@ -3,8 +3,8 @@
#include <kernel/faction.h>
#include <kernel/order.h>
#include "database.h"
#include "db/driver.h"
#include "orderdb.h"
#include <CuTest.h>
#include <tests.h>
@ -12,6 +12,17 @@
#include <stdio.h>
#include <string.h>
static void test_orderdb(CuTest *tc) {
order_data *od = NULL;
const char * s = "GIB enno 1 Hodor";
odata_create(&od, strlen(s) + 1, s);
CuAssertPtrNotNull(tc, od);
CuAssertStrEquals(tc, s, od->_str);
CuAssertTrue(tc, od->_refcount >= 1);
odata_release(od);
}
static void test_save_load_order(CuTest *tc) {
order_data *od;
int id;
@ -52,6 +63,7 @@ CuSuite *get_db_suite(void)
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_save_load_order);
SUITE_ADD_TEST(suite, test_update_faction);
SUITE_ADD_TEST(suite, test_orderdb);
return suite;
}

View File

@ -4,6 +4,8 @@
struct order_data;
typedef unsigned int dbrow_id;
extern void odata_create(struct order_data **pdata, size_t len, const char *str);
typedef enum database_t {
@ -13,8 +15,8 @@ typedef enum database_t {
int db_driver_open(database_t db, const char *dbname);
void db_driver_close(database_t db);
int db_driver_order_save(const char *str);
struct order_data *db_driver_order_load(int id);
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password);
unsigned int db_driver_string_save(const char *s);
const char *db_driver_string_load(unsigned int id, size_t *size);
dbrow_id db_driver_order_save(const char *str);
struct order_data *db_driver_order_load(dbrow_id id);
dbrow_id db_driver_faction_save(dbrow_id id, int no, int turn, const char *email, const char *password);
dbrow_id db_driver_string_save(const char *s);
const char *db_driver_string_load(dbrow_id id, size_t *size);

View File

@ -35,7 +35,7 @@ static void end_transaction(void) {
}
}
struct order_data *db_driver_order_load(int id)
struct order_data *db_driver_order_load(dbrow_id id)
{
struct order_data * od = NULL;
int err;
@ -61,7 +61,7 @@ struct order_data *db_driver_order_load(int id)
return NULL;
}
int db_driver_order_save(const char *str) {
dbrow_id db_driver_order_save(const char *str) {
int err;
sqlite3_int64 id;
@ -83,7 +83,7 @@ int db_driver_order_save(const char *str) {
err = sqlite3_step(g_stmt_insert_order);
assert(err == SQLITE_DONE);
id = sqlite3_last_insert_rowid(g_swap_db);
assert(id <= INT_MAX);
assert(id > 0 && id <= UINT_MAX);
if (g_insert_batchsize > 0) {
if (++g_insert_tx_size >= g_insert_batchsize) {
@ -91,11 +91,11 @@ int db_driver_order_save(const char *str) {
}
}
ERRNO_CHECK();
return (int)id;
return (dbrow_id)id;
}
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password)
dbrow_id db_driver_faction_save(dbrow_id id, int no, int turn, const char *email, const char *password)
{
sqlite3_int64 row_id;
int err;
@ -140,8 +140,8 @@ int db_driver_faction_save(int id, int no, int turn, const char *email, const ch
ERRNO_CHECK();
row_id = sqlite3_last_insert_rowid(g_game_db);
assert(row_id <= INT_MAX);
return (int)row_id;
assert(row_id>0 && row_id <= UINT_MAX);
return (dbrow_id)row_id;
}
static int db_open_game(const char *dbname) {
@ -240,7 +240,7 @@ void db_driver_close(database_t db)
ERRNO_CHECK();
}
unsigned int db_driver_string_save(const char *str) {
dbrow_id db_driver_string_save(const char *str) {
int err;
sqlite3_int64 id;
@ -262,7 +262,7 @@ unsigned int db_driver_string_save(const char *str) {
err = sqlite3_step(g_stmt_insert_string);
assert(err == SQLITE_DONE);
id = sqlite3_last_insert_rowid(g_swap_db);
assert(id <= INT_MAX);
assert(id > 0 && id <= UINT_MAX);
if (g_insert_batchsize > 0) {
if (++g_insert_tx_size >= g_insert_batchsize) {
@ -270,10 +270,10 @@ unsigned int db_driver_string_save(const char *str) {
}
}
ERRNO_CHECK();
return (int)id;
return (dbrow_id)id;
}
const char *db_driver_string_load(unsigned int id, size_t *size) {
const char *db_driver_string_load(dbrow_id id, size_t *size) {
int err;
end_transaction();

View File

@ -1,43 +0,0 @@
#include <platform.h>
#include "kernel/config.h"
#include "kernel/db/driver.h"
#include "orderdb.h"
#include <util/log.h>
#include <critbit.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
void orderdb_open(void)
{
const char *dbname;
dbname = config_get("game.dbswap");
db_driver_open(DB_SWAP, dbname);
}
void orderdb_close(void)
{
db_driver_close(DB_SWAP);
}
order_data *odata_load(int id)
{
if (id > 0) {
return db_driver_order_load(id);
}
return NULL;
}
int odata_save(order_data *od)
{
if (od->_str) {
return db_driver_order_save(od->_str);
}
return 0;
}

View File

@ -1,16 +0,0 @@
#ifndef H_ORDERDB
#define H_ORDERDB
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
void orderdb_open(void);
void orderdb_close(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,14 +0,0 @@
#include <platform.h>
#include "kernel/config.h"
#include "orderdb.h"
#include <util/log.h>
#include <critbit.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

View File

@ -1,25 +0,0 @@
#ifndef H_ORDERDB
#define H_ORDERDB
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct order_data {
const char *_str;
int _refcount;
} order_data;
void odata_create(order_data **pdata, size_t len, const char *str);
void odata_release(order_data * od);
void odata_addref(order_data *od);
void orderdb_open(void);
void orderdb_close(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,28 +0,0 @@
#include <platform.h>
#include <kernel/config.h>
#include "orderdb.h"
#include <CuTest.h>
#include <tests.h>
#include <string.h>
static void test_orderdb(CuTest *tc) {
order_data *od = NULL;
const char * s = "GIB enno 1 Hodor";
odata_create(&od, strlen(s) + 1, s);
CuAssertPtrNotNull(tc, od);
CuAssertStrEquals(tc, s, od->_str);
CuAssertTrue(tc, od->_refcount >= 1);
odata_release(od);
}
CuSuite *get_orderdb_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_orderdb);
return suite;
}

View File

@ -138,7 +138,6 @@ int RunAllTests(int argc, char *argv[])
ADD_SUITE(monsters);
ADD_SUITE(move);
ADD_SUITE(names);
ADD_SUITE(orderdb);
ADD_SUITE(orderfile);
ADD_SUITE(otherfaction);
ADD_SUITE(piracy);