Previous Page TOC Index Next Page



SQLBrowseConnect (ODBC 1.0, Level 2)

SQLBrowseConnect supports an iterative method of discovering and enumerating the attributes and attribute values required to connect to a data source. Each call to SQLBrowseConnect returns successive levels of attributes and attribute values. When all levels have been enumerated, a connection to the data source is completed and a complete connection string is returned by SQLBrowseConnect. A return code of SQL_SUCCESS or SQL_SUCCESS_WITH_INFO indicates that all connection information has been specified and the application is now connected to the data source.

Syntax

RETCODE SQLBrowseConnect(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut)

The SQLBrowseConnect function accepts the following arguments:

Type

Argument

Use

Description

HDBC

hdbc

Input

Connection handle.

UCHAR FAR *

szConnStrIn

Input

Browse request connection string (see "szConnStrIn Argument" in "Comments").

SWORD

cbConnStrIn

Input

Length of szConnStrIn.

UCHAR FAR *

szConnStrOut

Output

Pointer to storage for the browse result connection string (see "szConnStrOut Argument" in "Comments").

SWORD

cbConnStrOutMax

Input

Maximum length of the szConnStrOut buffer.

SWORD FAR *

pcbConnStrOut

Output

The total number of bytes (excluding the null termination byte) available to return in szConnStrOut. If the number of bytes available to return is greater than or equal to cbConnStrOutMax, the connection string in szConnStrOut is truncated to cbConnStrOutMax – 1 bytes.

Returns

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NEED_DATA, SQL_ERROR, or SQL_INVALID_HANDLE.

Diagnostics

When SQLBrowseConnect returns SQL_ERROR, SQL_SUCCESS_WITH_INFO, or SQL_NEED_DATA, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLBrowseConnect and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.

SQLSTATE

Error

Description

01000

General warning

Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.)

01004

Data truncated

The buffer szConnStrOut was not large enough to return entire browse result connection string, so the string was truncated. The argument pcbConnStrOut contains the length of the untruncated browse result connection string. (Function returns SQL_SUCCESS_WITH_INFO.)

01S00

Invalid connection string attribute

An invalid attribute keyword was specified in the browse request connection string (szConnStrIn). (Function returns SQL_NEED_DATA.)

An attribute keyword was specified in the browse request connection string (szConnStrIn) that does not apply to the current connection level. (Function returns SQL_NEED_DATA.)

08001

Unable to connect to data source

The driver was unable to establish a connection with the data source.

08002

Connection in use

(DM) The specified hdbc had already been used to establish a connection with a data source and the connection was open.

08004

Data source rejected establishment of connection

The data source rejected the establishment of the connection for implementation defined reasons.

08S01

Communication link failure

The communication link between the driver and the data source to which the driver was attempting to connect failed before the function completed processing.

28000

Invalid authorization specification

Either the user identifier or the authorization string or both as specified in the browse request connection string (szConnStrIn) violated restrictions defined by the data source.

IM001

Driver does not support this function

(DM) The driver corresponding to the specified data source name does not support the function.

IM002

Data source not found and no default driver specified

(DM) The data source name specified in the browse request connection string (szConnStrIn) was not found in the ODBC.INI file or registry nor was there a default driver specification.

(DM) The ODBC.INI file could not be found.

IM003

Specified driver could not be loaded

(DM) The driver listed in the data source specification in the ODBC.INI file or registry, or specified by the DRIVER keyword was not found or could not be loaded for some other reason.

IM004

Driver’s SQLAllocEnv failed

(DM) During SQLBrowseConnect, the Driver Manager called the driver’s SQLAllocEnv function and the driver returned an error.

IM005

Driver’s SQLAllocConnect failed

(DM) During SQLBrowseConnect, the Driver Manager called the driver’s SQLAllocConnect function and the driver returned an error.

IM006

Driver’s SQLSetConnectOption failed

(DM) During SQLBrowseConnect, the Driver Manager called the driver’s SQLSetConnectOption function and the driver returned an error.

IM009

Unable to load translation DLL

The driver was unable to load the translation DLL that was specified for the data source or for the connection.

IM010

Data source name too long

(DM) The attribute value for the DSN keyword was longer than SQL_MAX_DSN_LENGTH characters.

IM011

Driver name too long

(DM) The attribute value for the DRIVER keyword was longer than 255 characters.

IM012

DRIVER keyword syntax error

(DM) The keyword-value pair for the DRIVER keyword contained a syntax error.

S1000

General error

An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause.

S1001

Memory allocation failure

(DM) The Driver Manager was unable to allocate memory required to support execution or completion of the function.

The driver was unable to allocate memory required to support execution or completion of the function.

S1090

Invalid string or buffer length

(DM) The value specified for argument cbConnStrIn was less than 0 and was not equal to SQL_NTS.

(DM) The value specified for argument cbConnStrOutMax was less than 0.

S1T00

Timeout expired

The timeout period expired before the connection to the data source completed. The timeout period is set through SQLSetConnectOption, SQL_LOGIN_TIMEOUT.

Comments

szConnStrIn Argument

A browse request connection string has the following syntax:

connection-string ::= attribute[;] | attribute; connection-string
attribute ::= attribute-keyword=attribute-value | DRIVER={attribute-value}
(The braces are literal; the application must specify them.)
attribute-keyword ::= DSN | UID | PWD | driver-defined-attribute-keyword
attribute-value ::= character-string
driver-defined-attribute-keyword ::= identifier

