[asterisk-bugs] [Asterisk 0018473]: [patch] Schema selection support

Asterisk Bug Tracker noreply at bugs.digium.com
Tue Dec 14 17:18:48 UTC 2010


The following issue has been UPDATED. 
====================================================================== 
https://issues.asterisk.org/view.php?id=18473 
====================================================================== 
Reported By:                avf
Assigned To:                
====================================================================== 
Project:                    Asterisk
Issue ID:                   18473
Category:                   CDR/cdr_adaptive_odbc
Reproducibility:            N/A
Severity:                   feature
Priority:                   normal
Status:                     new
Asterisk Version:           1.8.0 
JIRA:                        
Regression:                 No 
Reviewboard Link:            
SVN Branch (only for SVN checkouts, not tarball releases): N/A 
SVN Revision (number only!):  
Request Review:              
====================================================================== 
Date Submitted:             2010-12-14 11:14 CST
Last Modified:              2010-12-14 11:18 CST
====================================================================== 
Summary:                    [patch] Schema selection support
Description: 
We use CDR with an Oracle backend, via ODBC.  The CDR table exists inside a
schema (called ASTERISKDBA), and there is a synonym (also called CDR) in
the PUBLIC schema.

When cdr_adaptive_odbc.c calls SQLColumns() to get a list of column names,
the result set contains each column twice --- once for the ASTERISKDBA
schema, and once for the PUBLIC schema.  Obviously, this causes INSERTs to
error.

This patch adds a "schema" configuration parameter which, when set, passes
the schema name into SQLColumns().

Setting "schema => ASTERISKDBA" (or, for that matter, "schema => PUBLIC")
fixes this problem in our environment.


--- cdr/cdr_adaptive_odbc.c.orig        2010-12-14 14:45:23.000000000
+0000
+++ cdr/cdr_adaptive_odbc.c     2010-12-14 15:16:35.000000000 +0000
@@ -88,7 +88,8 @@
        char columnname[80];
        char connection[40];
        char table[40];
-       int lenconnection, lentable, usegmtime = 0;
+       char schema[40];
+       int lenconnection, lentable, lenschema, usegmtime = 0;
        SQLLEN sqlptr;
        int res = 0;
        SQLHSTMT stmt = NULL;
@@ -130,6 +131,12 @@
                ast_copy_string(table, tmp, sizeof(table));
                lentable = strlen(table);
 
+               if(ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg,
"schema"))) {
+                       tmp = "";
+               }
+               ast_copy_string(schema, tmp, sizeof(schema));
+               lenschema = strlen(schema);
+
                res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
                if ((res != SQL_SUCCESS) && (res !=
SQL_SUCCESS_WITH_INFO)) {
                        ast_log(LOG_WARNING, "SQL Alloc Handle failed on
connection '%s'!\n", connection);
@@ -137,7 +144,7 @@
                        continue;
                }
 
-               res = SQLColumns(stmt, NULL, 0, NULL, 0, (unsigned char
*)table, SQL_NTS, (unsigned char *)"%", SQL_NTS);
+               res = SQLColumns(stmt, NULL, 0, lenschema == 0 ? NULL :
(unsigned char *)schema, SQL_NTS, (unsigned char *)table, SQL_NTS,
(unsigned char *)"%", SQL_NTS);
                if ((res != SQL_SUCCESS) && (res !=
SQL_SUCCESS_WITH_INFO)) {
                        ast_log(LOG_ERROR, "Unable to query database
columns on connection '%s'.  Skipping.\n", connection);
                        ast_odbc_release_obj(obj);


====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2010-12-14 11:18 avf            Summary                  Schema selection
support => [patch] Schema selection support
======================================================================




More information about the asterisk-bugs mailing list