Skip to content

Commit

Permalink
ODBC-210 Warnings fix on OSX
Browse files Browse the repository at this point in the history
and a bit of ODBC-208
  • Loading branch information
lawrinn committed Jan 18, 2019
1 parent df99372 commit 8ce8fd5
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 77 deletions.
10 changes: 5 additions & 5 deletions ma_bulk.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void MADB_CleanBulkOperData(MADB_Stmt *Stmt, unsigned int ParamOffset)

for (i= ParamOffset; i < MADB_STMT_PARAM_COUNT(Stmt); ++i)
{
if (CRec= MADB_DescGetInternalRecord(Stmt->Apd, i, MADB_DESC_READ))
if ((CRec= MADB_DescGetInternalRecord(Stmt->Apd, i, MADB_DESC_READ)) != NULL)
{
MaBind= &Stmt->params[i - ParamOffset];
DataPtr= GetBindOffset(Stmt->Apd, CRec, CRec->DataPtr, 0, CRec->OctetLength);
Expand Down Expand Up @@ -163,14 +163,14 @@ SQLRETURN MADB_SetBulkOperLengthArr(MADB_Stmt *Stmt, MADB_DescRecord *CRec, SQLL
continue;
}

if (OctetLengthPtr != NULL && OctetLengthPtr[row] == SQL_NULL_DATA
|| IndicatorPtr != NULL && IndicatorPtr[row] != SQL_NULL_DATA)
if ((OctetLengthPtr != NULL && OctetLengthPtr[row] == SQL_NULL_DATA)
|| (IndicatorPtr != NULL && IndicatorPtr[row] != SQL_NULL_DATA))
{
RETURN_ERROR_OR_CONTINUE(MADB_SetIndicatorValue(Stmt, MaBind, row, SQL_NULL_DATA));
continue;
}
if (OctetLengthPtr != NULL && OctetLengthPtr[row] == SQL_COLUMN_IGNORE
|| IndicatorPtr != NULL && IndicatorPtr[row] != SQL_COLUMN_IGNORE)
if ((OctetLengthPtr != NULL && OctetLengthPtr[row] == SQL_COLUMN_IGNORE)
|| (IndicatorPtr != NULL && IndicatorPtr[row] != SQL_COLUMN_IGNORE))
{
RETURN_ERROR_OR_CONTINUE(MADB_SetIndicatorValue(Stmt, MaBind, row, SQL_COLUMN_IGNORE));
continue;
Expand Down
12 changes: 7 additions & 5 deletions ma_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,10 @@ SQLRETURN MADB_DbcGetAttr(MADB_Dbc *Dbc, SQLINTEGER Attribute, SQLPOINTER ValueP
Dbc->CatalogName, strlen(Dbc->CatalogName), &Dbc->Error);
ret= SQL_SUCCESS;
}
if (StringLengthPtr)
if (StringLengthPtr != NULL)
{
*StringLengthPtr= (SQLINTEGER)StrLen;
}
return ret;
}
case SQL_ATTR_LOGIN_TIMEOUT:
Expand Down Expand Up @@ -513,7 +515,7 @@ SQLRETURN MADB_Dbc_GetCurrentDB(MADB_Dbc *Connection, SQLPOINTER CurrentDB, SQLI
ret= MA_SQLAllocHandle(SQL_HANDLE_STMT, (SQLHANDLE) Connection, (SQLHANDLE*)&Stmt);
if (!SQL_SUCCEEDED(ret))
return ret;
if (!SQL_SUCCEEDED(Stmt->Methods->ExecDirect(Stmt, (SQLCHAR *)"SELECT IF(DATABASE() IS NOT NULL,DATABASE(),'null')", SQL_NTS)) ||
if (!SQL_SUCCEEDED(Stmt->Methods->ExecDirect(Stmt, (char *)"SELECT IF(DATABASE() IS NOT NULL,DATABASE(),'null')", SQL_NTS)) ||
!SQL_SUCCEEDED(Stmt->Methods->Fetch(Stmt)))
{
MADB_CopyError(&Connection->Error, &Stmt->Error);
Expand Down Expand Up @@ -603,7 +605,7 @@ SQLRETURN MADB_DbcConnectDB(MADB_Dbc *Connection,
}
else
{
MADB_SetDefaultPluginsDir(Connection->mariadb);
MADB_SetDefaultPluginsDir(Connection);
}

/* If a client character set was specified in DSN, we will always use it.
Expand Down Expand Up @@ -1810,12 +1812,12 @@ SQLRETURN MADB_DriverConnect(MADB_Dbc *Dbc, SQLHWND WindowHandle, SQLCHAR *InCon
{
if (StringLength1 == SQL_NTS)
{
StringLength1= (SQLSMALLINT)strlen(InConnectionString);
StringLength1= (SQLSMALLINT)strlen((const char*)InConnectionString);
}
if (OutConnectionString && BufferLength)
{
/* Otherwise we are supposed to simply copy incoming connection string */
strncpy_s((char *)OutConnectionString, BufferLength, InConnectionString, StringLength1);
strncpy_s((char *)OutConnectionString, BufferLength, (const char*)InConnectionString, StringLength1);
}
Length= StringLength1;
}
Expand Down
2 changes: 2 additions & 0 deletions ma_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ MADB_Dbc * MADB_DbcInit(MADB_Env *Env);
SQLRETURN MADB_Dbc_GetCurrentDB(MADB_Dbc *Connection, SQLPOINTER CurrentDB, SQLINTEGER CurrentDBLength,
SQLSMALLINT *StringLengthPtr, my_bool isWChar);
BOOL MADB_SqlMode(MADB_Dbc *Connection, enum enum_madb_sql_mode SqlMode);
/* Has platform versions */
void MADB_SetDefaultPluginsDir(MADB_Dbc *Dbc);

#define MADB_SUPPORTED_CONVERSIONS SQL_CVT_BIGINT | SQL_CVT_BIT | SQL_CVT_CHAR | SQL_CVT_DATE |\
SQL_CVT_DECIMAL | SQL_CVT_DOUBLE | SQL_CVT_FLOAT |\
Expand Down
2 changes: 1 addition & 1 deletion ma_desc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************************
Copyright (C) 2013, 2018 MariaDB Corporation AB
Copyright (C) 2013, 2019 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand Down
10 changes: 8 additions & 2 deletions ma_dsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ my_bool MADB_ReadDSN(MADB_Dsn *Dsn, const char *KeyValue, my_bool OverWrite)
}
else
{
if (Value= strchr(KeyValue, '='))
if ((Value= strchr(KeyValue, '=')) != NULL)
{
++Value;
MADB_RESET(Dsn->DSNName, Value);
Expand Down Expand Up @@ -393,6 +393,8 @@ my_bool MADB_SaveDSN(MADB_Dsn *Dsn)
if (Val && Val[0])
ret= SQLWritePrivateProfileString(Dsn->DSNName, DsnKeys[i].DsnKey, Val, "ODBC.INI");
}
default:
/* To avoid warning with some compilers */
break;
}
if (!ret)
Expand Down Expand Up @@ -585,6 +587,8 @@ SQLULEN MADB_DsnToString(MADB_Dsn *Dsn, char *OutString, SQLULEN OutLength)
{
Value= "1";
}
default:
/* To avoid warning with some compilers */
break;
}
}
Expand All @@ -600,7 +604,9 @@ SQLULEN MADB_DsnToString(MADB_Dsn *Dsn, char *OutString, SQLULEN OutLength)
}