where character-string has zero or more characters; identifier has one or more characters; attribute-keyword is case insensitive; attribute-value may be case sensitive; and the value of the DSN keyword does not consist solely of blanks. Because of connection string and initialization file grammar, keywords and attribute values that contain the characters []{}(),;?*=!@ should be avoided. Because of the registry grammar, keywords and data source names cannot contain the backslash (\) character.


Note The DRIVER keyword was introduced in ODBC 2.0 and is not supported by ODBC 1.0 drivers.

If any keywords are repeated in the browse request connection string, the driver uses the value associated with the first occurrence of the keyword. If the DSN and DRIVER keywords are included in the same browse request connection string, the Driver Manager and driver use whichever keyword appears first.

szConnStrOut Argument

The browse result connection string is a list of connection attributes. A connection attribute consists of an attribute keyword and a corresponding attribute value. The browse result connection string has the following syntax:

connection-string ::= attribute[;] | attribute; connection-string
attribute ::= [*]attribute-keyword=attribute-value
attribute-keyword ::= ODBC-attribute-keyword |
driver-defined-attribute-keyword
ODBC-attribute-keyword = {UID | PWD}[:localized-identifier]
driver-defined-attribute-keyword ::= identifer[:localized-identifier]
attribute-value ::= {attribute-value-list} | ?
(The braces are literal; they are returned by the driver.)
attribute-value-list ::= character-string |
character-string, attribute-value-list

where character-string has zero or more characters; identifier and localized-identifier have one or more characters;attribute-keyword is case insensitive; and attribute-value may be case sensitive. Because of connection string and initialization file grammar, keywords, localized identifiers, and attribute values that contain the characters []{}(),;?*=!@ should be avoided. Because of the registry grammar, keywords and data source names cannot contain the backslash (\) character.

The browse result connection string syntax is used according to the following semantic rules:

Using SQLBrowseConnect

SQLBrowseConnect requires an allocated hdbc. The Driver Manager loads the driver that was specified in or that corresponds to the data source name specified in the initial browse request connection string; for information on when this occurs, see the "Comments" section in SQLConnect. It may establish a connection with the data source during the browsing process. If SQLBrowseConnect returns SQL_ERROR, outstanding connections are terminated and the hdbc is returned to an unconnected state.

When SQLBrowseConnect is called for the first time on an hdbc, the browse request connection string must contain the DSN keyword or the DRIVER keyword. If the browse request connection string contains the DSN keyword, the Driver Manager locates a corresponding data source specification in the ODBC.INI file or registry:

If the browse request connection string contains the DRIVER keyword, the Driver Manager loads the specified driver; it does not attempt to locate a data source in the ODBC.INI file or registry. Because the DRIVER keyword does not use information from the ODBC.INI file or registry, the driver must define enough keywords so that a driver can connect to a data source using only the information in the browse request connection strings.

On each call to SQLBrowseConnect, the application specifies the connection attribute values in the browse request connection string. The driver returns successive levels of attributes and attribute values in the browse result connection string; it returns SQL_NEED_DATA as long as there are connection attributes that have not yet been enumerated in the browse request connection string. The application uses the contents of the browse result connection string to build the browse request connection string for the next call to SQLBrowseConnect. Note that the application cannot use the contents of previous browse result connection strings when building the current browse request connection string; that is, it cannot specify different values for attributes set in previous levels.

When all levels of connection and their associated attributes have been enumerated, the driver returns SQL_SUCCESS, the connection to the data source is complete, and a complete connection string is returned to the application. The connection string is suitable to use in conjunction with SQLDriverConnect with the SQL_DRIVER_NOPROMPT option to establish another connection.

SQLBrowseConnect also returns SQL_NEED_DATA if there are recoverable, nonfatal errors during the browse process, for example, an invalid password supplied by the application or an invalid attribute keyword supplied by the application. When SQL_NEED_DATA is returned and the browse result connection string is unchanged, an error has occurred and the application must call SQLError to return the SQLSTATE for browse-time errors. This permits the application to correct the attribute and continue the browse.

An application may terminate the browse process at any time by calling SQLDisconnect. The driver will terminate any outstanding connections and return the hdbc to an unconnected state.

For more information, see "Connection Browsing With SQLBrowseConnect" in Chapter 5, "Establishing Connections."

If a driver supports SQLBrowseConnect, the driver keyword section of the ODBC.INF file for the driver must contain the ConnectFunctions keyword with the third character set to "Y".

Code Example

In the following example, an application calls SQLBrowseConnect repeatedly. Each time SQLBrowseConnect returns SQL_NEED_DATA, it passes back information about the data it needs in szConnStrOut. The application passes szConnStrOut to its routine GetUserInput (not shown). GetUserInput parses the information, builds and displays a dialog box, and returns the information entered by the user in szConnStrIn. The application passes the user’s information to the driver in the next call to SQLBrowseConnect. After the application has provided all necessary information for the driver to connect to the data source, SQLBrowseConnect returns SQL_SUCCESS and the application proceeds.

For example, to connect to the data source My Source, the following actions might occur. First, the application passes the following string to SQLBrowseConnect:

"DSN=My Source"

The Driver Manager loads the driver associated with the data source My Source. It then calls the driver’s SQLBrowseConnect function with the same arguments it received from the application. The driver returns the following string in szConnStrOut.

"HOST:Server={red,blue,green};UID:ID=?;PWD:Password=?"

The application passes this string to its GetUserInput routine, which builds a dialog box that asks the user to select the red, blue, or green server, and to enter a user ID and password. The routine passes the following user-specified information back in szConnStrIn, which the application passes to SQLBrowseConnect:

"HOST=red;UID=Smith;PWD=Sesame"

SQLBrowseConnect uses this information to connect to the red server as Smith with the password Sesame, then returns the following string in szConnStrOut:

