[asterisk-commits] tilghman: branch tilghman/cdr_custom_odbc r65168 - /team/tilghman/cdr_custom_...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri May 18 12:39:06 MST 2007


Author: tilghman
Date: Fri May 18 14:39:06 2007
New Revision: 65168

URL: http://svn.digium.com/view/asterisk?view=rev&rev=65168
Log:
Add some debugging code, and make datetime fields work on MS SQL Server

Modified:
    team/tilghman/cdr_custom_odbc/cdr/cdr_adaptive_odbc.c

Modified: team/tilghman/cdr_custom_odbc/cdr/cdr_adaptive_odbc.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/cdr_custom_odbc/cdr/cdr_adaptive_odbc.c?view=diff&rev=65168&r1=65167&r2=65168
==============================================================================
--- team/tilghman/cdr_custom_odbc/cdr/cdr_adaptive_odbc.c (original)
+++ team/tilghman/cdr_custom_odbc/cdr/cdr_adaptive_odbc.c Fri May 18 14:39:06 2007
@@ -225,9 +225,12 @@
 
 static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
 {
-	int res;
+	int res, i;
 	char *sql = data;
 	SQLHSTMT stmt;
+	SQLINTEGER nativeerror = 0, numfields = 0;
+	SQLSMALLINT diagbytes = 0;
+	unsigned char state[10], diagnostic[256];
 
 	res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
@@ -238,6 +241,15 @@
 	res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS);
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 		ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
+		SQLGetDiagField(SQL_HANDLE_STMT, stmt, 1, SQL_DIAG_NUMBER, &numfields, SQL_IS_INTEGER, &diagbytes);
+		for (i = 0; i < numfields; i++) {
+			SQLGetDiagRec(SQL_HANDLE_STMT, stmt, i + 1, state, &nativeerror, diagnostic, sizeof(diagnostic), &diagbytes);
+			ast_log(LOG_WARNING, "SQL Execute returned an error %d: %s: %s (%d)\n", res, state, diagnostic, diagbytes);
+			if (i > 10) {
+				ast_log(LOG_WARNING, "Oh, that was good.  There are really %d diagnostics?\n", (int)numfields);
+				break;
+			}
+		}
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 		return NULL;
 	}
@@ -390,6 +402,7 @@
 					}
 					break;
 				case SQL_TYPE_TIMESTAMP:
+				case SQL_TIMESTAMP:
 					{
 						int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
 						int count = sscanf(colptr, "%d-%d-%d %d:%d:%d", &year, &month, &day, &hour, &minute, &second);



More information about the asterisk-commits mailing list