[asterisk-commits] ivaxer: branch ivaxer/ast_storage r275625 - /team/ivaxer/ast_storage/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jul 12 10:32:16 CDT 2010
Author: ivaxer
Date: Mon Jul 12 10:32:12 2010
New Revision: 275625
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=275625
Log:
cosmetic changes
- changed variables/function naming
Modified:
team/ivaxer/ast_storage/res/res_storage_odbc.c
Modified: team/ivaxer/ast_storage/res/res_storage_odbc.c
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/res/res_storage_odbc.c?view=diff&rev=275625&r1=275624&r2=275625
==============================================================================
--- team/ivaxer/ast_storage/res/res_storage_odbc.c (original)
+++ team/ivaxer/ast_storage/res/res_storage_odbc.c Mon Jul 12 10:32:12 2010
@@ -66,12 +66,11 @@
char pathname[1];
};
-struct prepare_sql_cb_arg {
- struct odbc_storage_pvt *ost;
+struct get_query_data {
+ const char *sql;
const char *pathname;
const char *objectname;
const char *ext;
- const char *sql;
};
struct put_query_data {
@@ -329,33 +328,28 @@
return NULL;
}
-static SQLHSTMT prepare_get_sql_cb(struct odbc_obj *obj, void *cb_arg) {
+static SQLHSTMT prepare_get_query(struct odbc_obj *obj, void *arg) {
SQLHSTMT stmt;
SQLRETURN ret;
- struct prepare_sql_cb_arg *arg = (struct prepare_sql_cb_arg *) cb_arg;
- struct odbc_storage_pvt *ost = arg->ost;
- const char *pathname = arg->pathname;
- const char *objectname = arg->objectname;
- const char *ext = arg->ext;
- const char *sql = arg->sql;
-
- ret = SQLAllocHandle(SQL_HANDLE_STMT, ost->conn->con, &stmt);
+ struct get_query_data *qdata = (struct get_query_data *) arg;
+
+ ret = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
if (!SQL_SUCCEEDED(ret)) {
ast_log(LOG_WARNING, "SQL Alloc Handle failed!");
return NULL;
}
- ret = SQLPrepare(stmt, (SQLCHAR *)sql, SQL_NTS);
+ ret = SQLPrepare(stmt, (SQLCHAR *)qdata->sql, SQL_NTS);
if (!SQL_SUCCEEDED(ret)) {
- ast_log(LOG_WARNING, "SQL Prepare failed!\n[%s]", sql);
+ ast_log(LOG_WARNING, "SQL Prepare failed!\n[%s]", qdata->sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
return NULL;
}
- SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(pathname), 0, (void *)pathname, 0, NULL);
- SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(objectname), 0, (void *)objectname, 0, NULL);
- if (ext)
- SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(ext), 0, (void *)ext, 0, NULL);
+ SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->pathname), 0, (void *)qdata->pathname, 0, NULL);
+ SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->objectname), 0, (void *)qdata->objectname, 0, NULL);
+ if (qdata->ext)
+ SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->ext), 0, (void *)qdata->ext, 0, NULL);
return stmt;
}
@@ -363,15 +357,13 @@
static struct ast_storage_fileobject *se_get(struct ast_storage *st, const char *objectname, const char *exts)
{
struct odbc_storage_pvt *ost = (struct odbc_storage_pvt *)st->storage_pvt;
- struct prepare_sql_cb_arg prepare_cb_arg;
+ struct get_query_data qdata;
struct ast_storage_fileobject *fo = NULL;
struct ast_storage_fileinst *fi = NULL;
char ext[16];
char sql[128];
char *pathname;
SQLHSTMT stmt;
- //char rowdata[256], coltitle[128];
- //SQLSMALLINT colcount, collen, datatype;
if (ast_strlen_zero(objectname)) {
ast_log(LOG_WARNING, "objectname is null.\n");
@@ -399,16 +391,17 @@
snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE pathname=? AND filename=?", ost->tablename);
}
- memset(&prepare_cb_arg, 0, sizeof(prepare_cb_arg));
- prepare_cb_arg.ost = ost;
- prepare_cb_arg.sql = sql;
- prepare_cb_arg.objectname = objectname;
- prepare_cb_arg.pathname = pathname;
+ qdata.sql = sql;
+ qdata.objectname = objectname;
+ qdata.pathname = pathname;
if (exts) {
- prepare_cb_arg.ext = ext;
- }
-
- stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_get_sql_cb, (void *) &prepare_cb_arg);
+ qdata.ext = ext;
+ }
+ else {
+ qdata.ext = NULL;
+ }
+
+ stmt = ast_odbc_prepare_and_execute(ost->conn, prepare_get_query, (void *) &qdata);
if (!stmt) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n", sql);
return NULL;
@@ -445,7 +438,7 @@
static SQLHSTMT execute_put_query(struct odbc_obj *obj, void *arg) {
SQLRETURN ret;
SQLHSTMT stmt;
- struct put_query_data *pdata = (struct put_query_data *) arg;
+ struct put_query_data *qdata = (struct put_query_data *) arg;
ret = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
@@ -454,12 +447,12 @@
return NULL;
}
- SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(pdata->pathname), 0, (void *)pdata->pathname, 0, NULL);
- SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(pdata->objectname), 0, (void *)pdata->objectname, 0, NULL);
- SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(pdata->ext), 0, (void *)pdata->ext, 0, NULL);
- SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY, pdata->data_len, 0, (void *)pdata->data, 0, &pdata->data_ind);
-
- ret = SQLExecDirect(stmt, (unsigned char *)pdata->sql, SQL_NTS);
+ SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->pathname), 0, (void *)qdata->pathname, 0, NULL);
+ SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->objectname), 0, (void *)qdata->objectname, 0, NULL);
+ SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(qdata->ext), 0, (void *)qdata->ext, 0, NULL);
+ SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY, qdata->data_len, 0, (void *)qdata->data, 0, &qdata->data_ind);
+
+ ret = SQLExecDirect(stmt, (unsigned char *)qdata->sql, SQL_NTS);
if(!SQL_SUCCEEDED(ret)) {
ast_log(LOG_WARNING, "SQL Exec Direct failed!");
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
@@ -475,7 +468,7 @@
struct odbc_storage_pvt *ost = (struct odbc_storage_pvt *) st->storage_pvt;
struct ast_storage_fileinst *fi;
char sql[128], ext[16];
- struct put_query_data pdata;
+ struct put_query_data qdata;
int fd, fdlen;
void *fdm;
int putret = -1;
@@ -524,14 +517,14 @@
snprintf(sql, sizeof(sql), "INSERT INTO %s (pathname,filename,extension,recording) VALUES (?,?,?,?)", ost->tablename);
- pdata.sql = sql;
- pdata.pathname = ost->pathname;
- pdata.objectname = fo->objectname;
- pdata.ext = fi->ext;
- pdata.data = fdm;
- pdata.data_len = pdata.data_ind = fdlen;
-
- stmt = ast_odbc_direct_execute(ost->conn, execute_put_query, (void *) &pdata);
+ qdata.sql = sql;
+ qdata.pathname = ost->pathname;
+ qdata.objectname = fo->objectname;
+ qdata.ext = fi->ext;
+ qdata.data = fdm;
+ qdata.data_len = qdata.data_ind = fdlen;
+
+ stmt = ast_odbc_direct_execute(ost->conn, execute_put_query, (void *) &qdata);
if(!stmt) {
ast_log(LOG_WARNING, "SQL Execute failed!");
goto error;
@@ -687,7 +680,6 @@
{
struct ast_storage *st;
struct ast_storage_fileobject *fo;
-// struct ast_storage_fileinst *fi;
int ret;
char uri[] = "asterisk-storage-test/storage/testpath";
More information about the asterisk-commits
mailing list