Skip to content

Commit

Permalink
Merge pull request #34 from Bit-Quill/AT-680
Browse files Browse the repository at this point in the history
AT-680 Column descriptors - SQLDescribeCol
  • Loading branch information
jerrytfleung authored Mar 19, 2021
2 parents 6491ea9 + 04bdc6a commit 849a06b
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 102 deletions.
1 change: 1 addition & 0 deletions src/IntegrationTests/ITODBCHelper/it_odbc_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define SQLSTATE_RESTRICTED_DATA_TYPE_ERROR (SQLWCHAR*)L"07006"
#define SQLSTATE_INVALID_DESCRIPTOR_INDEX (SQLWCHAR*)L"07009"
#define SQLSTATE_GENERAL_ERROR (SQLWCHAR*)L"HY000"
#define SQLSTATE_INVALID_STRING_OR_BUFFER_LENGTH (SQLWCHAR*)L"HY090"
#define SQLSTATE_INVALID_DESCRIPTOR_FIELD_IDENTIFIER (SQLWCHAR*)L"HY091"
#define SQLSTATE_NUMERIC_VALUE_OUT_OF_RANGE (SQLWCHAR*) L"HY019"
#define SQLSTATE_STRING_CONVERSION_ERROR (SQLWCHAR*)L"22018"
Expand Down
531 changes: 440 additions & 91 deletions src/IntegrationTests/ITODBCResults/test_odbc_results.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/odfesqlodbc/es_apifunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ RETCODE SQL_API API_BrowseConnect(HDBC hdbc, const SQLCHAR *szConnStrIn,
SQLCHAR *szConnStrOut,
SQLSMALLINT cbConnStrOutMax,
SQLSMALLINT *pcbConnStrOut);
RETCODE SQL_API ESAPI_DescribeCol(
RETCODE SQL_API API_DescribeCol(
HSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLCHAR *ColumnName,
SQLSMALLINT BufferLength, SQLSMALLINT *NameLength, SQLSMALLINT *DataType,
SQLULEN *ColumnSize, SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable);
Expand Down
2 changes: 1 addition & 1 deletion src/odfesqlodbc/es_parse_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ bool AssignColumnHeaders(QResultClass *q_res,
break;
case Aws::TimestreamQuery::Model::ScalarType::NOT_SET:
default:
// NOT_SET, UNKNOWN & default
// NOT_SET & default
break;
}
} else if (type.ArrayColumnInfoHasBeenSet()) {
Expand Down
2 changes: 1 addition & 1 deletion src/odfesqlodbc/es_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ estype_attr_to_concise_type(const ConnectionClass *conn, OID type,
case ES_TYPE_FLOAT4:
return SQL_REAL;
case TS_TYPE_DOUBLE:
return SQL_FLOAT;
return SQL_DOUBLE;
case TS_TYPE_DATE:
if (EN_is_odbc3(env))
return SQL_TYPE_DATE;
Expand Down
12 changes: 9 additions & 3 deletions src/odfesqlodbc/odbcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,15 @@ RETCODE SQL_API SQLDescribeCol(HSTMT StatementHandle, SQLUSMALLINT ColumnNumber,
if (SC_connection_lost_check(stmt, __FUNCTION__))
return SQL_ERROR;

if (BufferLength < 0) {
SC_set_error(stmt, STMT_INVALID_STRING_OR_BUFFER_LENGTH_ERROR,
"Invalid string or buffer length", __FUNCTION__);
return SQL_ERROR;
}

ENTER_STMT_CS(stmt);
SC_clear_error(stmt);
ret = ESAPI_DescribeCol(StatementHandle, ColumnNumber, ColumnName,
ret = API_DescribeCol(StatementHandle, ColumnNumber, ColumnName,
BufferLength, NameLength, DataType, ColumnSize,
DecimalDigits, Nullable);
LEAVE_STMT_CS(stmt);
Expand Down Expand Up @@ -823,7 +829,7 @@ RETCODE SQL_API SQLDescribeParam(HSTMT hstmt, SQLUSMALLINT ipar,

// COLNUM_ERROR translates to 'invalid descriptor index'
SC_set_error(stmt, STMT_COLNUM_ERROR,
"Elasticsearch does not support parameters.", "SQLNumParams");
"Amazon Timestream does not support parameters.", "SQLDescribeParam");
return SQL_ERROR;
}

Expand Down Expand Up @@ -998,7 +1004,7 @@ RETCODE SQL_API SQLNumParams(HSTMT hstmt, SQLSMALLINT *pcpar) {
return SQL_ERROR;
SC_clear_error(stmt);
SC_set_error(stmt, STMT_NOT_IMPLEMENTED_ERROR,
"Elasticsearch does not support parameters.", "SQLNumParams");
"Amazon Timestream does not support parameters.", "SQLNumParams");
return SQL_SUCCESS_WITH_INFO;
}

Expand Down
8 changes: 7 additions & 1 deletion src/odfesqlodbc/odbcapiw.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ RETCODE SQL_API SQLDescribeColW(HSTMT StatementHandle,
if (SC_connection_lost_check(stmt, __FUNCTION__))
return SQL_ERROR;

if (BufferLength < 0) {
SC_set_error(stmt, STMT_INVALID_STRING_OR_BUFFER_LENGTH_ERROR,
"Invalid string or buffer length", __FUNCTION__);
return SQL_ERROR;
}

buflen = 0;
if (BufferLength > 0)
buflen = BufferLength * 3;
Expand All @@ -255,7 +261,7 @@ RETCODE SQL_API SQLDescribeColW(HSTMT StatementHandle,
break;
}
clName = clNamet;
ret = ESAPI_DescribeCol(StatementHandle, ColumnNumber,
ret = API_DescribeCol(StatementHandle, ColumnNumber,
(SQLCHAR *)clName, buflen, &nmlen, DataType,
ColumnSize, DecimalDigits, Nullable);
if (SQL_SUCCESS_WITH_INFO != ret || nmlen < buflen)
Expand Down
4 changes: 2 additions & 2 deletions src/odfesqlodbc/results.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ RETCODE SQL_API ESAPI_NumResultCols(HSTMT hstmt, SQLSMALLINT *pccol) {
* Return information about the database column the user wants
* information about.
*/
RETCODE SQL_API ESAPI_DescribeCol(HSTMT hstmt, SQLUSMALLINT icol,
RETCODE SQL_API API_DescribeCol(HSTMT hstmt, SQLUSMALLINT icol,
SQLCHAR *szColName, SQLSMALLINT cbColNameMax,
SQLSMALLINT *pcbColName,
SQLSMALLINT *pfSqlType, SQLULEN *pcbColDef,
SQLSMALLINT *pibScale,
SQLSMALLINT *pfNullable) {
CSTR func = "ESAPI_DescribeCol";
CSTR func = "API_DescribeCol";

/* gets all the information about a specific column */
StatementClass *stmt = (StatementClass *)hstmt;
Expand Down
3 changes: 2 additions & 1 deletion src/odfesqlodbc/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ static const struct {
{STMT_INVALID_NULL_ARG, "HY009", "S1009"},
{STMT_NO_RESPONSE, "08S01", "08S01"},
{STMT_COMMUNICATION_ERROR, "08S01", "08S01"},
{STMT_STRING_CONVERSION_ERROR, "22018", "22005"}};
{STMT_STRING_CONVERSION_ERROR, "22018", "22005"},
{STMT_INVALID_STRING_OR_BUFFER_LENGTH_ERROR, "HY090", "HY090"}};

static ES_ErrorInfo *SC_create_errorinfo(const StatementClass *self,
ES_ErrorInfo *eserror_fail_safe) {
Expand Down
3 changes: 2 additions & 1 deletion src/odfesqlodbc/statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ enum {
STMT_INVALID_NULL_ARG,
STMT_NO_RESPONSE,
STMT_COMMUNICATION_ERROR,
STMT_STRING_CONVERSION_ERROR
STMT_STRING_CONVERSION_ERROR,
STMT_INVALID_STRING_OR_BUFFER_LENGTH_ERROR
};

/* statement types */
Expand Down

0 comments on commit 849a06b

Please sign in to comment.