[svn-commits] anthonyl: branch anthonyl/7149 r47233 - /team/anthonyl/7149/cdr/cdr_sqlite.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Nov 6 11:05:15 MST 2006


Author: anthonyl
Date: Mon Nov  6 12:05:14 2006
New Revision: 47233

URL: http://svn.digium.com/view/asterisk?rev=47233&view=rev
Log:
small update

Modified:
    team/anthonyl/7149/cdr/cdr_sqlite.c

Modified: team/anthonyl/7149/cdr/cdr_sqlite.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/7149/cdr/cdr_sqlite.c?rev=47233&r1=47232&r2=47233&view=diff
==============================================================================
--- team/anthonyl/7149/cdr/cdr_sqlite.c (original)
+++ team/anthonyl/7149/cdr/cdr_sqlite.c Mon Nov  6 12:05:14 2006
@@ -48,9 +48,11 @@
 #include <stdio.h>
 #ifdef HAVE_SQLITE
 #include <sqlite.h>
-#else if HAVE_SQLITE2
+#endif
+#ifdef HAVE_SQLITE2
 #include <sqlite2.h>
-#else if HAVE_SQLITE3
+#endif
+#ifdef HAVE_SQLITE3
 #include <sqlite3.h>
 #endif
 #include "asterisk/channel.h"
@@ -65,7 +67,17 @@
 #define DATE_FORMAT "%Y-%m-%d %T"
 
 static char *name = "sqlite";
+#if HAVE_SQLITE
 static sqlite* db = NULL;
+#endif
+
+#if HAVE_SQLITE2
+static sqlite2* db = NULL;
+#endif
+
+#if HAVE_SQLITE3
+static sqlite3* db = NULL;
+#endif
 
 AST_MUTEX_DEFINE_STATIC(sqlite_lock);
 
@@ -120,44 +132,53 @@
 	strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm);
 
 	for(count=0; count<5; count++) {
+#if HAVE_SQLITE
 		res = sqlite_exec_printf(db,
+#endif
+#if HAVE_SQLITE2
+		res = sqlite_exec_printf(db,
+#endif
+#if HAVE_SQLITE3
+		res = sqlite3_exec_printf(db,
+#endif
 			"INSERT INTO cdr ("
 				"clid,src,dst,dcontext,"
 				"channel,dstchannel,lastapp,lastdata, "
 				"start,answer,end,"
 				"duration,billsec,disposition,amaflags, "
 				"accountcode"
-#				if LOG_UNIQUEID
+#if LOG_UNIQUEID
 				",uniqueid"
-#				endif
-#				if LOG_USERFIELD
+#endif
+#if LOG_USERFIELD
 				",userfield"
-#				endif
+#endif
 			") VALUES ("
 				"'%q', '%q', '%q', '%q', "
 				"'%q', '%q', '%q', '%q', "
 				"'%q', '%q', '%q', "
 				"%d, %d, %d, %d, "
 				"'%q'"
-#				if LOG_UNIQUEID
+#if LOG_UNIQUEID
 				",'%q'"
-#				endif
-#				if LOG_USERFIELD
+#endif
+#if LOG_USERFIELD
 				",'%q'"
-#				endif
+#endif
 			")", NULL, NULL, &zErr,
 				cdr->clid, cdr->src, cdr->dst, cdr->dcontext,
 				cdr->channel, cdr->dstchannel, cdr->lastapp, cdr->lastdata,
 				startstr, answerstr, endstr,
 				cdr->duration, cdr->billsec, cdr->disposition, cdr->amaflags,
 				cdr->accountcode
-#				if LOG_UNIQUEID
+#if LOG_UNIQUEID
 				,cdr->uniqueid
-#				endif
-#				if LOG_USERFIELD
+#endif
+#if LOG_USERFIELD
 				,cdr->userfield
-#				endif
+#endif
 			);
+					  
 		if (res != SQLITE_BUSY && res != SQLITE_LOCKED)
 			break;
 		usleep(200);
@@ -175,7 +196,13 @@
 static int unload_module(void)
 {
 	if (db)
+#ifdef HAVE_SQLITE
 		sqlite_close(db);
+#elseif HAVE_SQLITE2
+
+#elseif HAVE_SQLITE3
+	sqlite3_close(db);
+#endif
 	ast_cdr_unregister(name);
 	return 0;
 }
@@ -191,10 +218,12 @@
 
 #ifdef HAVE_SQLITE
 	db = sqlite_open(fn, 0660, &zErr);
-#else if HAVE_SQLITE2
-	db = sqlite2_open(fn, 0660, &zErr);
-#else if HAVE_SQLITE3
-	db = sqlite3_open(fn, 0660, &zErr);
+#endif
+#ifdef HAVE_SQLITE2
+	db = sqlite_open(fn, 0660, &zErr);
+#endif
+#ifdef HAVE_SQLITE3
+	db = sqlite3_open(fn, &db);
 #endif
 	
 	if (!db) {
@@ -204,13 +233,26 @@
 	}
 
 	/* is the table there? */
-#ifdef HAVE_SQLITE
+#if HAVE_SQLITE
 	res = sqlite_exec(db, "SELECT COUNT(AcctId) FROM cdr;", NULL, NULL, NULL);
 #endif 
+#if HAVE_SQLITE2
+	res = sqlite_exec(db, "SELECT COUNT(AcctId) FROM cdr;", NULL, NULL, NULL);
+#endif
+#if HAVE_SQLITE3
+	res = sqlite3_exec(db, "SELECT COUNT(AcctId) FROM cdr;", NULL, NULL, NULL);
+#endif 
 	if (res) {
+
 #ifdef HAVE_SQLITE
 		res = sqlite_exec(db, sql_create_table, NULL, NULL, &zErr);
 #endif
+#ifdef HAVE_SQLITE2
+		res = sqlite_exec(db, sql_create_table, NULL, NULL, &zErr);
+#endif
+#ifdef HAVE_SQLITE3
+		res = sqlite3_exec(db, sql_create_table, NULL, NULL, &zErr);
+#endif 
 		if (res) {
 			ast_log(LOG_ERROR, "cdr_sqlite: Unable to create table 'cdr': %s\n", zErr);
 			free(zErr);
@@ -228,9 +270,15 @@
 	return 0;
 
 err:
-#ifdef HAVE_SQLITE
 	if (db)
+#if HAVE_SQLITE
 		sqlite_close(db);
+#endif
+#if HAVE_SQLITE2
+	        sqlite_close(db);
+#endif
+#ifdef HAVE_SQLITE3
+	        sqlite3_close(db);
 #endif
 	
 	return -1;



More information about the svn-commits mailing list