Skip to content

Commit

Permalink
Moved funxtion mapping 2.x to 3.x col attribute identifiers to internal
Browse files Browse the repository at this point in the history
function of SQLColAttribute(w)
  • Loading branch information
lawrinn committed Jan 18, 2016
1 parent f8a58cd commit f48d3a5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
30 changes: 29 additions & 1 deletion ma_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -2460,14 +2480,22 @@ 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)))
{
MADB_SetError(&Stmt->Error, MADB_ERR_07009, NULL, 0);
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;
Expand Down
26 changes: 2 additions & 24 deletions odbc_3_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit f48d3a5

Please sign in to comment.