[svn-commits] tilghman: branch group/ast_storage r65750 -
/team/group/ast_storage/res/
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Wed May 23 20:31:16 MST 2007
Author: tilghman
Date: Wed May 23 22:31:15 2007
New Revision: 65750
URL: http://svn.digium.com/view/asterisk?view=rev&rev=65750
Log:
Add code to query column names (to be used later for matching config items to their appropriate columns)
Modified:
team/group/ast_storage/res/res_storage_odbc.c
Modified: team/group/ast_storage/res/res_storage_odbc.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/res/res_storage_odbc.c?view=diff&rev=65750&r1=65749&r2=65750
==============================================================================
--- team/group/ast_storage/res/res_storage_odbc.c (original)
+++ team/group/ast_storage/res/res_storage_odbc.c Wed May 23 22:31:15 2007
@@ -41,12 +41,24 @@
#include <fcntl.h>
#include <errno.h>
+struct columns {
+ char *name;
+ SQLSMALLINT type;
+ SQLINTEGER size;
+ SQLSMALLINT decimals;
+ SQLSMALLINT radix;
+ SQLSMALLINT nullable;
+ SQLINTEGER octetlen;
+ AST_LIST_ENTRY(columns) list;
+};
+
struct ast_storage_odbc {
const struct ast_storage_be *be;
char odbc_class[128];
char tablename[128];
char pathname[128];
struct odbc_obj *conn;
+ AST_RWLIST_HEAD(odbc_columns, columns) columns;
};
struct odbc_storage_dir {
@@ -95,15 +107,32 @@
return;
}
+static int se_free_odbc(struct ast_storage *st)
+{
+ struct ast_storage_odbc *ost = (struct ast_storage_odbc *)st;
+ ast_odbc_release_obj(ost->conn);
+ free(ost);
+ return 0;
+}
+
static struct ast_storage *se_new_odbc(const char *uri)
{
- char tmp[256];
+ char tmp[256], columnname[80];
+ int res;
struct ast_storage_odbc *ost = ast_calloc(1, sizeof(struct ast_storage_odbc));
+ struct columns *entry;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(class);
AST_APP_ARG(tablename);
AST_APP_ARG(pathname);
);
+ SQLHSTMT stmt = NULL;
+ SQLLEN sqlptr;
+
+ if (!ost)
+ return NULL;
+
+ AST_RWLIST_HEAD_INIT(&ost->columns);
/* odbc:// */
ast_copy_string(tmp, uri + 7, sizeof(tmp));
@@ -120,15 +149,45 @@
return NULL;
}
+ res = SQLAllocHandle(SQL_HANDLE_STMT, ost->conn, &stmt);
+ if (res != SQL_SUCCESS && res != SQL_SUCCESS_WITH_INFO) {
+ ast_log(LOG_ERROR, "Allocation of database handle failed.\n");
+ ast_odbc_release_obj(ost->conn);
+ free(ost);
+ }
+
+ /* Get the table columns */
+ res = SQLColumns(stmt, NULL, 0, NULL, 0, (unsigned char *)ost->tablename, 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 table '%s@%s'. Storage method fails.\n", ost->tablename, ost->odbc_class);
+ ast_odbc_release_obj(ost->conn);
+ free(ost);
+ return NULL;
+ }
+
+ while ((res = SQLFetch(stmt)) != SQL_NO_DATA && res != SQL_ERROR) {
+ SQLGetData(stmt, 4, SQL_C_CHAR, columnname, sizeof(columnname), &sqlptr);
+ entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(columnname) + 1);
+ if (!entry) {
+ ast_log(LOG_ERROR, "Unable to allocate column entry\n");
+ se_free_odbc((struct ast_storage *)ost);
+ return NULL;
+ }
+
+ entry->name = (char *)entry + sizeof(*entry);
+ strcpy(entry->name, columnname);
+
+ SQLGetData(stmt, 5, SQL_C_SHORT, &entry->type, sizeof(entry->type), NULL);
+ SQLGetData(stmt, 7, SQL_C_LONG, &entry->size, sizeof(entry->size), NULL);
+ SQLGetData(stmt, 9, SQL_C_SHORT, &entry->decimals, sizeof(entry->decimals), NULL);
+ SQLGetData(stmt, 10, SQL_C_SHORT, &entry->radix, sizeof(entry->radix), NULL);
+ SQLGetData(stmt, 11, SQL_C_SHORT, &entry->nullable, sizeof(entry->nullable), NULL);
+ SQLGetData(stmt, 16, SQL_C_LONG, &entry->octetlen, sizeof(entry->octetlen), NULL);
+
+ AST_LIST_INSERT_TAIL(&ost->columns, entry, list);
+ }
+
return ((struct ast_storage *)ost);
-}
-
-static int se_free_odbc(struct ast_storage *st)
-{
- struct ast_storage_odbc *ost = (struct ast_storage_odbc *)st;
- ast_odbc_release_obj(ost->conn);
- free(ost);
- return 0;
}
static void get_path_file(struct ast_storage_odbc *ost, const char *objectname, char *pathname, size_t pathnamesize, char *filename, size_t filenamesize)
More information about the svn-commits
mailing list