Skip to content

Commit

Permalink
Merge branch 'odbc-2.0' into odbc-3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrinn committed May 7, 2017
2 parents db72181 + fd9139d commit 66caaec
Show file tree
Hide file tree
Showing 33 changed files with 1,925 additions and 620 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@ ipch
*.diff
*.bak
*.so
*.dylib
Makefile
CPackConfig.cmake
CPackSourceConfig.cmake
Expand Down
17 changes: 14 additions & 3 deletions CMakeLists.txt
Expand Up @@ -22,10 +22,10 @@ cmake_minimum_required(VERSION 2.8)

SET(MARIADB_ODBC_VERSION_MAJOR 3)
SET(MARIADB_ODBC_VERSION_MINOR 0)
SET(MARIADB_ODBC_VERSION_PATCH 0)
SET(MARIADB_ODBC_VERSION_QUALITY "alpha")
SET(MARIADB_ODBC_VERSION_PATCH 1)
SET(MARIADB_ODBC_VERSION_QUALITY "beta")

SET(MARIADB_ODBC_VERSION "03.00.0000")
SET(MARIADB_ODBC_VERSION "03.00.0001")

CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/ma_odbc_version.h.in
${CMAKE_SOURCE_DIR}/ma_odbc_version.h)
Expand Down Expand Up @@ -132,6 +132,17 @@ IF(NOT WIN32)
ENDIF()
ENDIF()

IF(APPLE)
# Looking for iconv files
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/FindIconv.cmake)
IF(ICONV_FOUND)
INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
SET(PLATFORM_DEPENDENCIES ${PLATFORM_DEPENDENCIES} ${ICONV_LIBRARIES})
ELSE()
MESSAGE(FATAL_ERROR "iconv was not found")
ENDIF()
ENDIF()

SET(CPACK_PACKAGE_VERSION ${MARIADB_ODBC_VERSION_MAJOR}.${MARIADB_ODBC_VERSION_MINOR}.${MARIADB_ODBC_VERSION_PATCH})

# TODO: Make it optional
Expand Down
1 change: 1 addition & 0 deletions cmake/FindIconv.cmake
Expand Up @@ -9,6 +9,7 @@ IF(APPLE)
find_path(ICONV_INCLUDE_DIR iconv.h PATHS
/opt/local/include/
/usr/include/
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/
NO_CMAKE_SYSTEM_PATH)
ELSE()
find_path(ICONV_INCLUDE_DIR iconv.h)
Expand Down
38 changes: 31 additions & 7 deletions ma_connection.c
Expand Up @@ -425,13 +425,13 @@ MADB_Dbc *MADB_DbcInit(MADB_Env *Env)
InitializeCriticalSection(&Connection->cs);
/* Not sure that critical section is really needed here - this init routine is called when
no one has the handle yet */
EnterCriticalSection(&Connection->cs);
EnterCriticalSection(&Connection->Environment->cs);

/* Save connection in Environment list */
Connection->ListItem.data= (void *)Connection;
Connection->Environment->Dbcs= MADB_ListAdd(Connection->Environment->Dbcs, &Connection->ListItem);

LeaveCriticalSection(&Connection->cs);
LeaveCriticalSection(&Connection->Environment->cs);

MADB_PutErrorPrefix(NULL, &Connection->Error);

Expand Down Expand Up @@ -462,7 +462,10 @@ SQLRETURN MADB_DbcFree(MADB_Dbc *Connection)
more fingers movements
LOCK_MARIADB(Dbc);*/
if (Connection->mariadb)
{
mysql_close(Connection->mariadb);
Connection->mariadb= NULL;
}
/*UNLOCK_MARIADB(Dbc);*/

/* todo: delete all descriptors */
Expand Down Expand Up @@ -502,7 +505,8 @@ SQLRETURN MADB_Dbc_GetCurrentDB(MADB_Dbc *Connection, SQLPOINTER CurrentDB, SQLI
goto end;
}

ret= Stmt->Methods->GetData(Stmt, 1, SQL_CHAR, Buffer, 65, &Size);
ret= Stmt->Methods->GetData(Stmt, 1, SQL_CHAR, Buffer, 65, &Size, TRUE);

