Skip to content

Commit

Permalink
better impl of SQLColAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Sep 1, 2017
1 parent 6d329a7 commit d1d3d33
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
7 changes: 7 additions & 0 deletions driver/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ struct TypeInfo
SQLSMALLINT sql_type;
size_t column_size;
size_t octet_length;

inline bool IsIntegerType() const
{
return
sql_type == SQL_TINYINT || sql_type == SQL_SMALLINT ||
sql_type == SQL_INTEGER || sql_type == SQL_BIGINT;
}
};


Expand Down
31 changes: 25 additions & 6 deletions driver/odbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ SQLColAttribute(HSTMT statement_handle, SQLUSMALLINT column_number, SQLUSMALLINT
return doWith<Statement>(statement_handle, [&](Statement & statement) -> RETCODE
{
if (column_number < 1 || column_number > statement.result.getNumColumns())
throw std::runtime_error("Column number is out of range.");
throw SqlException("Column number is out of range.", "07009");

size_t column_idx = column_number - 1;

Expand All @@ -186,6 +186,7 @@ SQLColAttribute(HSTMT statement_handle, SQLUSMALLINT column_number, SQLUSMALLINT
num_value = SQL_FALSE;
break;
case SQL_DESC_BASE_COLUMN_NAME:
str_value = column_info.name;
break;
case SQL_DESC_BASE_TABLE_NAME:
break;
Expand All @@ -204,11 +205,23 @@ SQLColAttribute(HSTMT statement_handle, SQLUSMALLINT column_number, SQLUSMALLINT
num_value = column_info.display_size;
break;
case SQL_DESC_FIXED_PREC_SCALE:
num_value = SQL_FALSE;
break;
case SQL_DESC_LABEL:
str_value = column_info.name;
break;
case SQL_DESC_LENGTH:
if (type_info.sql_type == SQL_VARCHAR)
{
if (column_info.fixed_size)
{
num_value = column_info.fixed_size;
}
else
{
num_value = type_info.octet_length;
}
}
break;
case SQL_DESC_LITERAL_PREFIX:
break;
Expand All @@ -220,9 +233,7 @@ SQLColAttribute(HSTMT statement_handle, SQLUSMALLINT column_number, SQLUSMALLINT
str_value = column_info.name;
break;
case SQL_DESC_NULLABLE:
num_value = SQL_FALSE;
break;
case SQL_DESC_NUM_PREC_RADIX:
num_value = column_info.is_nullable;
break;
case SQL_DESC_OCTET_LENGTH:
if (column_info.fixed_size)
Expand All @@ -236,6 +247,12 @@ SQLColAttribute(HSTMT statement_handle, SQLUSMALLINT column_number, SQLUSMALLINT
break;
case SQL_DESC_PRECISION:
break;
case SQL_DESC_NUM_PREC_RADIX:
if (type_info.IsIntegerType())
{
num_value = 10;
}
break;
case SQL_DESC_SCALE:
break;
case SQL_DESC_SCHEMA_NAME:
Expand All @@ -261,11 +278,13 @@ SQLColAttribute(HSTMT statement_handle, SQLUSMALLINT column_number, SQLUSMALLINT
num_value = SQL_FALSE;
break;
default:
return SQL_ERROR;
throw SqlException(
"Unsupported FieldIdentifier = " + std::to_string(field_identifier),
"HYC00");
}

if (out_num_value)
*static_cast<SQLLEN*>(out_num_value) = num_value;
memcpy(out_num_value, &num_value, sizeof(SQLLEN));

return fillOutputPlatformString(str_value, out_string_value, out_string_value_max_size, out_string_value_size);
});
Expand Down

0 comments on commit d1d3d33

Please sign in to comment.