if (OutLength && OutString)
strncpy_s(OutString, OutLength, TmpStr, TotalLength);
{
strncpy_s(OutString, OutLength, TmpStr, TotalLength);
}
return TotalLength;
}
/* }}} */
12 changes: 6 additions & 6 deletions ma_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ int MADB_KeyTypeCount(MADB_Dbc *Connection, char *TableName, int KeyFlag)
unsigned int i;
char StmtStr[1024];
char *p= StmtStr;
char Database[65];
char Database[65]= {'\0'};
MADB_Stmt *Stmt= NULL;
MADB_Stmt *KeyStmt;

Connection->Methods->GetAttr(Connection, SQL_ATTR_CURRENT_CATALOG, Database, 65, NULL, FALSE);
p+= _snprintf(p, 1024, "SELECT * FROM ");
if (Database)
if (Database[0] != '\0')
{
p+= _snprintf(p, 1024 - strlen(p), "`%s`.", Database);
p+= _snprintf(p, sizeof(StmtStr) - strlen(p), "`%s`.", Database);
}
p+= _snprintf(p, 1024 - strlen(p), "%s LIMIT 0", TableName);
p+= _snprintf(p, sizeof(StmtStr) - strlen(p), "%s LIMIT 0", TableName);
if (MA_SQLAllocHandle(SQL_HANDLE_STMT, (SQLHANDLE)Connection, (SQLHANDLE*)&Stmt) == SQL_ERROR ||
Stmt->Methods->ExecDirect(Stmt, (SQLCHAR *)StmtStr, SQL_NTS) == SQL_ERROR ||
Stmt->Methods->ExecDirect(Stmt, (char *)StmtStr, SQL_NTS) == SQL_ERROR ||
Stmt->Methods->Fetch(Stmt) == SQL_ERROR)
{
goto end;
Expand Down Expand Up @@ -1233,7 +1233,7 @@ SQLRETURN MADB_DaeStmt(MADB_Stmt *Stmt, SQLUSMALLINT Operation)
break;
}

