diff options
Diffstat (limited to 'smsd/services/odbc.c')
-rw-r--r-- | smsd/services/odbc.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/smsd/services/odbc.c b/smsd/services/odbc.c index 76e3ad8..293ae5f 100644 --- a/smsd/services/odbc.c +++ b/smsd/services/odbc.c @@ -28,7 +28,7 @@ static void SMSDODBC_LogError(GSM_SMSDConfig * Config, SQLRETURN origret, SQLSMALLINT handle_type, SQLHANDLE handle, const char *message) { - SQLINTEGER i = 0; + SQLSMALLINT i = 0; SQLINTEGER native; SQLCHAR state[ 7 ]; SQLCHAR text[256]; @@ -82,8 +82,7 @@ time_t SMSDODBC_GetDate(GSM_SMSDConfig * Config, SQL_result *res, unsigned int f const char *SMSDODBC_GetString(GSM_SMSDConfig * Config, SQL_result *res, unsigned int field) { - SQLLEN sqllen; - int size; + SQLLEN size; SQLRETURN ret; char shortbuffer[1]; @@ -93,20 +92,12 @@ const char *SMSDODBC_GetString(GSM_SMSDConfig * Config, SQL_result *res, unsigne } /* Figure out string length */ - ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, shortbuffer, 0, &sqllen); + ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, shortbuffer, 0, &size); if (!SQL_SUCCEEDED(ret)) { SMSDODBC_LogError(Config, ret, SQL_HANDLE_STMT, res->odbc, "SQLGetData(string,0) failed"); return NULL; } - /* - * This hack seems to be needed to avoid type breakage on Win64, don't ask me why. - * - * Might be actually bug in MinGW compiler, but when using SQLLEN type below - * anything fails (it does not match to SQL_NULL_DATA and realloc always fails). - */ - size = sqllen; - /* Did not we get NULL? */ if (size == SQL_NULL_DATA) { SMSD_Log(DEBUG_SQL, Config, "Field %d returning NULL", field); @@ -116,12 +107,12 @@ const char *SMSDODBC_GetString(GSM_SMSDConfig * Config, SQL_result *res, unsigne /* Allocate string */ Config->conn.odbc.retstr[field] = realloc(Config->conn.odbc.retstr[field], size + 1); if (Config->conn.odbc.retstr[field] == NULL) { - SMSD_Log(DEBUG_ERROR, Config, "Field %d returning NULL, failed to allocate %d bytes of memory", field, size + 1); + SMSD_Log(DEBUG_ERROR, Config, "Field %d returning NULL, failed to allocate %ld bytes of memory", field, (long)(size + 1)); return NULL; } /* Actually grab result from database */ - ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, Config->conn.odbc.retstr[field], size + 1, &sqllen); + ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, Config->conn.odbc.retstr[field], size + 1, &size); if (!SQL_SUCCEEDED(ret)) { SMSDODBC_LogError(Config, ret, SQL_HANDLE_STMT, res->odbc, "SQLGetData(string) failed"); return NULL; @@ -279,6 +270,8 @@ char * SMSDODBC_QuoteString(GSM_SMSDConfig * Config, const char *string) strcasecmp(driver_name, "pgsql") == 0 || strcasecmp(driver_name, "native_pgsql") == 0 || strncasecmp(driver_name, "sqlite", 6) == 0 || + strncasecmp(driver_name, "oracle", 6) == 0 || + strncasecmp(driver_name, "freetds", 6) == 0 || strcasecmp(Config->driver, "access") == 0) { quote = '\''; } @@ -342,7 +335,7 @@ unsigned long SMSDODBC_AffectedRows(GSM_SMSDConfig * Config, SQL_result *res) SMSDODBC_LogError(Config, ret, SQL_HANDLE_DBC, Config->conn.odbc.dbc, "SQLRowCount failed"); return 0; } - return count; + return (unsigned long)count; } struct GSM_SMSDdbobj SMSDODBC = { |