Skip to content

Commit

Permalink
Update odbccpp dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mrylov authored and nyalldawson committed May 4, 2021
1 parent 747db18 commit 767a2eb
Show file tree
Hide file tree
Showing 5 changed files with 482 additions and 1 deletion.
121 changes: 121 additions & 0 deletions external/odbccpp/src/odbc/DatabaseMetaData.cpp
Expand Up @@ -96,6 +96,127 @@ ResultSetRef DatabaseMetaData::getPrimaryKeys(const char* catalogName,
return ret;
}
//------------------------------------------------------------------------------
ResultSetRef DatabaseMetaData::getSpecialColumns(
RowIdentifierType identifierType,
const char* catalogName, const char* schemaName, const char* tableName,
RowIdentifierScope scope, ColumnNullableValue nullable)
{
SQLUSMALLINT fColType;
switch (identifierType)
{
case RowIdentifierType::BEST_ROWID:
fColType = SQL_BEST_ROWID;
break;
case RowIdentifierType::ROWVER:
fColType = SQL_ROWVER;
break;
default:
throw Exception("Unknown rowid type");
}

size_t catalogLen = catalogName ? strlen(catalogName) : 0;
size_t schemaLen = schemaName ? strlen(schemaName) : 0;
size_t tableLen = tableName ? strlen(tableName) : 0;

size_t maxLen = (1 << 8 * sizeof(SQLSMALLINT)) - 1;
if (catalogLen > maxLen)
throw Exception("The catalog name is too long");
if (schemaLen > maxLen)
throw Exception("The schema name is too long");
if (tableLen > maxLen)
throw Exception("The table name is too long");

SQLUSMALLINT fScope;
switch (scope)
{
case RowIdentifierScope::CURRENT_ROW:
fScope = SQL_SCOPE_CURROW;
break;
case RowIdentifierScope::TRANSACTION:
fScope = SQL_SCOPE_TRANSACTION;
break;
case RowIdentifierScope::SESSION:
fScope = SQL_SCOPE_SESSION;
break;
default:
throw Exception("Unknown rowid scope");
}

SQLUSMALLINT fNullable;
switch (nullable)
{
case ColumnNullableValue::NO_NULLS:
fNullable = SQL_NO_NULLS;
break;
case ColumnNullableValue::NULLABLE:
fNullable = SQL_NULLABLE;
break;
default:
throw Exception("Unknown nullable value");
}

StatementRef stmt = createStatement();
ResultSetRef ret(new ResultSet(stmt.get()));
EXEC_STMT(SQLSpecialColumnsA, stmt->hstmt_, fColType,
(SQLCHAR*)catalogName, (SQLSMALLINT)catalogLen,
(SQLCHAR*)schemaName, (SQLSMALLINT)schemaLen,
(SQLCHAR*)tableName, (SQLSMALLINT)tableLen,
fScope, fNullable);
return ret;
}
//------------------------------------------------------------------------------
ResultSetRef DatabaseMetaData::getStatistics(
const char* catalogName, const char* schemaName, const char* tableName,
IndexType indexType, StatisticsAccuracy accuracy)
{
size_t catalogLen = catalogName ? strlen(catalogName) : 0;
size_t schemaLen = schemaName ? strlen(schemaName) : 0;
size_t tableLen = tableName ? strlen(tableName) : 0;

size_t maxLen = (1 << 8 * sizeof(SQLSMALLINT)) - 1;
if (catalogLen > maxLen)
throw Exception("The catalog name is too long");
if (schemaLen > maxLen)
throw Exception("The schema name is too long");
if (tableLen > maxLen)
throw Exception("The table name is too long");

SQLUSMALLINT fUnique;
switch (indexType)
{
case IndexType::ALL:
fUnique = SQL_INDEX_ALL;
break;
case IndexType::UNIQUE:
fUnique = SQL_INDEX_UNIQUE;
break;
default:
throw Exception("Unknown index type");
}

SQLUSMALLINT fAccuracy;
switch (accuracy)
{
case StatisticsAccuracy::ENSURE:
fAccuracy = SQL_ENSURE;
break;
case StatisticsAccuracy::QUICK:
fAccuracy = SQL_QUICK;
break;
default:
throw Exception("Unknown statistics accuracy");
}

StatementRef stmt = createStatement();
ResultSetRef ret(new ResultSet(stmt.get()));
EXEC_STMT(SQLStatisticsA, stmt->hstmt_,
(SQLCHAR*)catalogName, (SQLSMALLINT)catalogLen,
(SQLCHAR*)schemaName, (SQLSMALLINT)schemaLen,
(SQLCHAR*)tableName, (SQLSMALLINT)tableLen,
fUnique, fAccuracy);
return ret;
}
//------------------------------------------------------------------------------
ResultSetRef DatabaseMetaData::getTables(const char* catalogName,
const char* schemaName, const char* tableName, const char* tableType)
{
Expand Down
76 changes: 75 additions & 1 deletion external/odbccpp/src/odbc/DatabaseMetaData.h
Expand Up @@ -112,7 +112,7 @@ class ODBC_EXPORT DatabaseMetaData : public DatabaseMetaDataBase
* 5. Primary column sequence number in key (1-based)
* 6. Primary key name
*
* This functions uses the ODBC function SQLPrimaryKeys. Refer to its
* This function uses the ODBC function SQLPrimaryKeys. Refer to its
* documentation for further details on the data in the ResultSet object.
*
* @param catalogName A string indicating the catalog name.
Expand All @@ -126,6 +126,80 @@ class ODBC_EXPORT DatabaseMetaData : public DatabaseMetaDataBase
const char* schemaName,
const char* tableName);