"*DATABASE:Database={master,model,empdata}"

The application passes this string to its GetUserInput routine, which builds a dialog box that asks the user to select a database. The user selects empdata and the application calls SQLBrowseConnect a final time with the string:

"DATABASE=empdata"

This is the final piece of information the driver needs to connect to the data source; SQLBrowseConnect returns SQL_SUCCESS and szConnStrOut contains the completed connection string:

"DSN=My Source;HOST=red;UID=Smith;PWD=Sesame;DATABASE=empdata"
#define BRWS_LEN 100
HENV    henv;
HDBC    hdbc;
HSTMT   hstmt;
RETCODE retcode;
UCHAR   szConnStrIn[BRWS_LEN], szConnStrOut[BRWS_LEN];
SWORD   cbConnStrOut;
retcode = SQLAllocEnv(&henv);                 /* Environment handle */
if (retcode == SQL_SUCCESS) {
   retcode = SQLAllocConnect(henv, &hdbc);    /* Connection handle  */
   if (retcode == SQL_SUCCESS) {
      /* Call SQLBrowseConnect until it returns a value other than */
      /* SQL_NEED_DATA (pass the data source name the first time). */
      /* If SQL_NEED_DATA is returned, call GetUserInput (not      */
      /* shown) to build a dialog from the values in szConnStrOut. */
      /* The user-supplied values are returned in szConnStrIn,     */
      /* which is passed in the next call to SQLBrowseConnect.     */
      lstrcpy(szConnStrIn, "DSN=MyServer");
      do {
         retcode = SQLBrowseConnect(hstmt, szConnStrIn, SQL_NTS,
                               szConnStrOut, BRWS_LEN, &cbConnStrOut)
         if (retcode == SQL_NEED_DATA)
            GetUserInput(szConnStrOut, szConnStrIn);
      } while (retcode == SQL_NEED_DATA);
      if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
         /* Process data after successful connection */
         retcode = SQLAllocStmt(hdbc, &hstmt);
         if (retcode == SQL_SUCCESS) {
            ...;
            ...;
            ...;
            SQLFreeStmt(hstmt, SQL_DROP);
         }
         SQLDisconnect(hdbc);
      }
   }
   SQLFreeConnect(hdbc);
}
SQLFreeEnv(henv);

Related Functions

For information about

See

Allocating a connection handle

SQLAllocConnect

Connecting to a data source

SQLConnect

Disconnecting from a data source

SQLDisconnect

Connecting to a data source using a connection string or dialog box

SQLDriverConnect (extension)

Returning driver descriptions and attributes

SQLDrivers (extension)

Freeing a connection handle

SQLFreeConnect

SQLCancel (ODBC 1.0, Core)

SQLCancel cancels the processing on an hstmt.

Syntax

RETCODE SQLCancel(hstmt)

The SQLCancel function accepts the following argument.

Type

Argument

Use

Description

HSTMT

hstmt

Input

Statement handle.

Returns

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.

Diagnostics

When SQLCancel returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLCancel and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.

SQLSTATE

Error

Description

01000

General warning

Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.)

70100

Operation aborted

The data source was unable to process the cancel request.

IM001

Driver does not support this function

(DM) The driver associated with the hstmt does not support the function.

S1000

General error

An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause.

S1001

Memory allocation failure

The driver was unable to allocate memory required to support execution or completion of the function.

Comments

SQLCancel can cancel the following types of processing on an hstmt:

If an application calls SQLCancel when no processing is being done on the hstmt, SQLCancel has the same effect as SQLFreeStmt with the SQL_CLOSE option; this behavior is defined only for completeness and applications should call SQLFreeStmt to close cursors.

Canceling Asynchronous Processing

After an application calls a function asynchronously, it calls the function repeatedly to determine whether it has finished processing. If the function is still processing, it returns SQL_STILL_EXECUTING. If the function has finished processing, it returns a different code.

After any call to the function that returns SQL_STILL_EXECUTING, an application can call SQLCancel to cancel the function. If the cancel request is successful, the driver returns SQL_SUCCESS. This message does not indicate that the function was actually canceled; it indicates that the cancel request was processed. When or if the function is actually canceled is driver- and data source–dependent. The application must continue to call the original function until the return code is not SQL_STILL_EXECUTING. If the function was successfully canceled, the return code is SQL_ERROR and SQLSTATE S1008 (Operation canceled). If the function completed its normal processing, the return code is SQL_SUCCESS or SQL_SUCCESS_WITH_INFO if the function succeeded or SQL_ERROR and a SQLSTATE other than S1008 (Operation canceled) if the function failed.

Canceling Functions that Need Data

After SQLExecute or SQLExecDirect returns SQL_NEED_DATA and before data has been sent for all data-at-execution parameters, an application can call SQLCancel to cancel the statement execution. After the statement has been canceled, the application can call SQLExecute or SQLExecDirect again. For more information, see SQLBindParameter.

After SQLSetPos returns SQL_NEED_DATA and before data has been sent for all data-at-execution columns, an application can call SQLCancel to cancel the operation. After the operation has been canceled, the application can call SQLSetPos again; canceling does not affect the cursor state or the current cursor position. For more information, see SQLSetPos.

Canceling Functions in Multithreaded Applications

In a multithreaded application, the application can cancel a function that is running synchronously on an hstmt. To cancel the function, the application calls SQLCancel with the same hstmt as that used by the target function, but on a different thread. As in canceling a function running asynchronously, the return code of the SQLCancel only indicates whether the driver processed the request successfully. The return code of the original function indicates whether it completed normally or was canceled.

Related Functions

For information about

See

