Skip to content

Commit 3a59789

Browse files
committed
Fix of issue with iOdbc on ARM
We support iOdbc only on MacOS thus can be also formulated - ARM build on MacOS The problem is that iOdbc does nto use exact type of ODBC function pointers fromt he driver, but call them as variadic functions. That created different stack parameters location - in fact only for 10th parameter of SQLSpecialColumns function there 9th and 10th are 2 short parameters going one after another. To solve this we create this API function with different signature that only reads parameters correctly and passes them to the function that will process them.
1 parent bd98b9c commit 3a59789

File tree

6 files changed

+175
-19
lines changed

6 files changed

+175
-19
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ IF(WIN32)
296296
ENDIF()
297297
ENDIF()
298298
ELSE()
299+
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
300+
# This has to be for iOdbc only - the header does that job, we add it fro all ARM builds
301+
SET(MARIADB_ODBC_SOURCES ${MARIADB_ODBC_SOURCES}
302+
iodbc_arm.c)
303+
ENDIF()
299304
SEARCH_LIBRARY(LIB_MATH floor m)
300305
SET(PLATFORM_DEPENDENCIES ${PLATFORM_DEPENDENCIES} ${LIB_MATH})
301306
SET (MARIADB_ODBC_SOURCES ${MARIADB_ODBC_SOURCES}

iodbc_arm.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/************************************************************************************
2+
Copyright (C) 2026 MariaDB Corporation plc
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Library General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Library General Public License for more details.
13+
14+
You should have received a copy of the GNU Library General Public
15+
License along with this library; if not see <http://www.gnu.org/licenses>
16+
or write to the Free Software Foundation, Inc.,
17+
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
18+
*************************************************************************************/
19+
20+
// This is alternative definition for the iOdbc that calls driver ODBC functions as variadic functions,
21+
// and for SQLSpecialColumns that causes on ARM that Nullable does not receive the value. That is observed on Apple.
22+
// with latest iOdbc atm(3.52.16)
23+
// Assumning __aarch64__ is defined on Apple as well and the problem is mainly iOdbc and not Apple's ARM PCS
24+
#ifdef __aarch64__
25+
26+
#include <sqltypes.h>
27+
// This is seemingly the best way to detect iOdbc at compile time. This header is included from its sqltypes and defines this macro
28+
#ifdef _IODBCUNIX_H
29+
30+
#include "ma_api_internal.h"
31+
32+
// We can' pull in this translation unit ODBC API function declarations
33+
#ifndef SQL_INVALID_HANDLE
34+
#define SQL_INVALID_HANDLE (-2)
35+
#endif
36+
37+
// The only purpose of this gunctions is only to read stack parameters correctly and pass them further
38+
/* {{{ SQLSpecialColumns */
39+
SQLRETURN SQL_API SQLSpecialColumns(SQLHSTMT StatementHandle,
40+
SQLUSMALLINT IdentifierType,
41+
SQLCHAR *CatalogName,
42+
SQLSMALLINT NameLength1,
43+
SQLCHAR *SchemaName,
44+
SQLSMALLINT NameLength2,
45+
SQLCHAR *TableName,
46+
SQLSMALLINT NameLength3,
47+
SQLUINTEGER Scope,
48+
SQLUINTEGER Nullable)
49+
{
50+
if (!StatementHandle)
51+
return SQL_INVALID_HANDLE;
52+
return MA_SQLSpecialColumns(StatementHandle,IdentifierType, CatalogName, NameLength1, SchemaName, NameLength2,
53+
TableName, NameLength3, (SQLUSMALLINT)Scope, (SQLUSMALLINT)Nullable);
54+
}
55+
/* }}} */
56+
57+
/* {{{ SQLSpecialColumnsW */
58+
SQLRETURN SQL_API SQLSpecialColumnsW(SQLHSTMT StatementHandle,
59+
SQLUSMALLINT IdentifierType,
60+
SQLWCHAR *CatalogName,
61+
SQLSMALLINT NameLength1,
62+
SQLWCHAR *SchemaName,
63+
SQLSMALLINT NameLength2,
64+
SQLWCHAR *TableName,
65+
SQLSMALLINT NameLength3,
66+
SQLUINTEGER Scope,
67+
SQLUINTEGER Nullable)
68+
{
69+
if (!StatementHandle)
70+
return SQL_INVALID_HANDLE;
71+
72+
return MA_SQLSpecialColumnsW(StatementHandle,IdentifierType, CatalogName, NameLength1, SchemaName, NameLength2,
73+
TableName, NameLength3, (SQLUSMALLINT)Scope, (SQLUSMALLINT)Nullable);
74+
}
75+
/* }}} */
76+
#endif // _IODBCUNIX_H
77+
#endif // __aarch64__

ma_api_internal.c

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ SQLRETURN MA_SQLSetConnectAttr(SQLHDBC ConnectionHandle,
438438
}
439439
/* }}} */
440440

441-
/* {{{ SQLSetStmtAttr */
441+
/* {{{ MA_SQLSetStmtAttr */
442442
SQLRETURN MA_SQLSetStmtAttr(SQLHSTMT StatementHandle,
443443
SQLINTEGER Attribute,
444444
SQLPOINTER ValuePtr,
@@ -461,3 +461,66 @@ SQLRETURN MA_SQLSetStmtAttr(SQLHSTMT StatementHandle,
461461
}
462462
/* }}} */
463463

464+
/* {{{ MA_SQLSpecialColumns */
465+
SQLRETURN MA_SQLSpecialColumns(SQLHSTMT StatementHandle,
466+
SQLUSMALLINT IdentifierType,
467+
SQLCHAR* CatalogName,
468+
SQLSMALLINT NameLength1,
469+
SQLCHAR* SchemaName,
470+
SQLSMALLINT NameLength2,
471+
SQLCHAR* TableName,
472+
SQLSMALLINT NameLength3,
473+
SQLUSMALLINT Scope,
474+
SQLUSMALLINT Nullable)
475+
{
476+
MADB_Stmt* Stmt= (MADB_Stmt*)StatementHandle;
477+
MADB_CLEAR_ERROR(&Stmt->Error);
478+
return Stmt->Methods->SpecialColumns(Stmt, IdentifierType, (char*)CatalogName, NameLength1,
479+
(char*)SchemaName, NameLength2,
480+
(char*)TableName, NameLength3, Scope, Nullable);
481+
}
482+
/* }}} */
483+
484+
/* {{{ MA_SQLSpecialColumnsW */
485+
SQLRETURN MA_SQLSpecialColumnsW(SQLHSTMT StatementHandle,
486+
SQLUSMALLINT IdentifierType,
487+
SQLWCHAR* CatalogName,
488+
SQLSMALLINT NameLength1,
489+
SQLWCHAR* SchemaName,
490+
SQLSMALLINT NameLength2,
491+
SQLWCHAR* TableName,
492+
SQLSMALLINT NameLength3,
493+
SQLUSMALLINT Scope,
494+
SQLUSMALLINT Nullable)
495+
{
496+
MADB_Stmt* Stmt= (MADB_Stmt*)StatementHandle;
497+
SQLRETURN ret;
498+
char* CpCatalog= NULL,
499+
* CpSchema= NULL,
500+
* CpTable= NULL;
501+
SQLULEN CpLength1= 0, CpLength2= 0, CpLength3= 0;
502+
503+
MADB_CLEAR_ERROR(&Stmt->Error);
504+
if (CatalogName != NULL)
505+
{
506+
CpCatalog= MADB_ConvertFromWChar(CatalogName, NameLength1, &CpLength1, Stmt->Connection->ConnOrSrcCharset, NULL);
507+
}
508+
if (SchemaName != NULL)
509+
{
510+
CpSchema= MADB_ConvertFromWChar(SchemaName, NameLength2, &CpLength2, Stmt->Connection->ConnOrSrcCharset, NULL);
511+
}
512+
if (TableName != NULL)
513+
{
514+
CpTable= MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
515+
}
516+
517+
ret= Stmt->Methods->SpecialColumns(Stmt, IdentifierType, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema,
518+
(SQLSMALLINT)CpLength2, CpTable, (SQLSMALLINT)CpLength3, Scope, Nullable);
519+
520+
MADB_FREE(CpCatalog);
521+
MADB_FREE(CpSchema);
522+
MADB_FREE(CpTable);
523+
return ret;
524+
}
525+
/* }}} */
526+

ma_api_internal.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,27 @@ SQLRETURN MA_SQLSetStmtAttr(SQLHSTMT StatementHandle,
8888
SQLPOINTER ValuePtr,
8989
SQLINTEGER StringLength);
9090

91+
SQLRETURN MA_SQLSpecialColumns(SQLHSTMT StatementHandle,
92+
SQLUSMALLINT IdentifierType,
93+
SQLCHAR* CatalogName,
94+
SQLSMALLINT NameLength1,
95+
SQLCHAR* SchemaName,
96+
SQLSMALLINT NameLength2,
97+
SQLCHAR* TableName,
98+
SQLSMALLINT NameLength3,
99+
SQLUSMALLINT Scope,
100+
SQLUSMALLINT Nullable);
101+
102+
SQLRETURN MA_SQLSpecialColumnsW(SQLHSTMT StatementHandle,
103+
SQLUSMALLINT IdentifierType,
104+
SQLWCHAR* CatalogName,
105+
SQLSMALLINT NameLength1,
106+
SQLWCHAR* SchemaName,
107+
SQLSMALLINT NameLength2,
108+
SQLWCHAR* TableName,
109+
SQLSMALLINT NameLength3,
110+
SQLUSMALLINT Scope,
111+
SQLUSMALLINT Nullable);
112+
91113
#endif
92114

ma_statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3241,7 +3241,7 @@ SQLRETURN MADB_StmtGetData(SQLHSTMT StatementHandle,
32413241
}
32423242
else /* IrdRec->InternalBuffer == NULL && Stmt->Lengths[Offset] == 0 */
32433243
{
3244-
CharLength= CharLength= (Stmt->Lengths[Offset] - Stmt->CharOffset[Offset]) / sizeof(SQLWCHAR);
3244+
CharLength= (Stmt->Lengths[Offset] - Stmt->CharOffset[Offset]) / sizeof(SQLWCHAR);
32453245
/*SqlwcsLen((SQLWCHAR*)((char*)IrdRec->InternalBuffer + Stmt->CharOffset[Offset]), -1);*/
32463246
}
32473247

odbc_3_api.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,8 @@ SQLRETURN SQL_API SQLSetStmtOption(SQLHSTMT StatementHandle,
26722672
}
26732673
/* }}} */
26742674

2675+
// Assuming __aarch64__ also defined on Applle and main problem here iOdbc
2676+
#if !defined(__aarch64__) || !defined(_IODBCUNIX_H)
26752677
/* {{{ SQLSpecialColumns */
26762678
SQLRETURN SQL_API SQLSpecialColumns(SQLHSTMT StatementHandle,
26772679
SQLUSMALLINT IdentifierType,
@@ -2684,18 +2686,11 @@ SQLRETURN SQL_API SQLSpecialColumns(SQLHSTMT StatementHandle,
26842686
SQLUSMALLINT Scope,
26852687
SQLUSMALLINT Nullable)
26862688
{
2687-
MADB_Stmt *Stmt= (MADB_Stmt *)StatementHandle;
2689+
MADB_Stmt *Stmt= (MADB_Stmt*)StatementHandle;
26882690
if (!Stmt)
26892691
return SQL_INVALID_HANDLE;
26902692
MADB_CLEAR_ERROR(&Stmt->Error);
2691-
#ifdef _ACTIONS_TRACE_
2692-
#ifdef __APPLE__
2693-
if (getenv("GITHUB_ACTIONS") != NULL && strncmp(getenv("GITHUB_ACTIONS"), "true", 4) == 0 && IdentifierType == SQL_ROWVER)
2694-
{
2695-
printf("# -- Nullable: %hu)\n", Nullable);
2696-
}
2697-
#endif // __APPLE__
2698-
#endif
2693+
26992694
return Stmt->Methods->SpecialColumns(Stmt,IdentifierType, (char *)CatalogName, NameLength1,
27002695
(char *)SchemaName, NameLength2,
27012696
(char *)TableName, NameLength3, Scope, Nullable);
@@ -2737,14 +2732,7 @@ SQLRETURN SQL_API SQLSpecialColumnsW(SQLHSTMT StatementHandle,
27372732
{
27382733
CpTable = MADB_ConvertFromWChar(TableName, NameLength3, &CpLength3, Stmt->Connection->ConnOrSrcCharset, NULL);
27392734
}
2740-
#ifdef _ACTIONS_TRACE_
2741-
#ifdef __APPLE__
2742-
if (getenv("GITHUB_ACTIONS") != NULL && strncmp(getenv("GITHUB_ACTIONS"), "true", 4) == 0 && IdentifierType == SQL_ROWVER)
2743-
{
2744-
printf("# -- Nullable: %hu)\n", Nullable);
2745-
}
2746-
#endif // __APPLE__
2747-
#endif
2735+
27482736
ret= Stmt->Methods->SpecialColumns(Stmt,IdentifierType, CpCatalog, (SQLSMALLINT)CpLength1, CpSchema,
27492737
(SQLSMALLINT)CpLength2, CpTable, (SQLSMALLINT)CpLength3, Scope, Nullable);
27502738
MADB_FREE(CpCatalog);
@@ -2753,6 +2741,7 @@ SQLRETURN SQL_API SQLSpecialColumnsW(SQLHSTMT StatementHandle,
27532741
return ret;
27542742
}
27552743
/* }}} */
2744+
#endif
27562745

27572746
/* {{{ SQLStatistics */
27582747
SQLRETURN SQL_API SQLStatistics(SQLHSTMT StatementHandle,

0 commit comments

Comments
 (0)