ignore sqlite setting errno

This commit is contained in:
Enno Rehling 2018-05-03 22:40:54 +02:00
parent 069047d0ac
commit 5bcd8369af
4 changed files with 36 additions and 26 deletions

View file

@ -26,7 +26,8 @@ order_data *db_driver_order_load(int id)
{ {
order_data * od = NULL; order_data * od = NULL;
int err; int err;
ERRNO_CHECK();
if (g_order_tx_size > 0) { if (g_order_tx_size > 0) {
g_order_tx_size = 0; g_order_tx_size = 0;
err = sqlite3_exec(g_db, "COMMIT", NULL, NULL, NULL); err = sqlite3_exec(g_db, "COMMIT", NULL, NULL, NULL);
@ -45,10 +46,12 @@ order_data *db_driver_order_load(int id)
assert(bytes > 0); assert(bytes > 0);
text = sqlite3_column_text(g_stmt_select, 0); text = sqlite3_column_text(g_stmt_select, 0);
odata_create(&od, 1+(size_t)bytes, (const char *)text); odata_create(&od, 1+(size_t)bytes, (const char *)text);
ERRNO_CHECK();
return od; return od;
} }
} while (err == SQLITE_ROW); } while (err == SQLITE_ROW);
assert(err == SQLITE_DONE); assert(err == SQLITE_DONE);
ERRNO_CHECK();
return NULL; return NULL;
} }
@ -58,7 +61,9 @@ int db_driver_order_save(order_data *od)
sqlite3_int64 id; sqlite3_int64 id;
assert(od && od->_str); assert(od && od->_str);
ERRNO_CHECK();
if (g_order_batchsize > 0) { if (g_order_batchsize > 0) {
if (g_order_tx_size == 0) { if (g_order_tx_size == 0) {
err = sqlite3_exec(g_db, "BEGIN TRANSACTION", NULL, NULL, NULL); err = sqlite3_exec(g_db, "BEGIN TRANSACTION", NULL, NULL, NULL);
@ -82,7 +87,7 @@ int db_driver_order_save(order_data *od)
g_order_tx_size = 0; g_order_tx_size = 0;
} }
} }
ERRNO_CHECK();
return (int)id; return (int)id;
} }
@ -91,6 +96,7 @@ void db_driver_open(void)
int err; int err;
const char *dbname; const char *dbname;
ERRNO_CHECK();
g_order_batchsize = config_get_int("game.dbbatch", 100); g_order_batchsize = config_get_int("game.dbbatch", 100);
dbname = config_get("game.dbname"); dbname = config_get("game.dbname");
if (!dbname) { if (!dbname) {
@ -108,16 +114,20 @@ void db_driver_open(void)
assert(err == SQLITE_OK); assert(err == SQLITE_OK);
err = sqlite3_prepare_v2(g_db, "SELECT data FROM orders WHERE id = ?", -1, &g_stmt_select, NULL); err = sqlite3_prepare_v2(g_db, "SELECT data FROM orders WHERE id = ?", -1, &g_stmt_select, NULL);
assert(err == SQLITE_OK); assert(err == SQLITE_OK);
ERRNO_CHECK();
} }
void db_driver_close(void) void db_driver_close(void)
{ {
int err; int err;
ERRNO_CHECK();
err = sqlite3_finalize(g_stmt_select); err = sqlite3_finalize(g_stmt_select);
assert(err == SQLITE_OK); assert(err == SQLITE_OK);
err = sqlite3_finalize(g_stmt_insert); err = sqlite3_finalize(g_stmt_insert);
assert(err == SQLITE_OK); assert(err == SQLITE_OK);
err = sqlite3_close(g_db); err = sqlite3_close(g_db);
assert(err == SQLITE_OK); assert(err == SQLITE_OK);
ERRNO_CHECK();
} }

View file

@ -96,7 +96,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
@ -111,17 +110,6 @@ extern int *storms;
extern int weeks_per_month; extern int weeks_per_month;
extern int months_per_year; extern int months_per_year;
static void check_errno(const char * file, int line) {
if (errno) {
char zText[64];
sprintf(zText, "error %d during report at %s:%d", errno, file, line);
perror(zText);
errno = 0;
}
}
#define CHECK_ERRNO() check_errno(__FILE__, __LINE__)
static char *gamedate_season(const struct locale *lang) static char *gamedate_season(const struct locale *lang)
{ {
static char buf[256]; /* FIXME: static return value */ static char buf[256]; /* FIXME: static return value */
@ -2195,7 +2183,7 @@ report_plaintext(const char *filename, report_context * ctx,
} }
ch = 0; ch = 0;
CHECK_ERRNO(); ERRNO_CHECK();
for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem;
a = a->next) { a = a->next) {
const item_type *itype = (const item_type *)a->data.v; const item_type *itype = (const item_type *)a->data.v;
@ -2245,7 +2233,7 @@ report_plaintext(const char *filename, report_context * ctx,
} }
} }
newline(out); newline(out);
CHECK_ERRNO(); ERRNO_CHECK();
centre(out, LOC(f->locale, "nr_alliances"), false); centre(out, LOC(f->locale, "nr_alliances"), false);
newline(out); newline(out);
@ -2253,7 +2241,7 @@ report_plaintext(const char *filename, report_context * ctx,
rpline(out); rpline(out);
CHECK_ERRNO(); ERRNO_CHECK();
anyunits = 0; anyunits = 0;
for (r = ctx->first; r != ctx->last; r = r->next) { for (r = ctx->first; r != ctx->last; r = r->next) {
@ -2367,7 +2355,7 @@ report_plaintext(const char *filename, report_context * ctx,
newline(out); newline(out);
rpline(out); rpline(out);
CHECK_ERRNO(); ERRNO_CHECK();
} }
if (!is_monsters(f)) { if (!is_monsters(f)) {
if (!anyunits) { if (!anyunits) {
@ -2379,7 +2367,7 @@ report_plaintext(const char *filename, report_context * ctx,
} }
} }
fstream_done(&strm); fstream_done(&strm);
CHECK_ERRNO(); ERRNO_CHECK();
return 0; return 0;
} }

View file

@ -24,6 +24,14 @@ without prior permission by the authors of Eressea.
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
void errno_check(const char * file, int line) {
if (errno) {
log_info("errno is %d (%s) at %s:%d",
errno, strerror(errno), file, line);
errno = 0;
}
}
#ifdef STDIO_CP #ifdef STDIO_CP
static int stdio_codepage = STDIO_CP; static int stdio_codepage = STDIO_CP;
#else #else

View file

@ -28,13 +28,17 @@ extern "C" {
int log_level(struct log_t *log, int flags); int log_level(struct log_t *log, int flags);
void log_close(void); void log_close(void);
extern void log_fatal(const char *format, ...); void log_fatal(const char *format, ...);
extern void log_error(const char *format, ...); void log_error(const char *format, ...);
extern void log_warning(const char *format, ...); void log_warning(const char *format, ...);
extern void log_debug(const char *format, ...); void log_debug(const char *format, ...);
extern void log_info(const char *format, ...); void log_info(const char *format, ...);
extern void log_printf(FILE * ios, const char *format, ...); void log_printf(FILE * ios, const char *format, ...);
void errno_check(const char *file, int line);
#define ERRNO_CHECK() errno_check(__FILE__, __LINE__)
#define LOG_CPERROR 0x01 #define LOG_CPERROR 0x01
#define LOG_CPWARNING 0x02 #define LOG_CPWARNING 0x02
#define LOG_CPINFO 0x04 #define LOG_CPINFO 0x04