Assigning storage for a parameter

SQLBindParameter

Executing an SQL statement

SQLExecDirect

Executing a prepared SQL statement

SQLExecute

Freeing a statement handle

SQLFreeStmt

Positioning the cursor in a rowset

SQLSetPos (extension)

Returning the next parameter to send data for

SQLParamData (extension)

Sending parameter data at execution time

SQLPutData (extension)

SQLColAttributes (ODBC 1.0, Core)

SQLColAttributes returns descriptor information for a column in a result set; it cannot be used to return information about the bookmark column (column 0). Descriptor information is returned as a character string, a 32-bit descriptor-dependent value, or an integer value.

Syntax

RETCODE SQLColAttributes(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc)

The SQLColAttributes function accepts the following arguments.

Type

Argument

Use

Description

HSTMT

hstmt

Input

Statement handle.

UWORD

icol

Input

Column number of result data, ordered sequentially from left to right, starting
at 1. Columns may be described in any order.

UWORD

fDescType

Input

A valid descriptor type (see "Comments").

PTR

rgbDesc

Output

Pointer to storage for the descriptor information. The format of the descriptor information returned depends on the fDescType.

SWORD

cbDescMax

Input

Maximum length of the rgbDesc buffer.

SWORD FAR *

pcbDesc

Output

Total number of bytes (excluding the null termination byte for character data) available to return in rgbDesc.

For character data, if the number of bytes available to return is greater than or equal to cbDescMax, the descriptor information in rgbDesc is truncated to cbDescMax – 1 bytes and is null-terminated by the driver.

For all other types of data, the value of cbValueMax is ignored and the driver assumes the size of rgbValue is 32 bits.

SDWORD FAR *

pfDesc

Output

Pointer to an integer value to contain descriptor information for numeric descriptor types, such as SQL_COLUMN_LENGTH.

Returns

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_STILL_EXECUTING, SQL_ERROR, or SQL_INVALID_HANDLE.

Diagnostics

When SQLColAttributes returns either SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLColAttributes and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.

SQLSTATE

Error

Description

01000

General warning

Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.)

01004

Data truncated

The buffer rgbDesc was not large enough to return the entire string value, so the string value was truncated. The argument pcbDesc contains the length of the untruncated string value. (Function returns SQL_SUCCESS_WITH_INFO.)

24000

Invalid cursor state

The statement associated with the hstmt did not return a result set. There were no columns to describe.

IM001

Driver does not support this function

(DM) The driver associated with the hstmt does not support the function.

S1000

General error

An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause.

S1001

Memory allocation failure

The driver was unable to allocate memory required to support execution or completion of the function.

S1002

Invalid column number

(DM) The value specified for the argument icol was 0 and the argument fDescType was not SQL_COLUMN_COUNT.

The value specified for the argument icol was greater than the number of columns in the result set and the argument fDescType was not SQL_COLUMN_COUNT.

S1008

Operation canceled

Asynchronous processing was enabled for the hstmt. The function was called and before it completed execution, SQLCancel was called on the hstmt. Then the function was called again on the hstmt.

The function was called and, before it completed execution, SQLCancel was called on the hstmt from a different thread in a multithreaded application.

S1010

Function sequence error

(DM) The function was called prior to calling SQLPrepare or SQLExecDirect for the hstmt.

(DM) An asynchronously executing function (not this one) was called for the hstmt and was still executing when this function was called.

(DM) SQLExecute, SQLExecDirect, or SQLSetPos was called for the hstmt and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns.

S1090

Invalid string or buffer length

(DM) The value specified for the argument cbDescMax was less than 0.

S1091

Descriptor type out of range

(DM) The value specified for the argument fDescType was in the block of numbers reserved for ODBC descriptor types but was not valid for the version of ODBC supported by the driver (see "Comments").

S1C00

Driver not capable

The value specified for the argument fDescType was in the range of numbers reserved for driver-specific descriptor types but was not supported by the driver.

S1T00

Timeout expired

The timeout period expired before the data source returned the requested information. The timeout period is set through SQLSetStmtOption, SQL_QUERY_TIMEOUT.

SQLColAttributes can return any SQLSTATE that can be returned by SQLPrepare or SQLExecute when called after SQLPrepare and before SQLExecute depending on when the data source evaluates the SQL statement associated with the hstmt.

Comments

SQLColAttributes returns information either in pfDesc or in rgbDesc. Integer information is returned in pfDesc as a 32-bit, signed value; all other formats of information are returned in rgbDesc. When information is returned in pfDesc, the driver ignores rgbDesc, cbDescMax, and pcbDesc. When information is returned in rgbDesc, the driver ignores pfDesc.

The currently defined descriptor types, the version of ODBC in which they were introduced, and the arguments in which information is returned for them are shown below; it is expected that more descriptor types will be defined to take advantage of different data sources. Descriptor types from 0 to 999 are reserved by ODBC; driver developers must reserve values greater than or equal to SQL_COLUMN_DRIVER_START for driver-specific use.

A driver must return a value for each of the descriptor types defined in the following table. If a descriptor type does not apply to a driver or data source, then, unless otherwise stated, the driver returns 0 in pcbDesc or an empty string in rgbDesc.

fDescType

Information
returned in

Description

SQL_COLUMN_AUTO_INCREMENT(ODBC 1.0)

pfDesc

TRUE if the column is autoincrement.

FALSE if the column is not autoincrement or is not numeric.

Auto increment is valid for numeric data type columns only. An application can insert values into an autoincrement column, but cannot update values in the column.

SQL_COLUMN_CASE_SENSITIVE
(ODBC 1.0)

pfDesc

