mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 02:26:23 +00:00
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:
@@ -752,7 +752,6 @@ static int retrieve_file(char *dir, int msgnum)
|
|||||||
int fd=-1;
|
int fd=-1;
|
||||||
size_t fdlen = 0;
|
size_t fdlen = 0;
|
||||||
void *fdm=NULL;
|
void *fdm=NULL;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLSMALLINT colcount=0;
|
SQLSMALLINT colcount=0;
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
char sql[256];
|
char sql[256];
|
||||||
@@ -807,79 +806,74 @@ static int retrieve_file(char *dir, int msgnum)
|
|||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
goto yuck;
|
||||||
}
|
}
|
||||||
res = SQLRowCount(stmt, &rowcount);
|
res = SQLFetch(stmt);
|
||||||
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO))) {
|
if (res == SQL_NO_DATA) {
|
||||||
ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
|
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
goto yuck;
|
||||||
}
|
}
|
||||||
if (rowcount) {
|
else if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC);
|
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
||||||
if (fd < 0) {
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
|
goto yuck;
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
}
|
||||||
goto yuck;
|
fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
}
|
if (fd < 0) {
|
||||||
res = SQLNumResultCols(stmt, &colcount);
|
ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
|
goto yuck;
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
}
|
||||||
goto yuck;
|
res = SQLNumResultCols(stmt, &colcount);
|
||||||
}
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
res = SQLFetch(stmt);
|
ast_log(LOG_WARNING, "SQL Column Count 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++) {
|
||||||
|
rowdata[0] = '\0';
|
||||||
|
collen = sizeof(coltitle);
|
||||||
|
res = SQLDescribeCol(stmt, x + 1, coltitle, sizeof(coltitle), &collen,
|
||||||
|
&datatype, &colsize, &decimaldigits, &nullable);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
goto yuck;
|
||||||
}
|
}
|
||||||
if (f)
|
if (!strcasecmp(coltitle, "recording")) {
|
||||||
fprintf(f, "[message]\n");
|
res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize);
|
||||||
for (x=0;x<colcount;x++) {
|
fdlen = colsize;
|
||||||
rowdata[0] = '\0';
|
fd = open(full_fn, O_RDWR | O_TRUNC | O_CREAT, 0770);
|
||||||
collen = sizeof(coltitle);
|
if (fd > -1) {
|
||||||
res = SQLDescribeCol(stmt, x + 1, coltitle, sizeof(coltitle), &collen,
|
char tmp[1]="";
|
||||||
&datatype, &colsize, &decimaldigits, &nullable);
|
lseek(fd, fdlen - 1, SEEK_SET);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if (write(fd, tmp, 1) != 1) {
|
||||||
ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
|
close(fd);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
fd = -1;
|
||||||
goto yuck;
|
}
|
||||||
|
if (fd > -1)
|
||||||
|
fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
}
|
}
|
||||||
if (!strcmp(coltitle, "recording")) {
|
if (fdm) {
|
||||||
res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize);
|
memset(fdm, 0, fdlen);
|
||||||
fdlen = colsize;
|
res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize);
|
||||||
fd = open(full_fn, O_RDWR | O_TRUNC | O_CREAT, 0770);
|
|
||||||
if (fd > -1) {
|
|
||||||
char tmp[1]="";
|
|
||||||
lseek(fd, fdlen - 1, SEEK_SET);
|
|
||||||
if (write(fd, tmp, 1) != 1) {
|
|
||||||
close(fd);
|
|
||||||
fd = -1;
|
|
||||||
}
|
|
||||||
if (fd > -1)
|
|
||||||
fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
||||||
}
|
|
||||||
if (fdm) {
|
|
||||||
memset(fdm, 0, fdlen);
|
|
||||||
res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize);
|
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
|
||||||
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
|
||||||
goto yuck;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
|
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
goto yuck;
|
||||||
}
|
}
|
||||||
if (strcmp(coltitle, "msgnum") && strcmp(coltitle, "dir") && f)
|
|
||||||
fprintf(f, "%s=%s\n", coltitle, rowdata);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
|
||||||
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
|
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
||||||
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
|
goto yuck;
|
||||||
|
}
|
||||||
|
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);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
|
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 x = 0;
|
||||||
int res;
|
int res;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
char sql[256];
|
char sql[256];
|
||||||
char rowdata[20];
|
char rowdata[20];
|
||||||
@@ -941,12 +934,6 @@ static int last_message_index(struct ast_vm_user *vmu, char *dir)
|
|||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
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);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
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 x = 0;
|
||||||
int res;
|
int res;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
char sql[256];
|
char sql[256];
|
||||||
char rowdata[20];
|
char rowdata[20];
|
||||||
@@ -1002,12 +988,6 @@ static int message_exists(char *dir, int msgnum)
|
|||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
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);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
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)
|
static void delete_file(char *sdir, int smsg)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
char sql[256];
|
char sql[256];
|
||||||
char msgnums[20];
|
char msgnums[20];
|
||||||
@@ -1066,12 +1045,6 @@ static void delete_file(char *sdir, int smsg)
|
|||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
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);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
|
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)
|
static void copy_file(char *sdir, int smsg, char *ddir, int dmsg, char *dmailboxuser, char *dmailboxcontext)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
char sql[256];
|
char sql[256];
|
||||||
char msgnums[20];
|
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);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
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);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
|
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;
|
int fd = -1;
|
||||||
void *fdm=NULL;
|
void *fdm=NULL;
|
||||||
size_t fdlen = -1;
|
size_t fdlen = -1;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
SQLINTEGER len;
|
SQLINTEGER len;
|
||||||
char sql[256];
|
char sql[256];
|
||||||
@@ -1252,12 +1217,6 @@ static int store_file(char *dir, char *mailboxuser, char *mailboxcontext, int ms
|
|||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
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);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
|
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)
|
static void rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxcontext, char *ddir, int dmsg)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
char sql[256];
|
char sql[256];
|
||||||
char msgnums[20];
|
char msgnums[20];
|
||||||
@@ -1319,12 +1277,6 @@ static void rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxco
|
|||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
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);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
|
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 x = 0;
|
||||||
int res;
|
int res;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
char sql[256];
|
char sql[256];
|
||||||
char rowdata[20];
|
char rowdata[20];
|
||||||
@@ -2019,12 +1970,6 @@ static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
|
|||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
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);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
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);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
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);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
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 nummsgs = 0;
|
||||||
int res;
|
int res;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
char sql[256];
|
char sql[256];
|
||||||
char rowdata[20];
|
char rowdata[20];
|
||||||
@@ -2132,12 +2070,6 @@ static int has_voicemail(const char *mailbox, const char *folder)
|
|||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
goto yuck;
|
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);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
||||||
|
@@ -64,7 +64,6 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
|
|||||||
int res;
|
int res;
|
||||||
int x;
|
int x;
|
||||||
struct ast_variable *var=NULL, *prev=NULL;
|
struct ast_variable *var=NULL, *prev=NULL;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLULEN colsize;
|
SQLULEN colsize;
|
||||||
SQLSMALLINT colcount=0;
|
SQLSMALLINT colcount=0;
|
||||||
SQLSMALLINT datatype;
|
SQLSMALLINT datatype;
|
||||||
@@ -126,13 +125,6 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
|
|||||||
return NULL;
|
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);
|
res = SQLNumResultCols(stmt, &colcount);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
|
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
|
||||||
@@ -140,48 +132,50 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rowcount) {
|
res = SQLFetch(stmt);
|
||||||
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);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
for (x=0;x<colcount;x++) {
|
||||||
|
rowdata[0] = '\0';
|
||||||
|
collen = sizeof(coltitle);
|
||||||
|
res = SQLDescribeCol(stmt, x + 1, coltitle, sizeof(coltitle), &collen,
|
||||||
|
&datatype, &colsize, &decimaldigits, &nullable);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
if (var)
|
||||||
|
ast_variables_destroy(var);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (x=0;x<colcount;x++) {
|
|
||||||
rowdata[0] = '\0';
|
|
||||||
collen = sizeof(coltitle);
|
|
||||||
res = SQLDescribeCol(stmt, x + 1, coltitle, sizeof(coltitle), &collen,
|
|
||||||
&datatype, &colsize, &decimaldigits, &nullable);
|
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
|
||||||
ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
|
|
||||||
if (var)
|
|
||||||
ast_variables_destroy(var);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
indicator = 0;
|
indicator = 0;
|
||||||
res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), &indicator);
|
res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), &indicator);
|
||||||
if (indicator == SQL_NULL_DATA)
|
if (indicator == SQL_NULL_DATA)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
||||||
if (var)
|
if (var)
|
||||||
ast_variables_destroy(var);
|
ast_variables_destroy(var);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
stringp = rowdata;
|
stringp = rowdata;
|
||||||
while(stringp) {
|
while(stringp) {
|
||||||
chunk = strsep(&stringp, ";");
|
chunk = strsep(&stringp, ";");
|
||||||
if (chunk && !ast_strlen_zero(ast_strip(chunk))) {
|
if (chunk && !ast_strlen_zero(ast_strip(chunk))) {
|
||||||
if (prev) {
|
if (prev) {
|
||||||
prev->next = ast_variable_new(coltitle, chunk);
|
prev->next = ast_variable_new(coltitle, chunk);
|
||||||
if (prev->next)
|
if (prev->next)
|
||||||
prev = prev->next;
|
prev = prev->next;
|
||||||
} else
|
} else
|
||||||
prev = var = ast_variable_new(coltitle, chunk);
|
prev = var = ast_variable_new(coltitle, chunk);
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +204,6 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
|
|||||||
struct ast_config *cfg=NULL;
|
struct ast_config *cfg=NULL;
|
||||||
struct ast_category *cat=NULL;
|
struct ast_category *cat=NULL;
|
||||||
struct ast_realloca ra;
|
struct ast_realloca ra;
|
||||||
SQLLEN rowcount=0;
|
|
||||||
SQLULEN colsize;
|
SQLULEN colsize;
|
||||||
SQLSMALLINT colcount=0;
|
SQLSMALLINT colcount=0;
|
||||||
SQLSMALLINT datatype;
|
SQLSMALLINT datatype;
|
||||||
@@ -278,13 +271,6 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
|
|||||||
return NULL;
|
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);
|
res = SQLNumResultCols(stmt, &colcount);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (rowcount--) {
|
while ((res=SQLFetch(stmt)) != SQL_NO_DATA) {
|
||||||
var = NULL;
|
var = NULL;
|
||||||
res = SQLFetch(stmt);
|
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
||||||
continue;
|
continue;
|
||||||
|
@@ -110,7 +110,7 @@ int odbc_smart_execute(odbc_obj *obj, SQLHSTMT stmt)
|
|||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
res = SQLExecute(stmt);
|
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_log(LOG_WARNING, "SQL Execute error! Attempting a reconnect...\n");
|
||||||
ast_mutex_lock(&obj->lock);
|
ast_mutex_lock(&obj->lock);
|
||||||
obj->up = 0;
|
obj->up = 0;
|
||||||
@@ -147,7 +147,6 @@ int odbc_sanity_check(odbc_obj *obj)
|
|||||||
char *test_sql = "select 1";
|
char *test_sql = "select 1";
|
||||||
SQLHSTMT stmt;
|
SQLHSTMT stmt;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
SQLLEN rowcount = 0;
|
|
||||||
|
|
||||||
ast_mutex_lock(&obj->lock);
|
ast_mutex_lock(&obj->lock);
|
||||||
if(obj->up) { /* so you say... let's make sure */
|
if(obj->up) { /* so you say... let's make sure */
|
||||||
@@ -162,11 +161,6 @@ int odbc_sanity_check(odbc_obj *obj)
|
|||||||
res = SQLExecute(stmt);
|
res = SQLExecute(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
obj->up = 0; /* Liar!*/
|
obj->up = 0; /* Liar!*/
|
||||||
} else {
|
|
||||||
res = SQLRowCount(stmt, &rowcount);
|
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
|
||||||
obj->up = 0; /* Liar!*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user