/* Size= (SQLINTEGER)MADB_SetString(isWChar ? Connection->CodePage : 0, CurrentDB,
(isWChar) ? (int)(MIN(Size + sizeof(SQLWCHAR), CurrentDBLength) / sizeof(SQLWCHAR)) :
(int)(MIN(Size + 1, CurrentDBLength)),
Expand Down Expand Up @@ -931,6 +935,9 @@ SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoV
case SQL_CONVERT_CHAR:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, MADB_SUPPORTED_CONVERSIONS, StringLengthPtr);
break;
case SQL_CONVERT_WCHAR:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, MADB_SUPPORTED_CONVERSIONS, StringLengthPtr);
break;
#ifdef SQL_CONVERT_GUID
case SQL_CONVERT_GUID:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, 0, StringLengthPtr);
Expand Down Expand Up @@ -963,6 +970,9 @@ SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoV
case SQL_CONVERT_LONGVARCHAR:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, MADB_SUPPORTED_CONVERSIONS, StringLengthPtr);
break;
case SQL_CONVERT_WLONGVARCHAR:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, MADB_SUPPORTED_CONVERSIONS, StringLengthPtr);
break;
case SQL_CONVERT_NUMERIC:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, MADB_SUPPORTED_CONVERSIONS, StringLengthPtr);
break;
Expand All @@ -987,6 +997,9 @@ SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoV
case SQL_CONVERT_VARCHAR:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, MADB_SUPPORTED_CONVERSIONS, StringLengthPtr);
break;
case SQL_CONVERT_WVARCHAR:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, MADB_SUPPORTED_CONVERSIONS, StringLengthPtr);
break;
case SQL_CONVERT_FUNCTIONS:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, 0, StringLengthPtr);
break;
Expand Down Expand Up @@ -1390,9 +1403,6 @@ SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoV
SLen= (SQLSMALLINT)MADB_SetString(isWChar ? &Dbc->charset : NULL, (void *)InfoValuePtr, BUFFER_CHAR_LEN(BufferLength, isWChar),
"Y", SQL_NTS, &Dbc->Error);
break;
case SQL_POS_OPERATIONS:
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, 0, StringLengthPtr);
break;
case SQL_QUOTED_IDENTIFIER_CASE:
MADB_SET_NUM_VAL(SQLUSMALLINT, InfoValuePtr, SQL_IC_SENSITIVE, StringLengthPtr);
break;
Expand Down Expand Up @@ -1579,7 +1589,21 @@ SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoV
BUFFER_CHAR_LEN(BufferLength, isWChar),
"N", SQL_NTS, &Dbc->Error);
break;
default:
/* 2.0 types */
case SQL_POS_OPERATIONS:
MADB_SET_NUM_VAL(SQLINTEGER, InfoValuePtr, SQL_POS_POSITION | SQL_POS_REFRESH | SQL_POS_UPDATE | SQL_POS_DELETE | SQL_POS_ADD,
StringLengthPtr);
break;
case SQL_STATIC_SENSITIVITY:
MADB_SET_NUM_VAL(SQLINTEGER, InfoValuePtr, SQL_SS_DELETIONS | SQL_SS_UPDATES, StringLengthPtr);
break;
case SQL_LOCK_TYPES:
MADB_SET_NUM_VAL(SQLINTEGER, InfoValuePtr, SQL_LCK_NO_CHANGE, StringLengthPtr);
break;
case SQL_SCROLL_CONCURRENCY:
MADB_SET_NUM_VAL(SQLINTEGER, InfoValuePtr, SQL_SCCO_READ_ONLY | SQL_SCCO_OPT_VALUES, StringLengthPtr);
break;
default:
MADB_SetError(&Dbc->Error, MADB_ERR_HY096, NULL, 0);
return Dbc->Error.ReturnValue;
}
Expand Down
36 changes: 28 additions & 8 deletions ma_desc.c
Expand Up @@ -81,14 +81,14 @@ MADB_Desc *MADB_DescInit(MADB_Dbc *Dbc,enum enum_madb_desc_type DescType, my_boo
Desc->DescType= DescType;
MADB_PutErrorPrefix(Dbc, &Desc->Error);

if (MADB_InitDynamicArray(&Desc->Records, sizeof(MADB_DescRecord), 0, 0))
if (MADB_InitDynamicArray(&Desc->Records, sizeof(MADB_DescRecord), 0, MADB_DESC_INIT_REC_NUM))
{
MADB_FREE(Desc);
return NULL;
}
if (isExternal)
{
if (MADB_InitDynamicArray(&Desc->Stmts, sizeof(MADB_Stmt**), 0, 0))
if (MADB_InitDynamicArray(&Desc->Stmts, sizeof(MADB_Stmt**), 0, MADB_DESC_INIT_STMT_NUM))
{
MADB_DescFree(Desc, FALSE);
return NULL;
Expand Down Expand Up @@ -915,6 +915,10 @@ SQLRETURN MADB_DescSetField(SQLHDESC DescriptorHandle,
case SQL_DESC_CONCISE_TYPE:
DescRecord->ConciseType= (SQLSMALLINT)(SQLLEN)ValuePtr;
DescRecord->Type= MADB_GetTypeFromConciseType(DescRecord->ConciseType);
if (DescRecord->Type == SQL_INTERVAL)
{
DescRecord->DateTimeIntervalCode= DescRecord->ConciseType - 100;
}
break;
case SQL_DESC_DATA_PTR:
DescRecord->DataPtr= ValuePtr;
Expand Down Expand Up @@ -989,31 +993,47 @@ SQLRETURN MADB_DescCopyDesc(MADB_Desc *SrcDesc, MADB_Desc *DestDesc)
MADB_SetError(&DestDesc->Error, MADB_ERR_HY016, NULL, 0);
return SQL_ERROR;
}
if (!SrcDesc->Header.Count)
if (SrcDesc->DescType == MADB_DESC_IRD && !SrcDesc->Header.Count)
{
MADB_SetError(&DestDesc->Error, MADB_ERR_HY007, NULL, 0);
return SQL_ERROR;
}
/* make sure there aren't old records */
MADB_DeleteDynamic(&DestDesc->Records);
if (MADB_InitDynamicArray(&DestDesc->Records, sizeof(MADB_DescRecord),
SrcDesc->Records.elements, SrcDesc->Records.alloc_increment))
SrcDesc->Records.max_element, SrcDesc->Records.alloc_increment))
{
MADB_SetError(&DestDesc->Error, MADB_ERR_HY001, NULL, 0);
return SQL_ERROR;
}

memcpy(&DestDesc->Header, &SrcDesc->Header, sizeof(MADB_Header));
DestDesc->AppType= SrcDesc->AppType;

/* We don't copy AppType from Src to Dest. If we copy internal descriptor to the explicit/external, it stays explicit/external */

DestDesc->DescType= SrcDesc->DescType;
memcpy(&DestDesc->Error, &SrcDesc->Error, sizeof(MADB_Error));

/* Since we never allocate pointers we can just copy content */
memcpy(DestDesc->Records.buffer, SrcDesc->Records.buffer,
SrcDesc->Records.size_of_element * SrcDesc->Records.max_element);
/* todo: internal buffer needs to be clearead or we need to move it outside of
record structure
*/
DestDesc->Records.elements= SrcDesc->Records.elements;

/* internal buffer needs to be clearead or we will get it freed twice with all nice subsequences */
{
unsigned int i;

for (i= 0; i < DestDesc->Records.elements; ++i)
{
MADB_DescRecord *Rec= MADB_DescGetInternalRecord(DestDesc, i, MADB_DESC_READ);

if (Rec != NULL)
{
Rec->InternalBuffer= NULL;
}
}
}

return SQL_SUCCESS;
}
/* }}} */
Expand Down
3 changes: 3 additions & 0 deletions ma_desc.h
Expand Up @@ -24,6 +24,9 @@
#define MADB_DESC_WRITE 2
#define MADB_DESC_RW 3

