[asterisk-commits] twilson: branch twilson/sqlite_astdb r323153 - in /team/twilson/sqlite_astdb:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 13 12:44:20 CDT 2011


Author: twilson
Date: Mon Jun 13 12:44:19 2011
New Revision: 323153

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=323153
Log:
Add helper function + rollback

Modified:
    team/twilson/sqlite_astdb/include/asterisk/astdb.h
    team/twilson/sqlite_astdb/main/db.c

Modified: team/twilson/sqlite_astdb/include/asterisk/astdb.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/sqlite_astdb/include/asterisk/astdb.h?view=diff&rev=323153&r1=323152&r2=323153
==============================================================================
--- team/twilson/sqlite_astdb/include/asterisk/astdb.h (original)
+++ team/twilson/sqlite_astdb/include/asterisk/astdb.h Mon Jun 13 12:44:19 2011
@@ -68,6 +68,7 @@
 
 int ast_db_begin_transaction(void);
 int ast_db_commit_transaction(void);
+int ast_db_rollback_transaction(void);
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/twilson/sqlite_astdb/main/db.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/sqlite_astdb/main/db.c?view=diff&rev=323153&r1=323152&r2=323153
==============================================================================
--- team/twilson/sqlite_astdb/main/db.c (original)
+++ team/twilson/sqlite_astdb/main/db.c Mon Jun 13 12:44:19 2011
@@ -186,24 +186,35 @@
 	return *astdb;
 }
 
+/* This is currently only useful for operations that don't return rows */
+static int db_execute_sql(const char *sql)
+{
+	sqlite3 *astdb;
+	char *errmsg = NULL;
+	if (!(astdb = get_db_ts())) {
+		return -1;
+	}
+	sqlite3_exec(astdb, sql, NULL, NULL, &errmsg);
+	if (errmsg) {
+		ast_log(LOG_WARNING, "Error executing SQL: %s\n", errmsg);
+		return -1;
+	}
+
+	return 0;
+}
 int ast_db_begin_transaction(void)
 {
-	sqlite3 *astdb;
-	if (!(astdb = get_db_ts())) {
-		return -1;
-	}
-	sqlite3_exec(astdb, "BEGIN TRANSACTION", NULL, NULL, NULL);
-	return 0;
+	return db_execute_sql("BEGIN TRANSACTION");
 }
 
 int ast_db_commit_transaction(void)
 {
-	sqlite3 *astdb;
-	if (!(astdb = get_db_ts())) {
-		return -1;
-	}
-	sqlite3_exec(astdb, "COMMIT", NULL, NULL, NULL);
-	return 0;
+	return db_execute_sql("COMMIT");
+}
+
+int ast_db_rollback_transaction(void)
+{
+	return db_execute_sql("ROLLBACK");
 }
 
 static int init_stmt(sqlite3_stmt **stmt, const char *sql, size_t len)




More information about the asterisk-commits mailing list