TRUE if the column is treated as case sensitive for collations and comparisons.

FALSE if the column is not treated as case sensitive for collations and comparisons or is noncharacter.

SQL_COLUMN_COUNT
(ODBC 1.0)

pfDesc

Number of columns available in the result set. The icol argument is ignored.

SQL_COLUMN_DISPLAY_SIZE
(ODBC 1.0)

pfDesc

Maximum number of characters required to display data from the column. For more information on display size, see "Precision, Scale, Length, and Display Size" in Appendix D, "Data Types."

SQL_COLUMN_LABEL
(ODBC 2.0)

rgbDesc

The column label or title. For example, a column named EmpName might be labeled Employee Name.

If a column does not have a label, the column name is returned. If the column is unlabeled and unnamed, an empty string is returned.

SQL_COLUMN_LENGTH
(ODBC 1.0)

pfDesc

The length in bytes of data transferred on an SQLGetData or SQLFetch operation if SQL_C_DEFAULT is specified. For numeric data, this size may be different than the size of the data stored on the data source. For more length information, see "Precision, Scale, Length, and Display Size" in Appendix D, "Data Types."

SQL_COLUMN_MONEY
(ODBC 1.0)

pfDesc

TRUE if the column is money data type.

FALSE if the column is not money data type.

SQL_COLUMN_NAME
(ODBC 1.0)

rgbDesc

The column name.

If the column is unnamed, an empty string is returned.

SQL_COLUMN_NULLABLE
(ODBC 1.0)

pfDesc

SQL_NO_NULLS if the column does not accept NULL values.

SQL_NULLABLE if the column accepts NULL values.

SQL_NULLABLE_UNKNOWN if it is not known if the column accepts NULL values.

SQL_COLUMN_OWNER_NAME
(ODBC 2.0)

rgbDesc

The owner of the table that contains the column. The returned value is implementation-defined if the column is an expression or if the column is part of a view. If the data source does not support owners or the owner name cannot be determined, an empty string is returned.

SQL_COLUMN_PRECISION
(ODBC 1.0)

pfDesc

The precision of the column on the data source. For more information on precision, see "Precision, Scale, Length, and Display Size" in Appendix D, "Data Types."

SQL_COLUMN_QUALIFIER_NAME
(ODBC 2.0)

rgbDesc

The qualifier of the table that contains the column. The returned value is implementation-defined if the column is an expression or if the column is part of a view. If the data source does not support qualifiers or the qualifier name cannot be determined, an empty string is returned.

SQL_COLUMN_SCALE
(ODBC 1.0)

pfDesc

The scale of the column on the data source. For more information on scale, see "Precision, Scale, Length, and Display Size" in Appendix D, "Data Types."

SQL_COLUMN_SEARCHABLE
(ODBC 1.0)

pfDesc

SQL_UNSEARCHABLE if the column cannot be used in a WHERE clause.

SQL_LIKE_ONLY if the column can be used in a WHERE clause only with the LIKE predicate.

SQL_ALL_EXCEPT_LIKE if the column can be used in a WHERE clause with all comparison operators except LIKE.

SQL_SEARCHABLE if the column can be used in a WHERE clause with any comparison operator.

Columns of type SQL_LONGVARCHAR and SQL_LONGVARBINARY usually return SQL_LIKE_ONLY.

SQL_COLUMN_TABLE_NAME
(ODBC 2.0)

rgbDesc

The name of the table that contains the column. The returned value is implementation-defined if the column is an expression or if the column is part of a view.

If the table name cannot be determined, an empty string is returned.

SQL_COLUMN_TYPE
(ODBC 1.0)

pfDesc

SQL data type. This can be an ODBC SQL data type or a driver-specific SQL data type. For a list of valid ODBC SQL data types, see "SQL Data Types" in Appendix D, "Data Types." For information about driver-specific SQL data types, see the driver’s documentation.

SQL_COLUMN_TYPE_NAME
(ODBC 1.0)

rgbDesc

Data source–dependent data type name; for example, "CHAR", "VARCHAR", "MONEY", "LONG VARBINARY", or "CHAR ( ) FOR BIT DATA".

If the type is unknown, an empty string is returned.

SQL_COLUMN_UNSIGNED
(ODBC 1.0)

pfDesc

TRUE if the column is unsigned (or not numeric).

FALSE if the column is signed.

SQL_COLUMN_UPDATABLE
(ODBC 1.0)

pfDesc

Column is described by the values for the defined constants:

SQL_ATTR_READONLY
SQL_ATTR_WRITE
SQL_ATTR_READWRITE_UNKNOWN

SQL_COLUMN_UPDATABLE describes the updatability of the column in the result set. Whether a column is updatable can be based on the data type, user privileges, and the definition of the result set itself. If it is unclear whether a column is updatable, SQL_ATTR_READWRITE_UNKNOWN should be returned.

This function is an extensible alternative to SQLDescribeCol. SQLDescribeCol returns a fixed set of descriptor information based on ANSI-89 SQL. SQLColAttributes allows access to the more extensive set of descriptor information available in ANSI SQL-92 and DBMS vendor extensions.

Related Functions

For information about

See

Assigning storage for a column in a result set

SQLBindCol

Canceling statement processing

SQLCancel

Returning information about a column in a result set

SQLDescribeCol

Fetching a block of data or scrolling through a result set

SQLExtendedFetch (extension)

Fetching a row of data

SQLFetch

SQLColumnPrivileges (ODBC 1.0, Level 2)

SQLColumnPrivileges returns a list of columns and associated privileges for the specified table. The driver returns the information as a result set on the specified hstmt.

Syntax