#define MADB_DESC_INIT_REC_NUM 32
#define MADB_DESC_INIT_STMT_NUM 16

enum enum_madb_desc_type {MADB_DESC_APD= 0, MADB_DESC_ARD, MADB_DESC_IPD, MADB_DESC_IRD, MADB_DESC_UNKNOWN=254};

MADB_DescRecord *MADB_DescGetInternalRecord(MADB_Desc *Desc, SQLSMALLINT RecordNumber, SQLSMALLINT Type);
Expand Down
4 changes: 2 additions & 2 deletions ma_error.c
Expand Up @@ -184,7 +184,7 @@ SQLRETURN MADB_SetNativeError(MADB_Error *Error, SQLSMALLINT HandleType, void *P
break;
}
/* work-around of probalby a bug in mariadb_stmt_execute_direct, that returns 1160 in case of lost connection */
if ((NativeError == 2013 || NativeError == 2006 || NativeError == 1160) && strcmp(Sqlstate, "HY000") == 0)
if ((NativeError == 2013 || NativeError == 2006 || NativeError == 1160) && (strcmp(Sqlstate, "HY000") == 0 || strcmp(Sqlstate, "00000") == 0))
{
Sqlstate= "08S01";
}
Expand Down Expand Up @@ -213,7 +213,7 @@ SQLRETURN MADB_SetError(MADB_Error *Error,
unsigned int ErrorCode= SqlErrorCode;

Error->ErrorNum= 0;
if ((NativeError == 2013 || NativeError == 2006) && SqlErrorCode == MADB_ERR_HY000)
if ((NativeError == 2013 || NativeError == 2006 || NativeError == 1160) && SqlErrorCode == MADB_ERR_HY000)
ErrorCode= MADB_ERR_08S01;

Error->ErrRecord= &MADB_ErrorList[ErrorCode];
Expand Down

0 comments on commit 66caaec

Please sign in to comment.