From 27fb5d9128c3d326191d5f9f01dac4f715000682 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 29 Apr 2008 11:41:16 +0200 Subject: [PATCH] Fix several bugs in the journal query function. --- src/csync_journal.c | 13 +++++++++---- tests/csync_tests/check_csync_journal.c | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/csync_journal.c b/src/csync_journal.c index f45e7cb4d..a74417751 100644 --- a/src/csync_journal.c +++ b/src/csync_journal.c @@ -76,7 +76,7 @@ static int csync_journal_is_empty(CSYNC *ctx) { int rc = 0; result = csync_journal_query(ctx, "SELECT COUNT(key) FROM metadata LIMIT 1 OFFSET 0;"); - if (result && result->count == 0) { + if (result == NULL) { rc = 1; } c_strlist_destroy(result); @@ -264,7 +264,6 @@ c_strlist_t *csync_journal_query(CSYNC *ctx, const char *statement) { CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Gave up waiting for lock to clear"); } CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "sqlite3_compile error: %s - on query %s", sqlite3_errmsg(ctx->journal.db), statement); - result = c_strlist_new(1); break; } else { busy_count = 0; @@ -289,8 +288,14 @@ c_strlist_t *csync_journal_query(CSYNC *ctx, const char *statement) { CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite3_step: MISUSE!!"); } - if (err == SQLITE_DONE || err == SQLITE_ERROR) { - result = c_strlist_new(1); + if (err == SQLITE_DONE) { + if (result == NULL) { + result = c_strlist_new(1); + } + break; + } + + if (err == SQLITE_ERROR) { break; } diff --git a/tests/csync_tests/check_csync_journal.c b/tests/csync_tests/check_csync_journal.c index af16286eb..425f96eae 100644 --- a/tests/csync_tests/check_csync_journal.c +++ b/tests/csync_tests/check_csync_journal.c @@ -62,7 +62,20 @@ START_TEST (check_csync_journal_query_statement) c_strlist_destroy(result); result = csync_journal_query(csync, "SELECT;"); - fail_unless(result != NULL, NULL); + fail_unless(result == NULL, NULL); + c_strlist_destroy(result); +} +END_TEST + +START_TEST (check_csync_journal_create_error) +{ + c_strlist_t *result = NULL; + result = csync_journal_query(csync, "CREATE TABLE test(key INTEGER, text VARCHAR(10));"); + fail_if(result == NULL, NULL); + c_strlist_destroy(result); + + result = csync_journal_query(csync, "CREATE TABLE test(key INTEGER, text VARCHAR(10));"); + fail_unless(result == NULL, NULL); c_strlist_destroy(result); } END_TEST @@ -71,6 +84,7 @@ START_TEST (check_csync_journal_insert_statement) { c_strlist_t *result = NULL; result = csync_journal_query(csync, "CREATE TABLE test(key INTEGER, text VARCHAR(10));"); + fail_if(result == NULL, NULL); c_strlist_destroy(result); fail_unless(csync_journal_insert(csync, "INSERT;") == 0, NULL); fail_unless(csync_journal_insert(csync, "INSERT") == 0, NULL); @@ -120,6 +134,7 @@ static Suite *csync_suite(void) { create_case(s, "check_csync_journal_check", check_csync_journal_check); create_case_fixture(s, "check_csync_journal_load", check_csync_journal_load, setup, teardown); create_case_fixture(s, "check_csync_journal_query_statement", check_csync_journal_query_statement, setup_init, teardown); + create_case_fixture(s, "check_csync_journal_create_error", check_csync_journal_create_error, setup_init, teardown); create_case_fixture(s, "check_csync_journal_insert_statement", check_csync_journal_insert_statement, setup_init, teardown); create_case_fixture(s, "check_csync_journal_query_create_and_insert_table", check_csync_journal_query_create_and_insert_table, setup_init, teardown); create_case_fixture(s, "check_csync_journal_is_empty", check_csync_journal_is_empty, setup_init, teardown);