[GRASS-SVN] r48350 - grass/trunk/db/drivers/sqlite
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Sep 18 13:12:39 EDT 2011
Author: mmetz
Date: 2011-09-18 10:12:39 -0700 (Sun, 18 Sep 2011)
New Revision: 48350
Modified:
grass/trunk/db/drivers/sqlite/create_table.c
grass/trunk/db/drivers/sqlite/describe.c
grass/trunk/db/drivers/sqlite/execute.c
grass/trunk/db/drivers/sqlite/fetch.c
grass/trunk/db/drivers/sqlite/index.c
grass/trunk/db/drivers/sqlite/listtab.c
grass/trunk/db/drivers/sqlite/select.c
Log:
SQLite driver: get real return codes
Modified: grass/trunk/db/drivers/sqlite/create_table.c
===================================================================
--- grass/trunk/db/drivers/sqlite/create_table.c 2011-09-18 16:18:45 UTC (rev 48349)
+++ grass/trunk/db/drivers/sqlite/create_table.c 2011-09-18 17:12:39 UTC (rev 48350)
@@ -130,12 +130,14 @@
}
ret = sqlite3_step(statement);
+ /* get real result code */
+ ret = sqlite3_reset(statement);
if (ret == SQLITE_SCHEMA) {
sqlite3_finalize(statement);
/* try again */
}
- else if (ret != SQLITE_DONE) {
+ else if (ret != SQLITE_OK) {
append_error("Error in sqlite3_step():\n");
append_error((char *)sqlite3_errmsg(sqlite));
report_error();
Modified: grass/trunk/db/drivers/sqlite/describe.c
===================================================================
--- grass/trunk/db/drivers/sqlite/describe.c 2011-09-18 16:18:45 UTC (rev 48349)
+++ grass/trunk/db/drivers/sqlite/describe.c 2011-09-18 17:12:39 UTC (rev 48350)
@@ -65,27 +65,35 @@
return DB_FAILED;
}
- if (describe_table(statement, table, NULL) == DB_FAILED) {
+ ret = sqlite3_step(statement);
+ /* get real result code */
+ ret = sqlite3_reset(statement);
- ret = sqlite3_errcode(sqlite);
- if (ret == SQLITE_SCHEMA) {
- sqlite3_finalize(statement);
- /* try again */
- }
- else {
- append_error("Cannot describe table:\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
- sqlite3_finalize(statement);
- return DB_FAILED;
- }
+ if (ret == SQLITE_SCHEMA) {
+ sqlite3_finalize(statement);
+ /* try again */
}
+ else if (ret != SQLITE_OK) {
+ append_error("Error in sqlite3_step():\n");
+ append_error((char *)sqlite3_errmsg(sqlite));
+ report_error();
+ sqlite3_finalize(statement);
+ return DB_FAILED;
+ }
else
break;
}
db_free_string(&sql);
+ if (describe_table(statement, table, NULL) == DB_FAILED) {
+ append_error("Cannot describe table:\n");
+ append_error((char *)sqlite3_errmsg(sqlite));
+ report_error();
+ sqlite3_finalize(statement);
+ return DB_FAILED;
+ }
+
sqlite3_finalize(statement);
return DB_OK;
@@ -116,8 +124,11 @@
/* Try to get first row */
ret = sqlite3_step(statement);
if (ret != SQLITE_DONE && ret != SQLITE_ROW) {
+ /* get real result code */
ret = sqlite3_reset(statement);
- G_warning(_("SQLite driver: %s"), sqlite3_errmsg(sqlite));
+ append_error("Error in sqlite3_step():\n");
+ append_error((char *)sqlite3_errmsg(sqlite));
+ report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/sqlite/execute.c
===================================================================
--- grass/trunk/db/drivers/sqlite/execute.c 2011-09-18 16:18:45 UTC (rev 48349)
+++ grass/trunk/db/drivers/sqlite/execute.c 2011-09-18 17:12:39 UTC (rev 48350)
@@ -55,16 +55,18 @@
}
ret = sqlite3_step(stmt);
+ /* get real result code */
+ ret = sqlite3_reset(stmt);
if (ret == SQLITE_SCHEMA) {
sqlite3_finalize(stmt);
/* try again */
}
- else if (ret != SQLITE_DONE) {
+ else if (ret != SQLITE_OK) {
append_error("Error in sqlite3_step():\n");
append_error((char *)sqlite3_errmsg(sqlite));
report_error();
- ret = sqlite3_finalize(stmt);
+ sqlite3_finalize(stmt);
return DB_FAILED;
}
else
Modified: grass/trunk/db/drivers/sqlite/fetch.c
===================================================================
--- grass/trunk/db/drivers/sqlite/fetch.c 2011-09-18 16:18:45 UTC (rev 48349)
+++ grass/trunk/db/drivers/sqlite/fetch.c 2011-09-18 17:12:39 UTC (rev 48350)
@@ -65,13 +65,14 @@
ret = sqlite3_step(c->statement);
if (ret != SQLITE_ROW) {
- if (ret != SQLITE_DONE) {
+ /* get real result code */
+ ret = sqlite3_reset(c->statement);
+ if (ret != SQLITE_OK) {
append_error("Cannot fetch:\n");
append_error((char *)sqlite3_errmsg(sqlite));
report_error();
return DB_FAILED;
}
- sqlite3_reset(c->statement);
*more = 0;
return DB_OK;
}
@@ -272,16 +273,16 @@
c->nrows++;
}
- if (ret != SQLITE_DONE) {
- ret = sqlite3_reset(c->statement);
+ /* get real result code */
+ ret = sqlite3_reset(c->statement);
+
+ if (ret != SQLITE_OK) {
append_error("Cannot get number of rows\n");
append_error((char *)sqlite3_errmsg(sqlite));
report_error();
return DB_FAILED;
}
- sqlite3_reset(c->statement);
-
/* Reset cursor position */
row = -1;
if (c->row > -1) {
Modified: grass/trunk/db/drivers/sqlite/index.c
===================================================================
--- grass/trunk/db/drivers/sqlite/index.c 2011-09-18 16:18:45 UTC (rev 48349)
+++ grass/trunk/db/drivers/sqlite/index.c 2011-09-18 17:12:39 UTC (rev 48350)
@@ -83,22 +83,25 @@
}
ret = sqlite3_step(statement);
+ /* get real result code */
+ ret = sqlite3_reset(statement);
if (ret == SQLITE_SCHEMA) {
sqlite3_finalize(statement);
/* try again */
}
- else if (ret != SQLITE_DONE) {
+ else if (ret != SQLITE_OK) {
append_error("Error in sqlite3_step():\n");
append_error((char *)sqlite3_errmsg(sqlite));
report_error();
+ sqlite3_finalize(statement);
+ db_free_string(&sql);
return DB_FAILED;
}
else
break;
}
- sqlite3_reset(statement);
sqlite3_finalize(statement);
db_free_string(&sql);
Modified: grass/trunk/db/drivers/sqlite/listtab.c
===================================================================
--- grass/trunk/db/drivers/sqlite/listtab.c 2011-09-18 16:18:45 UTC (rev 48349)
+++ grass/trunk/db/drivers/sqlite/listtab.c 2011-09-18 17:12:39 UTC (rev 48350)
@@ -57,7 +57,16 @@
while (sqlite3_step(statement) == SQLITE_ROW) {
nrows++;
}
- sqlite3_reset(statement);
+ /* get real result code */
+ ret = sqlite3_reset(statement);
+
+ if (ret != SQLITE_OK) {
+ append_error("Cannot list tables\n");
+ append_error((char *)sqlite3_errmsg(sqlite));
+ report_error();
+ sqlite3_finalize(statement);
+ return DB_FAILED;
+ }
G_debug(3, "nrows = %d", nrows);
@@ -66,6 +75,7 @@
if (list == NULL) {
append_error("Cannot db_alloc_string_array()");
report_error();
+ sqlite3_finalize(statement);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/sqlite/select.c
===================================================================
--- grass/trunk/db/drivers/sqlite/select.c 2011-09-18 16:18:45 UTC (rev 48349)
+++ grass/trunk/db/drivers/sqlite/select.c 2011-09-18 17:12:39 UTC (rev 48350)
@@ -68,19 +68,21 @@
return DB_FAILED;
}
- if (describe_table(c->statement, &table, c) == DB_FAILED) {
- ret = sqlite3_errcode(sqlite);
- if (ret == SQLITE_SCHEMA) {
- sqlite3_finalize(c->statement);
- /* try again */
- }
- else {
- append_error("Cannot describe table\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
- return DB_FAILED;
- }
+ ret = sqlite3_step(c->statement);
+ /* get real result code */
+ ret = sqlite3_reset(c->statement);
+
+ if (ret == SQLITE_SCHEMA) {
+ sqlite3_finalize(c->statement);
+ /* try again */
}
+ else if (ret != SQLITE_OK) {
+ append_error("Error in sqlite3_step():\n");
+ append_error((char *)sqlite3_errmsg(sqlite));
+ report_error();
+ sqlite3_finalize(c->statement);
+ return DB_FAILED;
+ }
else
break;
}
@@ -88,6 +90,13 @@
if (str)
G_free(str);
+ if (describe_table(c->statement, &table, c) == DB_FAILED) {
+ append_error("Cannot describe table\n");
+ append_error((char *)sqlite3_errmsg(sqlite));
+ report_error();
+ return DB_FAILED;
+ }
+
c->nrows = -1;
c->row = -1;
More information about the grass-commit
mailing list