Help Center

CODBCStmt.GetStatisticsmethod

Retrieves a list of statistics about a single table and the indexes associated with the table.

DatabasesmethodCODBCStmt.incdocumented

Syntax

FUNCTION GetStatistics (BYREF wszCatalogName AS WSTRING, BYVAL CatalogNameLength AS SQLSMALLINT, BYREF wszSchemaName AS WSTRING, BYVAL SchemaNameLength AS SQLSMALLINT, BYREF wszTableName AS WSTRING, BYVAL TableNameLength AS SQLSMALLINT, BYVAL fUnique AS SQLUSMALLINT, BYVAL fCardinality AS SQLUSMALLINT) AS SQLRETURN

Parameters

NameDescription
hStmtStatement handle.
wszCatalogNameProcedure catalog. If a driver supports catalogs for some tables but not for others, such as when the driver retrieves data from different DBMSs, an empty string ("") denotes those tables that do not have catalogs. wszCatalogName cannot contain a string search pattern.
CatalogNameLengthLength of wszCatalogName.
wszSchemaNameString search pattern for procedure schema names. If a driver supports schemas for some procedures but not for others, such as when the driver retrieves data from different DBMSs, an empty string ("") denotes those procedures that do not have schemas. wszSchemaName cannot contain a string search pattern.
SchemaNameLengthLength of wszSchemaName.
wszTableNameTable name. wszTableName cannot contain a string search pattern.
If the SQL_ATTR_METADATA_ID statement attribute is set to SQL_TRUE, wszTableName is treated as an identifier and its case is not significant. If it is SQL_FALSE, wszTableName is an ordinary argument; it is treated literally, and its case is significant.
TableNameLengthLength of wszTableName.
fUniqueType of index: SQL_INDEX_UNIQUE or SQL_INDEX_ALL.
fCardinalityIndicates the importance of the CARDINALITY and PAGES columns in the result set. The following options affect the return of the CARDINALITY and PAGES columns only; index information is returned even if CARDINALITY and PAGES are not returned.
SQL_ENSURE requests that the driver unconditionally retrieve the statistics. (Drivers that conform only to the X/Open standard and do not support ODBC extensions will not be able to support SQL_ENSURE.)
SQL_QUICK requests that the driver retrieve the CARDINALITY and PAGES only if they are readily available from the server. In this case, the driver does not ensure that the values are current. (Applications that are written to the X/Open standard will always get SQL_QUICK behavior from ODBC 3.x-compliant drivers.)

Return value

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_STILL_EXECUTING, SQL_ERROR, or SQL_INVALID_HANDLE.

Description

Retrieves a list of statistics about a single table and the indexes associated with the table. The driver returns this information as a result set on the specified statement handle.

Example

#include once "AfxNova/COdbc.inc" USING AfxNova

' // Connect with the database DIM wszConStr AS WSTRING * 260 = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=biblio.mdb" DIM pDbc AS CODBC = wszConStr

' // Allocate an statement object DIM pStmt AS COdbcStmt = @pDbc IF pStmt.Handle = NULL THEN PRINT "Failed to allocate the statement handle": SLEEP : END

DIM cbbytes AS LONG DIM szCatalogName AS ZSTRING * 256 DIM szSchemaName AS ZSTRING * 256 DIM szTableName AS ZSTRING * 129 DIM iNonUnique AS SHORT DIM szIndexQualifier AS ZSTRING * 129 DIM szIndexName AS ZSTRING * 129 DIM iInfoType AS SHORT DIM iOrdinalPosition AS SHORT DIM szColumnName AS ZSTRING * 129 DIM szAscOrDesc AS ZSTRING * 2 DIM lCardinality AS LONG DIM lPages AS LONG DIM szFilterCondition AS ZSTRING * 129

' // Note: Despite calling the SQLStatisticsW function, the GetStatistics ' // method fails if we use unicode variables instead of ansi. szTableName = "Authors" pStmt.GetStatistics(szCatalogName, LEN(szCatalogName), szSchemaName, LEN(szSchemaName), _ szTableName, LEN(szTableName), SQL_INDEX_ALL, SQL_ENSURE)

print pStmt.GetLastResult pStmt.BindCol( 1, @szCatalogName, SIZEOF(szCatalogName), @cbBytes) pStmt.BindCol( 2, @szSchemaName, SIZEOF(szSchemaName), @cbbytes) pStmt.BindCol( 3, @szTableName, SIZEOF(szTableName), @cbbytes) pStmt.BindCol( 4, @iNonUnique, @cbbytes) pStmt.BindCol( 5, @szIndexQualifier, SIZEOF(szIndexQualifier), @cbbytes) pStmt.BindCol( 6, @szIndexName, SIZEOF(szIndexName), @cbbytes) pStmt.BindCol( 7, @iInfoType, @cbbytes) pStmt.BindCol( 8, @iOrdinalPosition, @cbbytes) pStmt.BindCol( 9, @szColumnName, SIZEOF(szColumnName), @cbbytes) pStmt.BindCol(10, @szAscOrDesc, SIZEOF(szAscOrDesc), @cbbytes) pStmt.BindCol(11, @lCardinality, @cbbytes) pStmt.BindCol(12, @lPages, @cbbytes) pStmt.BindCol(13, @szFilterCondition, SIZEOF(szFilterCondition), @cbbytes) DO IF pStmt.Fetch = FALSE THEN EXIT DO ? "Table catalog name: " & szCatalogName ? "Table schema name: " & szSchemaName ? "Table name: " & szTableName ? "Non unique: " & STR(iNonUnique) ? "Index qualifier: " & szIndexQualifier ? "Index name: " & szIndexName ? "Info type: " & STR(iInfoType) ? "Ordinal position: " & STR(iOrdinalPosition) ? "Column name: " & szColumnName ? "Asc or desc: " & szAscOrDesc ? "Cardinality: " & STR(lCardinality) ? "Pages: " & STR(lPages) ? "Filter condition: " & szFilterCondition PRINT PRINT "Press any key..." SLEEP CLS LOOP

Reference

  • Include file CODBCStmt.inc
  • Defined in AfxNova/COdbcStmt.inc:1955
  • Documented in Databases/ODBC Classes/CODBCStmt Class.md
  • Topic: CODBCStmt Class