[GRASS-SVN] r48180 -
grass/branches/releasebranch_6_4/db/drivers/sqlite
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Sep 7 04:26:58 EDT 2011
Author: mmetz
Date: 2011-09-07 01:26:58 -0700 (Wed, 07 Sep 2011)
New Revision: 48180
Modified:
grass/branches/releasebranch_6_4/db/drivers/sqlite/create_table.c
grass/branches/releasebranch_6_4/db/drivers/sqlite/cursor.c
grass/branches/releasebranch_6_4/db/drivers/sqlite/db.c
grass/branches/releasebranch_6_4/db/drivers/sqlite/describe.c
grass/branches/releasebranch_6_4/db/drivers/sqlite/execute.c
grass/branches/releasebranch_6_4/db/drivers/sqlite/fetch.c
grass/branches/releasebranch_6_4/db/drivers/sqlite/index.c
grass/branches/releasebranch_6_4/db/drivers/sqlite/listtab.c
grass/branches/releasebranch_6_4/db/drivers/sqlite/main.c
grass/branches/releasebranch_6_4/db/drivers/sqlite/select.c
Log:
clean up code, simplified usage of sqlite busy handler
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/create_table.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/create_table.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/create_table.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -113,13 +113,6 @@
G_debug(3, " SQL: %s", db_get_string(&sql));
ret = sqlite3_prepare(sqlite, db_get_string(&sql), -1, &statement, &rest);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
if (ret != SQLITE_OK) {
append_error("Cannot create table:\n");
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/cursor.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/cursor.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/cursor.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -21,7 +21,6 @@
int db__driver_close_cursor(dbCursor * dbc)
{
cursor *c;
- int ret;
init_error();
@@ -30,14 +29,7 @@
if (c == NULL)
return DB_FAILED;
- ret = sqlite3_finalize(c->statement);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
+ sqlite3_finalize(c->statement);
/* free_cursor(cursor) */
free_cursor(c);
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/db.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/db.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/db.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -88,6 +88,9 @@
return DB_FAILED;
}
+ /* set the sqlite busy handler */
+ sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
+
return DB_OK;
}
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/describe.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/describe.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/describe.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -50,13 +50,6 @@
db_append_string(&sql, " where oid < 0");
ret = sqlite3_prepare(sqlite, db_get_string(&sql), -1, &statement, &rest);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
if (ret != SQLITE_OK) {
append_error("Error in sqlite3_prepare():");
@@ -98,7 +91,7 @@
int describe_table(sqlite3_stmt * statement, dbTable ** table, cursor * c)
{
- int i, ncols, nkcols, ret;
+ int i, ncols, nkcols;
G_debug(3, "describe_table()");
@@ -106,14 +99,7 @@
G_debug(3, "ncols = %d", ncols);
/* Try to get first row */
- ret = sqlite3_step(statement);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
+ sqlite3_step(statement);
/* Count columns of known type */
nkcols = 0;
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/execute.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/execute.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/execute.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -42,13 +42,6 @@
G_debug(3, "execute: %s", s);
ret = sqlite3_prepare(sqlite, s, -1, &stmt, &rest);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
if (ret != SQLITE_OK) {
append_error("Error in sqlite3_prepare():\n");
@@ -100,13 +93,7 @@
G_debug(3, "execute: BEGIN");
ret = sqlite3_exec(sqlite, "BEGIN", NULL, NULL, NULL);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
+
if (ret != SQLITE_OK) {
append_error("Cannot 'BEGIN' transaction:\n");
append_error((char *)sqlite3_errmsg(sqlite));
@@ -133,13 +120,7 @@
G_debug(3, "execute: COMMIT");
ret = sqlite3_exec(sqlite, "COMMIT", NULL, NULL, NULL);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
+
if (ret != SQLITE_OK) {
append_error("Cannot 'COMMIT' transaction:\n");
append_error((char *)sqlite3_errmsg(sqlite));
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/fetch.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/fetch.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/fetch.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -64,13 +64,7 @@
c->row = -1;
ret = sqlite3_step(c->statement);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
+
if (ret != SQLITE_ROW) {
if (ret != SQLITE_DONE) {
append_error("Cannot step:\n");
@@ -256,7 +250,7 @@
{
cursor *c;
dbToken token;
- int row, ret;
+ int row;
/* get cursor token */
token = db_get_cursor_token(cn);
@@ -272,21 +266,14 @@
return (c->nrows);
}
- ret = sqlite3_reset(c->statement);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
+ sqlite3_reset(c->statement);
c->nrows = 0;
while (sqlite3_step(c->statement) == SQLITE_ROW) {
c->nrows++;
}
- ret = sqlite3_reset(c->statement);
+ sqlite3_reset(c->statement);
/* Reset cursor position */
row = -1;
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/index.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/index.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/index.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -66,13 +66,6 @@
G_debug(3, " SQL: %s", db_get_string(&sql));
ret = sqlite3_prepare(sqlite, db_get_string(&sql), -1, &statement, &rest);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
if (ret != SQLITE_OK) {
append_error("Cannot create index:\n");
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/listtab.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/listtab.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/listtab.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -45,14 +45,6 @@
"select name from sqlite_master where type = 'table' or type = 'view'",
-1, &statement, &rest);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
-
if (ret != SQLITE_OK) {
append_error("Cannot list tables\n");
append_error((char *)sqlite3_errmsg(sqlite));
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/main.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/main.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/main.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -32,10 +32,10 @@
static time_t start_time = 0;
time_t curr_time;
int min;
- static int last_min = 0;
+ static int last_min = -1;
/* do something here while waiting? */
- if (n_calls > 0) {
+ if (n_calls > 0 && last_min > -1) {
time(&curr_time);
min = (curr_time - start_time) / 60;
if (min > 1 && min > last_min) {
Modified: grass/branches/releasebranch_6_4/db/drivers/sqlite/select.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/sqlite/select.c 2011-09-07 07:36:15 UTC (rev 48179)
+++ grass/branches/releasebranch_6_4/db/drivers/sqlite/select.c 2011-09-07 08:26:58 UTC (rev 48180)
@@ -54,13 +54,6 @@
G_debug(3, "Escaped SQL: %s", str);
ret = sqlite3_prepare(sqlite, str, -1, &(c->statement), &rest);
-#if (SQLITE_VERSION_NUMBER > 3003008)
- while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-#else
- while (ret == SQLITE_BUSY) {
-#endif
- ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
- }
if (str)
G_free(str);
More information about the grass-commit
mailing list