[asterisk-commits] seanbright: branch seanbright/cdr-tds-conversion r126225 - /team/seanbright/c...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Jun 28 16:12:01 CDT 2008
Author: seanbright
Date: Sat Jun 28 16:12:00 2008
New Revision: 126225
URL: http://svn.digium.com/view/asterisk?view=rev&rev=126225
Log:
I shouldn't have lied to you... Make sure to check for the existence of the
table specified in the configuration. Also made a couple error messages
more clear.
Modified:
team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c
Modified: team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c?view=diff&rev=126225&r1=126224&r2=126225
==============================================================================
--- team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c (original)
+++ team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c Sat Jun 28 16:12:00 2008
@@ -197,20 +197,18 @@
);
if (erc == FAIL) {
- ast_log(LOG_ERROR, "Failed to build query\n");
+ ast_log(LOG_ERROR, "Failed to build INSERT statement, no CDR was logged.\n");
goto done;
}
- erc = dbsqlexec(settings->dbproc);
-
- if (erc == FAIL) {
- ast_log(LOG_ERROR, "Failed to send query\n");
+ if (dbsqlexec(settings->dbproc) == FAIL) {
+ ast_log(LOG_ERROR, "Failed to execute INSERT statement, no CDR was logged.\n");
goto done;
}
/* Consume any results we might get back (this is more of a sanity check than
* anything else, since an INSERT shouldn't return results). */
- while ((erc = dbresults(settings->dbproc)) != NO_MORE_RESULTS) {
+ while (dbresults(settings->dbproc) != NO_MORE_RESULTS) {
while (dbnextrow(settings->dbproc) != NO_MORE_ROWS);
}
@@ -312,19 +310,36 @@
return -1;
}
+ dbloginfree(login);
+
if (dbuse(settings->dbproc, (char *) settings->database) == FAIL) {
ast_log(LOG_ERROR, "Unable to select database %s\n", settings->database);
- dbclose(settings->dbproc);
- settings->dbproc = NULL;
- dbloginfree(login);
- return -1;
- }
-
- dbloginfree(login);
+ goto failed;
+ }
+
+ if (dbfcmd(settings->dbproc, "SELECT 1 FROM [%s]", settings->table) == FAIL) {
+ ast_log(LOG_ERROR, "Unable to build query while verifying the existence of table '%s'\n", settings->table);
+ goto failed;
+ }
+
+ if (dbsqlexec(settings->dbproc) == FAIL) {
+ ast_log(LOG_ERROR, "Unable to verify existence of table '%s'\n", settings->table);
+ goto failed;
+ }
+
+ /* Consume the result set (we don't really care about the result, though) */
+ while (dbresults(settings->dbproc) != NO_MORE_RESULTS) {
+ while (dbnextrow(settings->dbproc) != NO_MORE_ROWS);
+ }
settings->connected = 1;
return 0;
+
+failed:
+ dbclose(settings->dbproc);
+ settings->dbproc = NULL;
+ return -1;
}
static int tds_unload_module(void)
More information about the asterisk-commits
mailing list