if (!SQL_SUCCEEDED(Stmt->DaeStmt->Methods->Prepare(Stmt->DaeStmt, (SQLCHAR *)DynStmt.str, SQL_NTS, FALSE)))
if (!SQL_SUCCEEDED(Stmt->DaeStmt->Methods->Prepare(Stmt->DaeStmt, DynStmt.str, SQL_NTS, FALSE)))
{
MADB_CopyError(&Stmt->Error, &Stmt->DaeStmt->Error);
Stmt->Methods->StmtFree(Stmt->DaeStmt, SQL_DROP);
Expand Down
2 changes: 1 addition & 1 deletion ma_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extern my_bool DummyError;
#define MADB_REALLOC(a,b) realloc((a),(b))

/* If required to free old memory pointed by current ptr, and set new value */
#define MADB_RESET(ptr, newptr) {\
#define MADB_RESET(ptr, newptr) do {\
char *local_new_ptr= (newptr);\
if (local_new_ptr != ptr) {\
free((char*)(ptr));\
Expand Down
2 changes: 1 addition & 1 deletion ma_legacy_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int MADB_ListWalk(MADB_List *list, MADB_ListWalkAction action, char * argument)
}


/************************** MADB_DynString ***************************
/************************** MADB_DynString ***************************/
/*
Code for handling strings with can grow dynamicly.
Copyright Monty Program KB.
Expand Down
2 changes: 1 addition & 1 deletion ma_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ int ParseQuery(MADB_QUERY *Query)
Quote= *p++;
SavePosition= p; /* In case we go past eos while looking for ending quote */
if (Query->NoBackslashEscape || Quote == '`' || /* Backtick works with ANSI_QUOTES */
Query->AnsiQuotes && Quote == '"')/* In indetifier quotation backslash does not escape anything - CLI has error with that */
(Query->AnsiQuotes && Quote == '"'))/* In indetifier quotation backslash does not escape anything - CLI has error with that */
{
SkipQuotedString_Noescapes(&p, end, Quote);
}
Expand Down
6 changes: 3 additions & 3 deletions ma_platform_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ SQLINTEGER SqlwcsOctetLen(const SQLWCHAR *str, SQLINTEGER *CharLen)