RETCODE SQLColumnPrivileges(hstmt, szTableQualifier, cbTableQualifier, szTableOwner, cbTableOwner, szTableName, cbTableName, szColumnName, cbColumnName)

The SQLColumnPrivileges function accepts the following arguments:

Type

Argument

Use

Description

HSTMT

hstmt

Input

Statement handle.

UCHAR FAR *

szTableQualifier

Input

Table qualifier. If a driver supports qualifiers 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 qualifiers.

SWORD

cbTableQualifier

Input

Length of szTableQualifier.

UCHAR FAR *

szTableOwner

Input

Owner name. If a driver supports owners 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 owners.

SWORD

cbTableOwner

Input

Length of szTableOwner.

UCHAR FAR *

szTableName

Input

Table name.

SWORD

cbTableName

Input

Length of szTableName.

UCHAR FAR *

szColumnName

Input

String search pattern for column names.

SWORD

cbColumnName

Input

Length of szColumnName.

Returns

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_STILL_EXECUTING, SQL_ERROR, or SQL_INVALID_HANDLE.

Diagnostics

When SQLColumnPrivileges returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLColumnPrivileges and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.

SQLSTATE

Error

Description

01000

General warning

Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.)

08S01

Communication link failure

The communication link between the driver and the data source to which the driver was connected failed before the function completed processing.

24000

Invalid cursor state

(DM) A cursor was open on the hstmt and SQLFetch or SQLExtendedFetch had been called.

A cursor was open on the hstmt but SQLFetch or SQLExtendedFetch had not been called.

IM001

Driver does not support this function

(DM) The driver associated with the hstmt does not support the function.

S1000

General error

An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause.

S1001

Memory allocation failure

The driver was unable to allocate memory required to support execution or completion of the function.

S1008

Operation canceled

Asynchronous processing was enabled for the hstmt. The function was called and before it completed execution, SQLCancel was called on the hstmt. Then the function was called again on the hstmt.

The function was called and, before it completed execution, SQLCancel was called on the hstmt from a different thread in a multithreaded application.

S1010

Function sequence error

(DM) An asynchronously executing function (not this one) was called for the hstmt and was still executing when this function was called.

(DM) SQLExecute, SQLExecDirect, or SQLSetPos was called for the hstmt and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns.

S1090

Invalid string or buffer length

(DM) The value of one of the name length arguments was less than 0, but not equal to SQL_NTS.



The value of one of the name length arguments exceeded the maximum length value for the corresponding qualifier or name (see "Comments").

S1C00

Driver not capable

A table qualifier was specified and the driver or data source does not support qualifiers.

A table owner was specified and the driver or data source does not support owners.



A string search pattern was specified for the column name and the data source does not support search patterns for that argument.

The combination of the current settings of the SQL_CONCURRENCY and SQL_CURSOR_TYPE statement options was not supported by the driver or data source.

S1T00

Timeout expired

The timeout period expired before the data source returned the result set. The timeout period is set through SQLSetStmtOption, SQL_QUERY_TIMEOUT.

Comments

SQLColumnPrivileges returns the results as a standard result set, ordered by TABLE_QUALIFIER, TABLE_OWNER, TABLE_NAME, COLUMN_NAME, and PRIVILEGE. The following table lists the columns in the result set.


Note SQLColumnPrivileges might not return privileges for all columns. For example, a driver might not return information about privileges for pseudo-columns, such as ROWID. Applications can use any valid column, regardless of whether it is returned by SQLColumnPrivileges.

The lengths of VARCHAR columns shown in the table are maximums; the actual lengths depend on the data source. To determine the actual lengths of the TABLE_QUALIFIER, TABLE_OWNER, TABLE_NAME, and COLUMN_NAME columns, an application can call SQLGetInfo with the SQL_MAX_QUALIFIER_NAME_LEN, SQL_MAX_OWNER_NAME_LEN, SQL_MAX_TABLE_NAME_LEN, and SQL_MAX_COLUMN_NAME_LEN options.

Column Name

Data Type

Comments

TABLE_QUALIFIER

Varchar(128)

Table qualifier identifier; NULL if not applicable to the data source. If a driver supports qualifiers for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have qualifiers.

TABLE_OWNER

Varchar(128)

Table owner identifier; NULL if not applicable to the data source. If a driver supports owners for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have owners.

TABLE_NAME

Varchar(128)
not NULL

Table identifier.

COLUMN_NAME

Varchar(128)
not NULL

Column identifier.

GRANTOR

Varchar(128)

Identifier of the user who granted the privilege; NULL if not applicable to the data source.

GRANTEE

Varchar(128)
not NULL

Identifier of the user to whom the privilege was granted.

PRIVILEGE

Varchar(128)
not NULL

Identifies the column privilege. May be one of the following or others supported by the data source when implementation-defined:

SELECT: The grantee is permitted to retrieve data for the column.

INSERT: The grantee is permitted to provide data for the column in new rows that are inserted into the associated table.

UPDATE: The grantee is permitted to update data in the column.

REFERENCES: The grantee is permitted to refer to the column within a constraint (for example, a unique, referential, or table check constraint).

IS_GRANTABLE

Varchar(3)

Indicates whether the grantee is permitted to grant the privilege to other users; "YES", "NO", or NULL if unknown or not applicable to the data source.

The szColumnName argument accepts a search pattern. For more information about valid search patterns, see "Search Pattern Arguments" earlier in this chapter.

Code Example

For a code example of a similar function, see SQLColumns.

Related Functions

For information about

See

Assigning storage for a column in a result set

SQLBindCol

Canceling statement processing

SQLCancel

Returning the columns in a table or tables

SQLColumns (extension)

