From f48d3a517ac26cffb671ccc54b161f50eab4b1b4 Mon Sep 17 00:00:00 2001 From: Lawrin Novitsky Date: Mon, 18 Jan 2016 15:17:51 +0100 Subject: [PATCH] Moved funxtion mapping 2.x to 3.x col attribute identifiers to internal function of SQLColAttribute(w) --- ma_statement.c | 30 +++++++++++++++++++++++++++++- odbc_3_api.c | 26 ++------------------------ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/ma_statement.c b/ma_statement.c index 328acf2c..555aa8d0 100644 --- a/ma_statement.c +++ b/ma_statement.c @@ -2415,6 +2415,26 @@ SQLRETURN MADB_StmtRowCount(MADB_Stmt *Stmt, SQLLEN *RowCountPtr) } /* }}} */ +SQLUSMALLINT MapColAttributeDescType(SQLUSMALLINT FieldIdentifier) +{ + /* we need to map the old field identifiers, see bug ODBC-8 */ + switch (FieldIdentifier) + { + case SQL_COLUMN_SCALE: + return SQL_DESC_SCALE; + case SQL_COLUMN_PRECISION: + return SQL_DESC_PRECISION; + case SQL_COLUMN_NULLABLE: + return SQL_DESC_NULLABLE; + case SQL_COLUMN_LENGTH: + return SQL_DESC_OCTET_LENGTH; + case SQL_COLUMN_NAME: + return SQL_DESC_NAME; + default: + return FieldIdentifier; + } +} + /* {{{ MADB_StmtRowCount */ SQLRETURN MADB_StmtParamCount(MADB_Stmt *Stmt, SQLSMALLINT *ParamCountPtr) { @@ -2460,7 +2480,7 @@ SQLRETURN MADB_StmtColAttr(MADB_Stmt *Stmt, SQLUSMALLINT ColumnNumber, SQLUSMALL } /* We start at offset zero */ - ColumnNumber--; + --ColumnNumber; if (!(Record= MADB_DescGetInternalRecord(Stmt->Ird, ColumnNumber, MADB_DESC_READ))) { @@ -2468,6 +2488,14 @@ SQLRETURN MADB_StmtColAttr(MADB_Stmt *Stmt, SQLUSMALLINT ColumnNumber, SQLUSMALL return Stmt->Error.ReturnValue; } + /* Mapping ODBC2 attributes to ODBC3 + TODO: it looks like it takes more than that + "In ODBC 3.x driver must support SQL_COLUMN_PRECISION and SQL_DESC_PRECISION, SQL_COLUMN_SCALE and SQL_DESC_SCALE, + and SQL_COLUMN_LENGTH and SQL_DESC_LENGTH. These values are different because precision, scale, and length are defined + differently in ODBC 3.x than they were in ODBC 2.x." + */ + FieldIdentifier= MapColAttributeDescType(FieldIdentifier); + switch(FieldIdentifier) { case SQL_DESC_AUTO_UNIQUE_VALUE: NumericAttribute= (SQLLEN)Record->AutoUniqueValue; diff --git a/odbc_3_api.c b/odbc_3_api.c index cee4b082..7fbacfcf 100644 --- a/odbc_3_api.c +++ b/odbc_3_api.c @@ -359,7 +359,6 @@ SQLRETURN SQL_API SQLColAttributeW (SQLHSTMT StatementHandle, MDBUG_C_DUMP(Stmt->Connection, BufferLength, d); MDBUG_C_DUMP(Stmt->Connection, StringLengthPtr, 0x); MDBUG_C_DUMP(Stmt->Connection, NumericAttributePtr, 0x); - ret= Stmt->Methods->ColAttribute(Stmt, ColumnNumber, FieldIdentifier, CharacterAttributePtr, BufferLength, StringLengthPtr, NumericAttributePtr, TRUE); @@ -368,26 +367,6 @@ SQLRETURN SQL_API SQLColAttributeW (SQLHSTMT StatementHandle, } /* }}} */ -SQLUSMALLINT MapColAttributeDescType(SQLUSMALLINT FieldIdentifier) -{ - /* we need to map the old field identifiers, see bug ODBC-8 */ - switch (FieldIdentifier) - { - case SQL_COLUMN_SCALE: - return SQL_DESC_SCALE; - case SQL_COLUMN_PRECISION: - return SQL_DESC_PRECISION; - case SQL_COLUMN_NULLABLE: - return SQL_DESC_NULLABLE; - case SQL_COLUMN_LENGTH: - return SQL_DESC_OCTET_LENGTH; - case SQL_COLUMN_NAME: - return SQL_DESC_NAME; - default: - return FieldIdentifier; - } -} - SQLRETURN SQL_API SQLColAttributes(SQLHSTMT hstmt, SQLUSMALLINT icol, SQLUSMALLINT fDescType, @@ -396,7 +375,7 @@ SQLRETURN SQL_API SQLColAttributes(SQLHSTMT hstmt, SQLSMALLINT * pcbDesc, SQLLEN * pfDesc) { - return SQLColAttribute(hstmt, icol, MapColAttributeDescType(fDescType), rgbDesc, cbDescMax, pcbDesc, pfDesc); + return SQLColAttribute(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc); } SQLRETURN SQL_API SQLColAttributesW(SQLHSTMT hstmt, @@ -407,10 +386,9 @@ SQLRETURN SQL_API SQLColAttributesW(SQLHSTMT hstmt, SQLSMALLINT * pcbDesc, SQLLEN * pfDesc) { - return SQLColAttributeW(hstmt, icol, MapColAttributeDescType(fDescType), rgbDesc, cbDescMax, pcbDesc, pfDesc); + return SQLColAttributeW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc); } - /* {{{ SQLColumnPrivileges */ SQLRETURN SQL_API SQLColumnPrivileges(SQLHSTMT StatementHandle, SQLCHAR *CatalogName,