if (str)
{
while (inChars > 0 || inChars < 0 && *str)
while (inChars > 0 || (inChars < 0 && *str))
{
result+= DmUnicodeCs->mb_charlen(*str);
--inChars;
Expand Down Expand Up @@ -394,11 +394,11 @@ int GetSourceAnsiCs(Client_Charset *cc)
/* {{{ MADB_DSN_PossibleConnect(MADB_Dsn *) */
BOOL MADB_DSN_PossibleConnect(MADB_Dsn *Dsn)
{
return Dsn->Socket || Dsn->ServerName && Dsn->Port > 0 && Dsn->IsTcpIp;
return Dsn->Socket || (Dsn->ServerName && Dsn->Port > 0 && Dsn->IsTcpIp);
}


/* Stub - atm it looks like we don't need to do anything here */
void MADB_SetDefaultPluginsDir(MYSQL *mariadb)
void MADB_SetDefaultPluginsDir(MADB_Dbc *Dbc)
{
}
4 changes: 2 additions & 2 deletions ma_platform_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ BOOL MADB_DirectoryExists(const char *Path)
return (FileAttributes != INVALID_FILE_ATTRIBUTES) && (FileAttributes & FILE_ATTRIBUTE_DIRECTORY);
}

void MADB_SetDefaultPluginsDir(MYSQL *mariadb)
void MADB_SetDefaultPluginsDir(MADB_Dbc *Dbc)
{
HMODULE hModule = GetModuleHandle(MADB_DRIVER_NAME);
char OurLocation[_MAX_PATH];
Expand All @@ -306,7 +306,7 @@ void MADB_SetDefaultPluginsDir(MYSQL *mariadb)

if (MADB_DirectoryExists(OurLocation) != FALSE)
{
mysql_options(mariadb, MYSQL_PLUGIN_DIR, OurLocation);
mysql_options(Dbc->mariadb, MYSQL_PLUGIN_DIR, OurLocation);
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions ma_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,18 @@ SQLULEN MADB_RowsToFetch(MADB_Cursor *Cursor, SQLULEN ArraySize, unsigned long l
Cursor->RowsetSize= ArraySize;

if (Position + ArraySize > RowsInResultst)
result= (SQLULEN)(RowsInResultst - Position);
{
if (Position >= 0 && RowsInResultst > Position)
{
result= (SQLULEN)(RowsInResultst - Position);
}
else
{
result= 1;
}
}

return result >= 0 ? result : 1;
return result;
}
/* }}} */

12 changes: 7 additions & 5 deletions ma_statement.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************************
Copyright (C) 2013,2018 MariaDB Corporation AB
Copyright (C) 2013,2019 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -444,10 +444,12 @@ void MADB_StmtReset(MADB_Stmt *Stmt)
SQLRETURN MADB_EDPrepare(MADB_Stmt *Stmt)
{
/* TODO: In case of positioned command it shouldn't be always*/
if (Stmt->ParamCount= Stmt->Apd->Header.Count + (MADB_POSITIONED_COMMAND(Stmt) ? MADB_POS_COMM_IDX_FIELD_COUNT(Stmt) : 0))
if ((Stmt->ParamCount= Stmt->Apd->Header.Count + (MADB_POSITIONED_COMMAND(Stmt) ? MADB_POS_COMM_IDX_FIELD_COUNT(Stmt) : 0)) != 0)
{
if (Stmt->params)
{
MADB_FREE(Stmt->params);
}
/* If we have "WHERE CURRENT OF", we will need bind additionaly parameters for each field in the index */
Stmt->params= (MYSQL_BIND *)MADB_CALLOC(sizeof(MYSQL_BIND) * Stmt->ParamCount);
}
Expand Down Expand Up @@ -886,7 +888,7 @@ SQLRETURN MADB_GetOutParams(MADB_Stmt *Stmt, int CurrentOffset)
for (i=0; i < (unsigned int)Stmt->ParamCount && ParameterNr < mysql_stmt_field_count(Stmt->stmt); i++)
{
MADB_DescRecord *IpdRecord, *ApdRecord;
if (IpdRecord= MADB_DescGetInternalRecord(Stmt->Ipd, i, MADB_DESC_READ))
if ((IpdRecord= MADB_DescGetInternalRecord(Stmt->Ipd, i, MADB_DESC_READ))!= NULL)
{
if (IpdRecord->ParameterType == SQL_PARAM_INPUT_OUTPUT ||
IpdRecord->ParameterType == SQL_PARAM_OUTPUT)
Expand Down Expand Up @@ -955,8 +957,8 @@ SQLRETURN MADB_DoExecute(MADB_Stmt *Stmt, BOOL ExecDirect)
MDBUG_C_PRINT(Stmt->Connection, ExecDirect ? "mariadb_stmt_execute_direct(%0x,%s)"
: "mariadb_stmt_execute(%0x)(%s)", Stmt->stmt, STMT_STRING(Stmt));

if (ExecDirect && mariadb_stmt_execute_direct(Stmt->stmt, STMT_STRING(Stmt), strlen(STMT_STRING(Stmt)))
|| !ExecDirect && mysql_stmt_execute(Stmt->stmt))
if ((ExecDirect && mariadb_stmt_execute_direct(Stmt->stmt, STMT_STRING(Stmt), strlen(STMT_STRING(Stmt))))
|| (!ExecDirect && mysql_stmt_execute(Stmt->stmt)))
{
ret= MADB_SetNativeError(&Stmt->Error, SQL_HANDLE_STMT, Stmt->stmt);
MDBUG_C_PRINT(Stmt->Connection, "mysql_stmt_execute:ERROR%s", "");
Expand Down
6 changes: 3 additions & 3 deletions ma_string.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************************
Copyright (C) 2013,2017 MariaDB Corporation AB
Copyright (C) 2013,2019 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -236,7 +236,7 @@ my_bool MADB_DynStrGetWhere(MADB_Stmt *Stmt, MADB_DynString *DynString, char *Ta

MA_SQLAllocHandle(SQL_HANDLE_STMT, Stmt->Connection, (SQLHANDLE*)&CountStmt);
_snprintf(StmtStr, 256, "SELECT * FROM `%s` LIMIT 0", TableName);
CountStmt->Methods->ExecDirect(CountStmt, (SQLCHAR *)StmtStr, SQL_NTS);
CountStmt->Methods->ExecDirect(CountStmt, (char *)StmtStr, SQL_NTS);
FieldCount= mysql_stmt_field_count(((MADB_Stmt *)CountStmt)->stmt);
CountStmt->Methods->StmtFree(CountStmt, SQL_DROP);

Expand Down Expand Up @@ -460,7 +460,7 @@ SQLLEN MbstrOctetLen(const char *str, SQLLEN *CharLen, MARIADB_CHARSET_INFO *cs)
}
else
{
while (inChars > 0 || inChars < 0 && *str)
while (inChars > 0 || (inChars < 0 && *str))
{
result+= cs->mb_charlen(0 + *str);
--inChars;
Expand Down
6 changes: 3 additions & 3 deletions ma_typeconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ SQLRETURN MADB_Str2Ts(const char *Str, size_t Length, MYSQL_TIME *Tm, BOOL Inter
*isTime= 1;
}

if (Frac= strchr(Start, '.')) /* fractional seconds */
if ((Frac= strchr(Start, '.')) != NULL) /* fractional seconds */
{
size_t FracMulIdx= End - (Frac + 1) - 1/*to get index array index */;
/* ODBC - nano-seconds */
if (sscanf(Start, "%d:%u:%u.%6u", &Tm->hour, &Tm->minute,
if (sscanf(Start, "%d:%u:%u.%6lu", &Tm->hour, &Tm->minute,
&Tm->second, &Tm->second_part) < 4)
{
return MADB_SetError(Error, MADB_ERR_22008, NULL, 0);
Expand Down Expand Up @@ -456,7 +456,7 @@ SQLRETURN MADB_TsConversionIsPossible(SQL_TIMESTAMP_STRUCT *ts, SQLSMALLINT SqlT
}
default:
/* This only would be good for SQL_TYPE_TIME. If C type is time(isTime!=0), and SQL type is timestamp, date fields may be NULL - driver should set them to current date */
if (isTime == 0 && ts->year == 0 || ts->month == 0 || ts->day == 0)
if ((isTime == 0 && ts->year == 0) || ts->month == 0 || ts->day == 0)
{
return MADB_SetError(Error, SqlState, NULL, 0);
}
Expand Down
10 changes: 7 additions & 3 deletions odbc_3_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ SQLRETURN MA_SQLAllocHandle(SQLSMALLINT HandleType,
case SQL_HANDLE_DBC:
EnterCriticalSection(&((MADB_Env *)InputHandle)->cs);
MADB_CLEAR_ERROR(&((MADB_Env *)InputHandle)->Error);
if (*OutputHandlePtr = (SQLHANDLE)MADB_DbcInit((MADB_Env *)InputHandle))
if ((*OutputHandlePtr= (SQLHANDLE)MADB_DbcInit((MADB_Env *)InputHandle)) != NULL)
{
ret= SQL_SUCCESS;
}
LeaveCriticalSection(&((MADB_Env *)InputHandle)->cs);
break;
case SQL_HANDLE_DESC:
EnterCriticalSection(&((MADB_Dbc *)InputHandle)->cs);
MADB_CLEAR_ERROR(&((MADB_Dbc *)InputHandle)->Error);
if (*OutputHandlePtr = (SQLHANDLE)MADB_DescInit((MADB_Dbc *)InputHandle, MADB_DESC_UNKNOWN, TRUE))
if ((*OutputHandlePtr= (SQLHANDLE)MADB_DescInit((MADB_Dbc *)InputHandle, MADB_DESC_UNKNOWN, TRUE)) != NULL)
{
ret= SQL_SUCCESS;
}
LeaveCriticalSection(&((MADB_Dbc *)InputHandle)->cs);
break;
case SQL_HANDLE_ENV:
if ((*OutputHandlePtr = (SQLHANDLE)MADB_EnvInit()))
if ((*OutputHandlePtr= (SQLHANDLE)MADB_EnvInit()) != NULL)
{
ret= SQL_SUCCESS;
}
Expand Down
Loading

0 comments on commit 8ce8fd5

Please sign in to comment.