[PATCH] osmo-hlr[master]: less noise: simplify db_remove_reset()

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Tue Oct 10 01:31:59 UTC 2017


Review at  https://gerrit.osmocom.org/4179

less noise: simplify db_remove_reset()

db_remove_reset() needs to be called after each stmt run, whether it succeeded
or not.

In case sqlite3_clear_bindings() would fail to unbind a stmt, we would anyway
be beyond recovery. There seem to be no plausible situations where such failure
would occur, unless there have been no bindings in the first place.

In case there was an SQL stmt failure, sqlite3_reset() will re-barf the same
error message, we will always have logged it earlier already in the proper
context.

We are never evaluating the return value, nor would we know how to recover from
non-success.

The conclusions:
- db_remove_reset() does not need to log any errors.
- db_remove_reset() does not need to return success.

Change-Id: I21678463e59f607f5f5c5732963e274392f0fffd
---
M src/db.c
M src/db.h
M tests/db/db_test.err
3 files changed, 4 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/79/4179/1

diff --git a/src/db.c b/src/db.c
index 57362ac..6104fe6 100644
--- a/src/db.c
+++ b/src/db.c
@@ -69,20 +69,10 @@
 }
 
 /* remove bindings and reset statement to be re-executed */
-bool db_remove_reset(sqlite3_stmt *stmt)
+void db_remove_reset(sqlite3_stmt *stmt)
 {
-	int rc = sqlite3_clear_bindings(stmt);
-	if (rc != SQLITE_OK) {
-		LOGP(DDB, LOGL_ERROR, "Error clerearing bindings: %d\n", rc);
-		return false;
-	}
-
-	rc = sqlite3_reset(stmt);
-	if (rc != SQLITE_OK) {
-		LOGP(DDB, LOGL_ERROR, "Error in sqlite3_reset: %d\n", rc);
-		return false;
-	}
-	return true;
+	sqlite3_clear_bindings(stmt);
+	sqlite3_reset(stmt);
 }
 
 /** bind text arg and do proper cleanup in case of failure. If param_name is
diff --git a/src/db.h b/src/db.h
index d7a8303..ee2d801 100644
--- a/src/db.h
+++ b/src/db.h
@@ -25,7 +25,7 @@
 	sqlite3_stmt *stmt[_NUM_DB_STMT];
 };
 
-bool db_remove_reset(sqlite3_stmt *stmt);
+void db_remove_reset(sqlite3_stmt *stmt);
 bool db_bind_text(sqlite3_stmt *stmt, const char *param_name, const char *text);
 bool db_bind_int(sqlite3_stmt *stmt, const char *param_name, int nr);
 bool db_bind_int64(sqlite3_stmt *stmt, const char *param_name, int64_t nr);
diff --git a/tests/db/db_test.err b/tests/db/db_test.err
index ac0e2f1..1b08cec 100644
--- a/tests/db/db_test.err
+++ b/tests/db/db_test.err
@@ -29,7 +29,6 @@
 
 db_subscr_create(dbc, imsi0) --> -EIO
 DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
-DDB Error in sqlite3_reset: 2067
 DAUC IMSI='123456789000000': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
@@ -40,12 +39,10 @@
 
 db_subscr_create(dbc, imsi1) --> -EIO
 DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
-DDB Error in sqlite3_reset: 2067
 DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_create(dbc, imsi1) --> -EIO
 DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
-DDB Error in sqlite3_reset: 2067
 DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_get_by_imsi(dbc, imsi1, &g_subscr) --> 0
@@ -56,12 +53,10 @@
 
 db_subscr_create(dbc, imsi2) --> -EIO
 DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
-DDB Error in sqlite3_reset: 2067
 DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_create(dbc, imsi2) --> -EIO
 DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
-DDB Error in sqlite3_reset: 2067
 DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_get_by_imsi(dbc, imsi2, &g_subscr) --> 0

-- 
To view, visit https://gerrit.osmocom.org/4179
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I21678463e59f607f5f5c5732963e274392f0fffd
Gerrit-PatchSet: 1
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>


More information about the gerrit-log mailing list