/**
* Retrieves information about the unique row identifier of a table.
*
* The list of columns is returned as a ResultSet object, in which each
* returned row has the following columns:
* 1. Actual scope of the rowid
* 2. Column name
* 3. SQL data type
* 4. Data source-dependent data type name
* 5. The size of the column on the data source
* 6. The length in bytes of data transferred
* 7. The decimal digits of the column on the data source
* 8. Indicates whether the column is a pseudo-column
*
* This function uses the ODBC function SQLSpecialColumns. Refer to its
* documentation for further details on the data in the ResultSet object.
*
* @param identifierType Type of unique row identifier to return.
* @param catalogName A string indicating the catalog name.
* @param schemaName A string indicating the schema name.
* @param tableName A string indicating the table name.
* @param scope Minimum required scope of the rowid.
* @param nullable Determines whether to return special columns that
* can have a NULL value.
* @return Returns a ResultSet object containing the
* unique row identifier information.
*/
ResultSetRef getSpecialColumns(
RowIdentifierType identifierType,
const char* catalogName,
const char* schemaName,
const char* tableName,
RowIdentifierScope scope,
ColumnNullableValue nullable);

/**
* Retrieves the statistics about the specified table and its indexes.
*
* The list of columns is returned as a ResultSet object, in which each
* returned row has the following columns:
* 1. Catalog name of the table
* 2. Schema name of the table
* 3. Table name of the table
* 4. Indicates whether the index does not allow duplicate values
* 5. The identifier that is used to qualify the index name doing a
* DROP INDEX
* 6. Index name
* 7. Type of information being returned
* 8. Column sequence number in index (starting with 1)
* 9. Column name
* 10. Sort sequence for the column: "A" for ascending; "D" for
* descending
* 11. Cardinality of table or index
* 12. Number of pages used to store the index or table
* 13. If the index is a filtered index
*
* This function uses the ODBC function SQLStatistics. Refer to its
* documentation for further details on the data in the ResultSet object.
*
* @param catalogName A string indicating the catalog name.
* @param schemaName A string indicating the schema name.
* @param tableName A string indicating the table name.
* @param indexType Type of index.
* @param accuracy Indicates the accuracy of the returned statistics.
* @return Returns a ResultSet object containing the statistics
* about the specified table and its indexes.
*/
ResultSetRef getStatistics(
const char* catalogName,
const char* schemaName,
const char* tableName,
IndexType indexType,
StatisticsAccuracy accuracy);