Fetching a block of data or scrolling through a result set

SQLExtendedFetch (extension)

Fetching a row of data

SQLFetch

Returning privileges for a table or tables

SQLTablePrivileges (extension)

Returning a list of tables in a data source

SQLTables (extension)

SQLColumns (ODBC 1.0, Level 1)

SQLColumns returns the list of column names in specified tables. The driver returns this information as a result set on the specified hstmt.

Syntax

RETCODE SQLColumns(hstmt, szTableQualifier, cbTableQualifier, szTableOwner, cbTableOwner, szTableName, cbTableName, szColumnName, cbColumnName)

The SQLColumns function accepts the following arguments:

Type

Argument

Use

Description

HSTMT

hstmt

Input

Statement handle.

UCHAR FAR *

szTableQualifier

Input

Qualifier name. If a driver supports qualifiers 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 qualifiers.

SWORD

cbTableQualifier

Input

Length of szTableQualifier.

UCHAR FAR *

szTableOwner

Input

String search pattern for owner names. If a driver supports owners 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 owners.

SWORD

cbTableOwner

Input

Length of szTableOwner.

UCHAR FAR *

szTableName

Input

String search pattern for table names.

SWORD

cbTableName

Input

Length of szTableName.

UCHAR FAR *

szColumnName

Input

String search pattern for column names.

SWORD

cbColumnName

Input

Length of szColumnName.

Returns

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_STILL_EXECUTING, SQL_ERROR, or SQL_INVALID_HANDLE.

Diagnostics

When SQLColumns returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLError. The following table lists the SQLSTATE values commonly returned by SQLColumns and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.

SQLSTATE

Error

Description

01000

General warning

Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.)

08S01

Communication link failure

The communication link between the driver and the data source to which the driver was connected failed before the function completed processing.

24000

Invalid cursor state

(DM) A cursor was open on the hstmt and SQLFetch or SQLExtendedFetch had been called.

A cursor was open on the hstmt but SQLFetch or SQLExtendedFetch had not been called.

IM001

Driver does not support this function

(DM) The driver associated with the hstmt does not support the function.

S1000

General error

An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLError in the argument szErrorMsg describes the error and its cause.

S1001

Memory allocation failure

The driver was unable to allocate memory required to support execution or completion of the function.

S1008

Operation canceled

Asynchronous processing was enabled for the hstmt. The function was called and before it completed execution, SQLCancel was called on the hstmt. Then the function was called again on the hstmt.

The function was called and, before it completed execution, SQLCancel was called on the hstmt from a different thread in a multithreaded application.

S1010

Function sequence error

(DM) An asynchronously executing function (not this one) was called for the hstmt and was still executing when this function was called.

(DM) SQLExecute, SQLExecDirect, or SQLSetPos was called for the hstmt and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns.

S1090

Invalid string or buffer length

(DM) The value of one of the name length arguments was less than 0, but not equal to SQL_NTS.



The value of one of the name length arguments exceeded the maximum length value for the corresponding qualifier or name. The maximum length of each qualifier or name may be obtained by calling SQLGetInfo with the fInfoType values (see "Comments").

S1C00

Driver not capable

A table qualifier was specified and the driver or data source does not support qualifiers.

A table owner was specified and the driver or data source does not support owners.



A string search pattern was specified for the table owner, table name, or column name and the data source does not support search patterns for one or more of those arguments.

The combination of the current settings of the SQL_CONCURRENCY and SQL_CURSOR_TYPE statement options was not supported by the driver or data source.

S1T00

Timeout expired

The timeout period expired before the data source returned the result set. The timeout period is set through SQLSetStmtOption, SQL_QUERY_TIMEOUT.

Comments

This function is typically used before statement execution to retrieve information about columns for a table or tables from the data source’s catalog. Note by contrast, that the functions SQLColAttributes and SQLDescribeCol describe the columns in a result set and that the function SQLNumResultCols returns the number of columns in a result set.


Note SQLColumns might not return all columns. For example, a driver might not return information about pseudo-columns, such as Oracle ROWID. Applications can use any valid column, regardless of whether it is returned by SQLColumns.

SQLColumns returns the results as a standard result set, ordered by TABLE_QUALIFIER, TABLE_OWNER, and TABLE_NAME. The following table lists the columns in the result set. Additional columns beyond column 12 (REMARKS) can be defined by the driver.

The lengths of VARCHAR columns shown in the table are maximums; the actual lengths depend on the data source. To determine the actual lengths of the TABLE_QUALIFIER, TABLE_OWNER, TABLE_NAME, and COLUMN_NAME columns, an application can call SQLGetInfo with the SQL_MAX_QUALIFIER_NAME_LEN, SQL_MAX_OWNER_NAME_LEN, SQL_MAX_TABLE_NAME_LEN, and SQL_MAX_COLUMN_NAME_LEN options.

Column Name

Data Type

Comments

TABLE_QUALIFIER

Varchar(128)

Table qualifier identifier; NULL if not applicable to the data source. If a driver supports qualifiers for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have qualifiers.

TABLE_OWNER

Varchar(128)

Table owner identifier; NULL if not applicable to the data source. If a driver supports owners for some tables but not for others, such as when the driver retrieves data from different DBMSs, it returns an empty string ("") for those tables that do not have owners.

TABLE_NAME

Varchar(128) not NULL

Table identifier.

COLUMN_NAME

Varchar(128) not NULL

Column identifier.

DATA_TYPE

Smallint not NULL

SQL data type. This can be an ODBC SQL data type or a driver-specific SQL data type. For a list of valid ODBC SQL data types, see "SQL Data Types" in Appendix D, "Data Types." For information about driver-specific SQL data types, see the driver’s documentation.

