Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AD-621] adapt SqlColAttribute (#79)
### Summary <!--- General summary / title --> adapt the function SQLColAttribute to be ODBC 3.0 compatible. ### Description <!--- Details of what you changed --> adapt the function SQLColAttribute - [x] adapt isAutoIncrement, to be used in SQLColAttribute - [x] adapt `SQL_DESC_AUTO_UNIQUE_VALUE` - [x] make sure `SQL_DESC_CASE_SENSITIVE` is implemented correctly (currently it only handles `JDBC_TYPE_VARCHAR`) and check possible JDBC types returned from JDBC - [x] adapt `SQL_DESC_LITERAL_PREFIX` and `SQL_DESC_LITERAL_SUFFIX` - [x] adapt `SQL_DESC_UNNAMED` - [x] fix adaptation of `SQL_DESC_NUM_PREC_RADIX` - [x] adapt `SQL_DESC_PRECISION` - [x] adapt `SQL_DESC_SCALE` - [x] fix implementation of `SQL_DESC_LENGTH`, `SQL_DESC_OCTET_LENGTH`, and `SQL_COLUMN_LENGTH` - [x] fix implementation of `SQL_DESC_FIXED_PREC_SCALE` Write tests for - [x] get `SQL_DESC_AUTO_UNIQUE_VALUE` by calling SQLColAttribute - [x] get `SQL_DESC_CASE_SENSITIVE` by calling SQLColAttribute - [x] get `SQL_DESC_LITERAL_PREFIX` - [x] prefix: for JDBC_BINARY types (JDBC_TYPE_VARBINARY, and JDBC_TYPE_LONGVARBINARY), make sure "0x" is returned - [x] "'" is supposed to be returned for JDBC *CHAR types for both prefix and suffix. - [x] get `SQL_DESC_LITERAL_SUFFIX` by calling SQLColAttribute - [x] get `SQL_DESC_UNNAMED` by calling SQLColAttribute - [x] get `SQL_DESC_PRECISION` by calling SQLColAttribute - [x] get `SQL_DESC_SCALE` by calling SQLColAttribute - [x] SQL_DESC_BASE_COLUMN_NAME - [x] SQL_DESC_BASE_TABLE_NAME - [x] SQL_DESC_CATALOG_NAME - [x] SQL_DESC_CONCISE_TYPE - [x] SQL_DESC_DISPLAY_SIZE - [x] SQL_DESC_FIXED_PREC_SCALE - [x] SQL_DESC_LABEL - [x] SQL_DESC_LENGTH - [x] SQL_DESC_LITERAL_SUFFIX - [x] SQL_DESC_LOCAL_TYPE_NAME - [x] SQL_DESC_NAME - [x] SQL_DESC_NULLABLE - [x] SQL_DESC_OCTET_LENGTH - [x] SQL_DESC_SCHEMA_NAME - [x] SQL_DESC_SEARCHABLE - [x] SQL_DESC_TABLE_NAME - [x] SQL_DESC_TYPE - [x] SQL_DESC_TYPE_NAME - [x] SQL_DESC_UNSIGNED - [x] SQL_DESC_UPDATABLE Fields that are already (correctly) implemented before this PR: - SQL_DESC_BASE_COLUMN_NAME - SQL_DESC_BASE_TABLE_NAME - SQL_DESC_CATALOG_NAME - SQL_DESC_CONCISE_TYPE - SQL_DESC_DISPLAY_SIZE - SQL_DESC_LABEL - SQL_DESC_LITERAL_SUFFIX - SQL_DESC_LOCAL_TYPE_NAME - SQL_DESC_NAME - SQL_DESC_NULLABLE - SQL_DESC_SCHEMA_NAME - SQL_DESC_SEARCHABLE - SQL_DESC_TABLE_NAME - SQL_DESC_TYPE - SQL_DESC_TYPE_NAME - SQL_DESC_UNSIGNED - SQL_DESC_UPDATABLE For SQL_DESC_SEARCHABLE, SQL_PRED_BASIC is always returned because our DocumentDB JDBC does not support the LIKE operator. For SQL_DESC_UPDATABLE, SQL_ATTR_READWRITE_UNKNOWN is automatically returned. ### Related Issue <!--- Link to issue where this is tracked --> https://bitquill.atlassian.net/browse/AD-621 * [AD-621] add todo for adapting SQL_DESC_COUNT * reason why a TODO (AD-760) is created: Currently our DocDB JDBC only has result sets that are forward only and does not support: { resultSet.last(); count = resultSet.getRow(); } Therefore the task is more complicated than it seems and we may or may not support this feature. * [AD-621] adapt SQL_DESC_CASE_SENSITIVE * [AD-621] adapt SQL_DESC_LITERAL_PREFIX and SQL_DESC_LITERAL_SUFFIX * prefix: for JDBC_BINARY types (JDBC_TYPE_VARBINARY, and JDBC_TYPE_LONGVARBINARY), "0x" is returned * "'" is returned for JDBC *CHAR types for both prefix and suffix. * [AD-621] adapt SQL_DESC_UNNAMED * make value returned from SQL_DESC_UNNAMED match the [reference](https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlcolattribute-function?view=sql-server-ver16). - SQL_DESC_UNNAMED is set to SQL_NAMED if there is a column name or column alias. If there is no column name or a column alias, SQL_DESC_UNNAMED is set to SQL_UNNAMED. * [AD-621] adapt SQL_DESC_NUM_PREC_RADIX * for all non-numeric data types, the `SQL_DESC_NUM_PREC_RADIX` field should be set to 0, not -1. * update test for `num_prec_radix`, as it should not be null. * [AD-621] implement getting decimal digits * decimal digits have a different meaning from precision or scale, so it has its own variable * [AD-621] adapt SQL_DESC_PRECISION * and some reformatting * [AD-621] test for SQL_DESC_CASE_SENSITIVE * [AD-621] add test for SQL_DESC_AUTO_UNIQUE_VALUE * [AD-621] test for SQL_DESC_LITERAL_PREFIX * [AD-621] adapt SQL_COLUMN_SCALE * for scale, return decimal digits for all exact numeric types * [AD-621] add test TestColAttributeDescLiteralSuffix * [AD-621] remove SQL_DESC_COUNT field in ColumnMeta::GetAttribute * the SQL_DESC_COUNT field is already handled in odbc.cpp * [AD-621] add test TestColAttributeDescUnnamed * [AD-621] add test TestColAttributeDescPrecision * [AD-621] add test TestColAttributeDescScale * add implementation for BinaryTypeDecimalDigits. All exact numeric types other than SQL_DECIMAL and SQL_NUMERIC should return 0. * [AD-621] temporarily disable TestColAttributeDescPrecision * [AD-621] add tests * add tests: - TestColAttributeDescBaseColumnName - TestColAttributeDescBaseTableName - TestColAttributeDescCatalogName * [AD-621] add test TestColAttributeDescConciseType * [AD-621] add test TestColAttributeDescCount * [AD-621] update comment * [AD-621] attempt to fix TestColAttributeDescBaseColumnName and TestColAttributeDescBaseTableName * [AD-621] fix TestColAttributeDescCatalogName * [AD-621] make value -1 by default in ColumnMeta::GetAttribute(uint16_t fieldId, SqlLen& value) * [AD-621] fix TestColAttributeDescConciseType * `"columnName": null` in json table does not mean that the column is of NULL type. Therefore I'm replacing the reference of fieldNull to fieldString * [AD-621] add test TestColAttributeDescDisplaySize * [AD-621] test TestColAttributeDescPrecision * removed SQL_TYPE_NULL check because JDBC is not automatically recognizing fields containing null values as JDBC_TYPE_NULL * added test for checking precision values of SQL_VARCHAR * [AD-621] fix TestColAttributeDescDisplaySize * correct the expected value of display size for SQL_TYPE_TIMESTAMP * [AD-621] add test TestColAttributeDescFixedPrecScale * only SQL_FALSE is returned for the field SQL_DESC_FIXED_PREC_SCALE for all possible columns * [AD-621] add test TestColAttributeDescBaseLabel * SQL_DESC_LABEL returns the same value for column name * [AD-621] undo accidental commit merge * [AD-621] add test TestColAttributeDescLength * [AD-621] Refactoring comments * removed commented out code * added comments * [AD-621] update TestColAttributeDescLiteralSuffix * reason: fieldObjectId is recognized as VARCHAR type, therefore it would get the "'" literal instead. So replace fieldObjectId with fieldBoolean, which is non-char and non-binary * [AD-621] add test TestColAttributeDescLocalTypeName * tests local type names for: SQL_DOUBLE, SQL_VARCHAR, SQL_BINARY, SQL_TYPE_TIMESTAMP, SQL_INTEGER * update `req` to `req1` in `TestColAttributeDescPrecision` for a better naming convention * [AD-621] dereference optional int for scale value * this is an attempt to fix the TestColAttributeDescFixedPrecScale test * [AD-621] fix implementation of SQL_DESC_LENGTH, SQL_DESC_OCTET_LENGTH, and SQL_COLUMN_LENGTH * column length should not be the precision value and only the type_traits::BinaryTypeTransferLength function should be used for that value instead * [AD-621] fix test TestColAttributeDescLength * [AD-621] refactor replace `req` with `req1` * update `req` to `req1` in tests for a better naming convention * [AD-621] add test TestColAttributeDescName * [AD-621] add test TestColAttributeDescNullable * fieldObjectId should not be nullable because it contains an primary key id * fields that are not primary keys should be nullable. This is according to settings on JDBC driver * [AD-621] fix TestColAttributeDescLocalTypeName * reason: binary fields would be recognized as type SQL_VARBINARY instead of SQL_BINARY. * [AD-621] fix implementation of SQL_DESC_FIXED_PREC_SCALE * SQL_TRUE if the column has a fixed precision and nonzero scale that are data source-specific. * SQL_FALSE if the column does not have a fixed precision and nonzero scale that are data source specific. * refactor changes * [AD-621] add test TestColAttributeDescNumPrecRadix * tests 3 columns (field float, int, any non-numeric column), each should return 2,10, 0 for precision radix value respectively * [AD-621] fix implementation of SQL_DESC_OCTET_LENGTH * SQL_DESC_LENGTH is the character length of a datatype, and SQL_DESC_OCTET_LENGTH is SQL_DESC_LENGTH in bytes. Therefore, they should have different values if the number of bytes per char is not 1. * [AD-621] add test TestColAttributeDescOctetLength * [AD-621] fix test TestColAttributeDescNullable * meta_queries_test_001__id is the correct primary keys field * [AD-621] fix test TestColAttributeDescNumPrecRadix * added float field in test database * [AD-621] fix implementation of SQL_DESC_SCALE * [AD-621] fix implementation of precision value * JDBC precision/scale value does not apply to ODBC, thus we do not retrieve the precision/scale value from JDBC. * fixed implementation for retrieving column attribute field SQL_DESC_PRECISION. * [AD-621] add test TestColAttributeDescSchemaName * schema name is the database name * [AD-621] add tests added tests: * TestColAttributeDescSearchable * TestColAttributeDescTableName * TestColAttributeDescType * TestColAttributeDescUnsigned * TestColAttributeDescUpdatable * [AD-621] fix test TestColAttributeDescType * and added todo for re-enabling the tests * [AD-621] refactor changes * added debug messages for InternalGetColumnAttribute * [AD-621] add todo link to Jira ticket * [AD-621] add file column_meta_test.cpp * column_meta_test contains unit tests for ColumnMeta::GetAttribute * [AD-621] add checks for GetAttribute with string value * added BOOST checks for calling ColumnMeta::GetAttribute with all of SQL_DESC_* fields that apply * removed unnecessary include <sql.h> * [AD-621] add more checks for retrieving int values * added more boost checks for unit test * [AD-621] resolve code review comments * add function `isCharType` to replace duplicate code * fixed typo * [AD-621] code refactor * added function SqlCharToString to replace duplicate code. The function converts SQLCHAR[] array to a std::string * [AD-621] refactor code * created function callSQLColAttribute to check the return value from the attribute field with the expected string. * removed comment * [AD-621] code refactor * created function callSQLColAttribute to check the return value from the attribute field with the expected int. * added documentation for callSQLColAttribute functions * [AD-621] add more checks for TestGetAttribute * [AD-621] add unit test TestGetAttributeLiteralPrefix * [AD-621] add test TestGetAttributeLiteralSuffix * [AD-621] add unit test TestGetAttributeLocalTypeName * [AD-621] fix implementation * fix implementation of SQL_DESC_UNNAMED * fix implementation of SQL_COLUMN_PRECISION and SQL_COLUMN_SCALE. Added check to ensure decimalDigits is not -1. * [AD-621] add unit tests * added unit tests: TestGetAttributeCaseSensitive, TestGetAttributeConciseTypeAndType, TestGetAttributeDisplaySize, TestGetAttributeLength, TestGetAttributeOctetLength, TestGetAttributeNullable, TestGetAttributeNumPrecRadix, TestGetAttributePrecision, TestGetAttributeScale, TestGetAttributeUnnamed, TestGetAttributeUnsigned * [AD-621] Add test that checks multiple columns * add test TestColAttributeDataTypesAndColumnNames * [AD-621] code refactor * added function connectToLocalServer to reduce the amount of duplicate code * [AD-621] code refactor * removed duplicate code * removed extra line * [AD-621] fix unit test TestGetAttributeOctetLength * changed the expected value for JDBC_TYPE_DATE, JDBC_TYPE_TIME, JDBC_TYPE_TIMESTAMP * refactored to re-use variable size_of_char
- Loading branch information