don't use 'rowcount' after SELECT statements, since the ODBC API does not say it is allowed (issue #5083)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6904 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2005-10-31 21:31:25 +00:00
parent c3f9388b23
commit 551ac9af04
3 changed files with 91 additions and 180 deletions

View File

@@ -752,7 +752,6 @@ static int retrieve_file(char *dir, int msgnum)
int fd=-1;
size_t fdlen = 0;
void *fdm=NULL;
SQLLEN rowcount=0;
SQLSMALLINT colcount=0;
SQLHSTMT stmt;
char sql[256];
@@ -807,13 +806,16 @@ static int retrieve_file(char *dir, int msgnum)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO))) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
res = SQLFetch(stmt);
if (res == SQL_NO_DATA) {
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
else if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
if (rowcount) {
fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC);
if (fd < 0) {
ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
@@ -826,12 +828,6 @@ static int retrieve_file(char *dir, int msgnum)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLFetch(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
if (f)
fprintf(f, "[message]\n");
for (x=0;x<colcount;x++) {
@@ -844,7 +840,7 @@ static int retrieve_file(char *dir, int msgnum)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
if (!strcmp(coltitle, "recording")) {
if (!strcasecmp(coltitle, "recording")) {
res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize);
fdlen = colsize;
fd = open(full_fn, O_RDWR | O_TRUNC | O_CREAT, 0770);
@@ -874,12 +870,10 @@ static int retrieve_file(char *dir, int msgnum)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
if (strcmp(coltitle, "msgnum") && strcmp(coltitle, "dir") && f)
if (strcasecmp(coltitle, "msgnum") && strcasecmp(coltitle, "dir") && f)
fprintf(f, "%s=%s\n", coltitle, rowdata);
}
}
} else if (msgnum > -1) /* msgnum will be -1 if the message hasn't yet been saved */
ast_log(LOG_WARNING, "Failed to retrieve rows for msgnum=%s and dir=%s\n", msgnums, dir);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
} else
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -914,7 +908,6 @@ static int last_message_index(struct ast_vm_user *vmu, char *dir)
{
int x = 0;
int res;
SQLLEN rowcount=0;
SQLHSTMT stmt;
char sql[256];
char rowdata[20];
@@ -941,12 +934,6 @@ static int last_message_index(struct ast_vm_user *vmu, char *dir)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLFetch(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
@@ -972,7 +959,6 @@ static int message_exists(char *dir, int msgnum)
{
int x = 0;
int res;
SQLLEN rowcount=0;
SQLHSTMT stmt;
char sql[256];
char rowdata[20];
@@ -1002,12 +988,6 @@ static int message_exists(char *dir, int msgnum)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLFetch(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
@@ -1037,7 +1017,6 @@ static int count_messages(struct ast_vm_user *vmu, char *dir)
static void delete_file(char *sdir, int smsg)
{
int res;
SQLLEN rowcount=0;
SQLHSTMT stmt;
char sql[256];
char msgnums[20];
@@ -1066,12 +1045,6 @@ static void delete_file(char *sdir, int smsg)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO))) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
} else
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -1082,7 +1055,6 @@ yuck:
static void copy_file(char *sdir, int smsg, char *ddir, int dmsg, char *dmailboxuser, char *dmailboxcontext)
{
int res;
SQLLEN rowcount=0;
SQLHSTMT stmt;
char sql[256];
char msgnums[20];
@@ -1127,12 +1099,6 @@ static void copy_file(char *sdir, int smsg, char *ddir, int dmsg, char *dmailbox
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s] (You probably don't have MySQL 4.1 or later installed)\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
} else
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -1147,7 +1113,6 @@ static int store_file(char *dir, char *mailboxuser, char *mailboxcontext, int ms
int fd = -1;
void *fdm=NULL;
size_t fdlen = -1;
SQLLEN rowcount=0;
SQLHSTMT stmt;
SQLINTEGER len;
char sql[256];
@@ -1252,12 +1217,6 @@ static int store_file(char *dir, char *mailboxuser, char *mailboxcontext, int ms
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
} else
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -1274,7 +1233,6 @@ yuck:
static void rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxcontext, char *ddir, int dmsg)
{
int res;
SQLLEN rowcount=0;
SQLHSTMT stmt;
char sql[256];
char msgnums[20];
@@ -1319,12 +1277,6 @@ static void rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxco
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
} else
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -1974,7 +1926,6 @@ static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
{
int x = 0;
int res;
SQLLEN rowcount=0;
SQLHSTMT stmt;
char sql[256];
char rowdata[20];
@@ -2019,12 +1970,6 @@ static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLFetch(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
@@ -2058,12 +2003,6 @@ static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLFetch(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
@@ -2090,7 +2029,6 @@ static int has_voicemail(const char *mailbox, const char *folder)
{
int nummsgs = 0;
int res;
SQLLEN rowcount=0;
SQLHSTMT stmt;
char sql[256];
char rowdata[20];
@@ -2132,12 +2070,6 @@ static int has_voicemail(const char *mailbox, const char *folder)
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLRowCount(stmt, &rowcount);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
goto yuck;
}
res = SQLFetch(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);

View File

@@ -64,7 +64,6 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
int res;
int x;
struct ast_variable *var=NULL, *prev=NULL;
SQLLEN rowcount=0;
SQLULEN colsize;
SQLSMALLINT colcount=0;
SQLSMALLINT datatype;
@@ -126,13 +125,6 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
return NULL;
}
res = SQLRowCount(stmt, &rowcount);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
return NULL;
}
res = SQLNumResultCols(stmt, &colcount);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
@@ -140,8 +132,11 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
return NULL;
}
if (rowcount) {
res = SQLFetch(stmt);
if (res == SQL_NO_DATA) {
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
return NULL;
}
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
@@ -184,7 +179,6 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
}
}
}
}
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
@@ -210,7 +204,6 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
struct ast_config *cfg=NULL;
struct ast_category *cat=NULL;
struct ast_realloca ra;
SQLLEN rowcount=0;
SQLULEN colsize;
SQLSMALLINT colcount=0;
SQLSMALLINT datatype;
@@ -278,13 +271,6 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
return NULL;
}
res = SQLRowCount(stmt, &rowcount);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
return NULL;
}
res = SQLNumResultCols(stmt, &colcount);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
@@ -299,9 +285,8 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
return NULL;
}
while (rowcount--) {
while ((res=SQLFetch(stmt)) != SQL_NO_DATA) {
var = NULL;
res = SQLFetch(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
continue;

View File

@@ -110,7 +110,7 @@ int odbc_smart_execute(odbc_obj *obj, SQLHSTMT stmt)
{
int res = 0;
res = SQLExecute(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
ast_log(LOG_WARNING, "SQL Execute error! Attempting a reconnect...\n");
ast_mutex_lock(&obj->lock);
obj->up = 0;
@@ -147,7 +147,6 @@ int odbc_sanity_check(odbc_obj *obj)
char *test_sql = "select 1";
SQLHSTMT stmt;
int res = 0;
SQLLEN rowcount = 0;
ast_mutex_lock(&obj->lock);
if(obj->up) { /* so you say... let's make sure */
@@ -162,11 +161,6 @@ int odbc_sanity_check(odbc_obj *obj)
res = SQLExecute(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
obj->up = 0; /* Liar!*/
} else {
res = SQLRowCount(stmt, &rowcount);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
obj->up = 0; /* Liar!*/
}
}
}
}