/**
* Retrieves a description of the tables that are available in the connected
* database.
Expand Down
121 changes: 121 additions & 0 deletions external/odbccpp/src/odbc/DatabaseMetaDataUnicode.cpp
Expand Up @@ -108,6 +108,127 @@ ResultSetRef DatabaseMetaDataUnicode::getPrimaryKeys(
return ret;
}
//------------------------------------------------------------------------------
ResultSetRef DatabaseMetaDataUnicode::getSpecialColumns(
RowIdentifierType identifierType, const char16_t* catalogName,
const char16_t* schemaName, const char16_t* tableName,
RowIdentifierScope scope, ColumnNullableValue nullable)
{
SQLUSMALLINT fColType;
switch (identifierType)
{
case RowIdentifierType::BEST_ROWID:
fColType = SQL_BEST_ROWID;
break;
case RowIdentifierType::ROWVER:
fColType = SQL_ROWVER;
break;
default:
throw Exception("Unknown rowid type");
}

size_t catalogLen = catalogName ? strlen16(catalogName) : 0;
size_t schemaLen = schemaName ? strlen16(schemaName) : 0;
size_t tableLen = tableName ? strlen16(tableName) : 0;

size_t maxLen = (1 << 8 * sizeof(SQLSMALLINT)) - 1;
if (catalogLen > maxLen)
throw Exception("The catalog name is too long");
if (schemaLen > maxLen)
throw Exception("The schema name is too long");
if (tableLen > maxLen)
throw Exception("The table name is too long");

SQLUSMALLINT fScope;
switch (scope)
{
case RowIdentifierScope::CURRENT_ROW:
fScope = SQL_SCOPE_CURROW;
break;
case RowIdentifierScope::TRANSACTION:
fScope = SQL_SCOPE_TRANSACTION;
break;
case RowIdentifierScope::SESSION:
fScope = SQL_SCOPE_SESSION;
break;
default:
throw Exception("Unknown rowid scope");
}

SQLUSMALLINT fNullable;
switch (nullable)
{
case ColumnNullableValue::NO_NULLS:
fNullable = SQL_NO_NULLS;
break;
case ColumnNullableValue::NULLABLE:
fNullable = SQL_NULLABLE;
break;
default:
throw Exception("Unknown nullable value");
}

StatementRef stmt = createStatement();
ResultSetRef ret(new ResultSet(stmt.get()));
EXEC_STMT(SQLSpecialColumnsW, stmt->hstmt_, fColType,
(SQLWCHAR*)catalogName, (SQLSMALLINT)catalogLen,
(SQLWCHAR*)schemaName, (SQLSMALLINT)schemaLen,
(SQLWCHAR*)tableName, (SQLSMALLINT)tableLen,
fScope, fNullable);
return ret;
}
//------------------------------------------------------------------------------
ResultSetRef DatabaseMetaDataUnicode::getStatistics(const char16_t* catalogName,
const char16_t* schemaName, const char16_t* tableName,
IndexType indexType, StatisticsAccuracy accuracy)
{
size_t catalogLen = catalogName ? strlen16(catalogName) : 0;
size_t schemaLen = schemaName ? strlen16(schemaName) : 0;
size_t tableLen = tableName ? strlen16(tableName) : 0;

size_t maxLen = (1 << 8 * sizeof(SQLSMALLINT)) - 1;
if (catalogLen > maxLen)
throw Exception("The catalog name is too long");
if (schemaLen > maxLen)
throw Exception("The schema name is too long");
if (tableLen > maxLen)
throw Exception("The table name is too long");

SQLUSMALLINT fUnique;
switch (indexType)
{
case IndexType::ALL:
fUnique = SQL_INDEX_ALL;
break;
case IndexType::UNIQUE:
fUnique = SQL_INDEX_UNIQUE;
break;
default:
throw Exception("Unknown index type");
}

SQLUSMALLINT fAccuracy;
switch (accuracy)
{
case StatisticsAccuracy::ENSURE:
fAccuracy = SQL_ENSURE;
break;
case StatisticsAccuracy::QUICK:
fAccuracy = SQL_QUICK;
break;
default:
throw Exception("Unknown statistics accuracy");
}

StatementRef stmt = createStatement();
ResultSetRef ret(new ResultSet(stmt.get()));
EXEC_STMT(SQLStatisticsW, stmt->hstmt_,
(SQLWCHAR*)catalogName, (SQLSMALLINT)catalogLen,
(SQLWCHAR*)schemaName, (SQLSMALLINT)schemaLen,
(SQLWCHAR*)tableName, (SQLSMALLINT)tableLen,
fUnique, fAccuracy);
return ret;
}
//------------------------------------------------------------------------------
ResultSetRef DatabaseMetaDataUnicode::getTables(const char16_t* catalogName,
const char16_t* schemaName, const char16_t* tableName,
const char16_t* tableType)
Expand Down

0 comments on commit 767a2eb

Please sign in to comment.