TYPE_NAME

Varchar(128) not NULL

Data source–dependent data type name; for example, "CHAR", "VARCHAR", "MONEY", "LONG VARBINARY", or "CHAR ( ) FOR BIT DATA".

PRECISION

Integer

The precision of the column on the data source. For precision information, see "Precision, Scale, Length, and Display Size" in Appendix D, "Data Types."

LENGTH

Integer

The length in bytes of data transferred on an SQLGetData or SQLFetch operation if SQL_C_DEFAULT is specified. For numeric data, this size may be different than the size of the data stored on the data source. This value is the same as the PRECISION column for character or binary data. For more information about length, see "Precision, Scale, Length, and Display Size" in Appendix D, "Data Types."

SCALE

Smallint

The scale of the column on the data source. For more scale information, see "Precision, Scale, Length, and Display Size" in Appendix D, "Data Types." NULL is returned for data types where scale is not applicable.

RADIX

Smallint

For numeric data types, either 10 or 2. If it is 10, the values in PRECISION and SCALE give the number of decimal digits allowed for the column. For example, a DECIMAL(12,5) column would return a RADIX of 10, a PRECISION of 12, and a SCALE of 5; A FLOAT column could return a RADIX of 10, a PRECISION of 15 and a SCALE of NULL.

If it is 2, the values in PRECISION and SCALE give the number of bits allowed in the column. For example, a FLOAT column could return a RADIX of 2, a PRECISION of 53, and a SCALE of NULL.

NULL is returned for data types where radix is not applicable.

NULLABLE

Smallint not NULL

SQL_NO_NULLS if the column does not accept NULL values.

SQL_NULLABLE if the column accepts NULL values.

SQL_NULLABLE_UNKNOWN if it is not known if the column accepts NULL values.

REMARKS

Varchar(254)

A description of the column.

The szTableOwner, szTableName, and szColumnName arguments accept search patterns. For more information about valid search patterns, see "Search Pattern Arguments" earlier in this chapter.

Code Example

In the following example, an application declares storage locations for the result set returned by SQLColumns. It calls SQLColumns to return a result set that describes each column in the EMPLOYEE table. It then calls SQLBindCol to bind the columns in the result set to the storage locations. Finally, the application fetches each row of data with SQLFetch and processes it.

#define STR_LEN 128+1
#define REM_LEN 254+1
/* Declare storage locations for result set data */
UCHAR  szQualifier[STR_LEN], szOwner[STR_LEN];
UCHAR  szTableName[STR_LEN], szColName[STR_LEN];
UCHAR  szTypeName[STR_LEN], szRemarks[REM_LEN];
SDWORD Precision, Length;
SWORD  DataType, Scale, Radix, Nullable;
/* Declare storage locations for bytes available to return */
SDWORD cbQualifier, cbOwner, cbTableName, cbColName;
SDWORD cbTypeName, cbRemarks, cbDataType, cbPrecision;
SDWORD cbLength, cbScale, cbRadix, cbNullable;
retcode = SQLColumns(hstmt,
                     NULL, 0,              /* All qualifiers */
                     NULL, 0,              /* All owners     */
                     "EMPLOYEE", SQL_NTS,  /* EMPLOYEE table */
                     NULL, 0);             /* All columns    */
if (retcode == SQL_SUCCESS) {
   /* Bind columns in result set to storage locations */
   SQLBindCol(hstmt, 1, SQL_C_CHAR, szQualifier, STR_LEN,&cbQualifier);
   SQLBindCol(hstmt, 2, SQL_C_CHAR, szOwner, STR_LEN, &cbOwner);
   SQLBindCol(hstmt, 3, SQL_C_CHAR, szTableName, STR_LEN,&cbTableName);
   SQLBindCol(hstmt, 4, SQL_C_CHAR, szColName, STR_LEN, &cbColName);
   SQLBindCol(hstmt, 5, SQL_C_SSHORT, &DataType, 0, &cbDataType);
   SQLBindCol(hstmt, 6, SQL_C_CHAR, szTypeName, STR_LEN, &cbTypeName);
   SQLBindCol(hstmt, 7, SQL_C_SLONG, &Precision, 0, &cbPrecision);
   SQLBindCol(hstmt, 8, SQL_C_SLONG, &Length, 0, &cbLength);
   SQLBindCol(hstmt, 9, SQL_C_SSHORT, &Scale, 0, &cbScale);
   SQLBindCol(hstmt, 10, SQL_C_SSHORT, &Radix, 0, &cbRadix);
   SQLBindCol(hstmt, 11, SQL_C_SSHORT, &Nullable, 0, &cbNullable);
   SQLBindCol(hstmt, 12, SQL_C_CHAR, szRemarks, REM_LEN, &cbRemarks);
   while(TRUE) {
      retcode = SQLFetch(hstmt);
      if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
         show_error( );
      }
      if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
         ...;  /* Process fetched data */
      } else {
         break;
      }
   }
}

Related Functions

For information about

See

Assigning storage for a column in a result set

SQLBindCol

Canceling statement processing

SQLCancel

Returning privileges for a column or columns

SQLColumnPrivileges (extension)

Fetching a block of data or scrolling through a result set

SQLExtendedFetch (extension)

Fetching a row of data

SQLFetch

Returning table statistics and indexes

SQLStatistics (extension)

Returning a list of tables in a data source

SQLTables (extension)

Returning privileges for a table or tables

SQLTablePrivileges (extension)

Previous Page TOC Index Next Page

Copyright © 1992-1997 Solid Information Technology Ltd All rights reserved.