[GRASS-SVN] r48182 - grass/trunk/db/drivers/sqlite

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 7 04:27:53 EDT 2011


Author: mmetz
Date: 2011-09-07 01:27:53 -0700 (Wed, 07 Sep 2011)
New Revision: 48182

Modified:
   grass/trunk/db/drivers/sqlite/create_table.c
   grass/trunk/db/drivers/sqlite/cursor.c
   grass/trunk/db/drivers/sqlite/db.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:
clean up code, simplified usage of sqlite busy handler

Modified: grass/trunk/db/drivers/sqlite/create_table.c
===================================================================
--- grass/trunk/db/drivers/sqlite/create_table.c	2011-09-07 08:27:17 UTC (rev 48181)
+++ grass/trunk/db/drivers/sqlite/create_table.c	2011-09-07 08:27:53 UTC (rev 48182)
@@ -113,9 +113,6 @@
     G_debug(3, " SQL: %s", db_get_string(&sql));
 
     ret = sqlite3_prepare(sqlite, db_get_string(&sql), -1, &statement, &rest);
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
-    }
 
     if (ret != SQLITE_OK) {
 	append_error("Cannot create table:\n");

Modified: grass/trunk/db/drivers/sqlite/cursor.c
===================================================================
--- grass/trunk/db/drivers/sqlite/cursor.c	2011-09-07 08:27:17 UTC (rev 48181)
+++ grass/trunk/db/drivers/sqlite/cursor.c	2011-09-07 08:27:53 UTC (rev 48182)
@@ -21,7 +21,6 @@
 int db__driver_close_cursor(dbCursor * dbc)
 {
     cursor *c;
-    int ret;
 
     init_error();
 
@@ -30,10 +29,7 @@
     if (c == NULL)
 	return DB_FAILED;
 
-    ret = sqlite3_finalize(c->statement);
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
-    }
+    sqlite3_finalize(c->statement);
 
     /* free_cursor(cursor) */
     free_cursor(c);

Modified: grass/trunk/db/drivers/sqlite/db.c
===================================================================
--- grass/trunk/db/drivers/sqlite/db.c	2011-09-07 08:27:17 UTC (rev 48181)
+++ grass/trunk/db/drivers/sqlite/db.c	2011-09-07 08:27:53 UTC (rev 48182)
@@ -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/trunk/db/drivers/sqlite/describe.c
===================================================================
--- grass/trunk/db/drivers/sqlite/describe.c	2011-09-07 08:27:17 UTC (rev 48181)
+++ grass/trunk/db/drivers/sqlite/describe.c	2011-09-07 08:27:53 UTC (rev 48182)
@@ -94,7 +94,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()");
 
@@ -102,10 +102,7 @@
     G_debug(3, "ncols = %d", ncols);
 
     /* Try to get first row */
-    ret = sqlite3_step(statement);
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
-    }
+    sqlite3_step(statement);
 
     /* Count columns of known type */
     nkcols = 0;

Modified: grass/trunk/db/drivers/sqlite/execute.c
===================================================================
--- grass/trunk/db/drivers/sqlite/execute.c	2011-09-07 08:27:17 UTC (rev 48181)
+++ grass/trunk/db/drivers/sqlite/execute.c	2011-09-07 08:27:53 UTC (rev 48182)
@@ -42,9 +42,6 @@
     G_debug(3, "execute: %s", s);
 
     ret = sqlite3_prepare(sqlite, s, -1, &stmt, &rest);
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
-    }
 
     if (ret != SQLITE_OK) {
 	append_error("Error in sqlite3_prepare():\n");
@@ -96,9 +93,7 @@
     G_debug(3, "execute: BEGIN");
 
     ret = sqlite3_exec(sqlite, "BEGIN", NULL, NULL, NULL);
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	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));
@@ -125,9 +120,7 @@
     G_debug(3, "execute: COMMIT");
 
     ret = sqlite3_exec(sqlite, "COMMIT", NULL, NULL, NULL);
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	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/trunk/db/drivers/sqlite/fetch.c
===================================================================
--- grass/trunk/db/drivers/sqlite/fetch.c	2011-09-07 08:27:17 UTC (rev 48181)
+++ grass/trunk/db/drivers/sqlite/fetch.c	2011-09-07 08:27:53 UTC (rev 48182)
@@ -64,12 +64,9 @@
 	    c->row = -1;
 
 	ret = sqlite3_step(c->statement);
-	while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	    ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
-	}
 	if (ret != SQLITE_ROW) {
 	    if (ret != SQLITE_DONE) {
-		append_error("Cannot step:\n");
+		append_error("Cannot fetch:\n");
 		append_error((char *)sqlite3_errmsg(sqlite));
 		report_error();
 		return DB_FAILED;
@@ -252,7 +249,7 @@
 {
     cursor *c;
     dbToken token;
-    int row, ret;
+    int row;
 
     /* get cursor token */
     token = db_get_cursor_token(cn);
@@ -268,17 +265,14 @@
 	return (c->nrows);
     }
 
-    ret = sqlite3_reset(c->statement);
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	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/trunk/db/drivers/sqlite/index.c
===================================================================
--- grass/trunk/db/drivers/sqlite/index.c	2011-09-07 08:27:17 UTC (rev 48181)
+++ grass/trunk/db/drivers/sqlite/index.c	2011-09-07 08:27:53 UTC (rev 48182)
@@ -66,9 +66,6 @@
     G_debug(3, " SQL: %s", db_get_string(&sql));
 
     ret = sqlite3_prepare(sqlite, db_get_string(&sql), -1, &statement, &rest);
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
-    }
 
     if (ret != SQLITE_OK) {
 	append_error("Cannot create index:\n");

Modified: grass/trunk/db/drivers/sqlite/listtab.c
===================================================================
--- grass/trunk/db/drivers/sqlite/listtab.c	2011-09-07 08:27:17 UTC (rev 48181)
+++ grass/trunk/db/drivers/sqlite/listtab.c	2011-09-07 08:27:53 UTC (rev 48182)
@@ -45,10 +45,6 @@
 			  "select name from sqlite_master where type = 'table' or type = 'view'",
 			  -1, &statement, &rest);
 
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	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/trunk/db/drivers/sqlite/select.c
===================================================================
--- grass/trunk/db/drivers/sqlite/select.c	2011-09-07 08:27:17 UTC (rev 48181)
+++ grass/trunk/db/drivers/sqlite/select.c	2011-09-07 08:27:53 UTC (rev 48182)
@@ -54,9 +54,6 @@
     G_debug(3, "Escaped SQL: %s", str);
 
     ret = sqlite3_prepare(sqlite, str, -1, &(c->statement), &rest);
-    while (ret == SQLITE_BUSY || ret == SQLITE_IOERR_BLOCKED) {
-	ret = sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL);
-    }
 
     if (str)
 	G_free(str);



More information about the grass-commit mailing list