Freigeben über


SQLTABLES( ) Function

Stores the names of tables in a data source to a Visual FoxPro cursor.

SQLTABLES(nConnectionHandle [, cTableTypes] [, cCursorName])

Return Values

Numeric

Parameters

  • nConnectionHandle
    Specifies the connection handle to the data source returned by SQLCONNECT( ).

  • cTableTypes
    Specifies one or more table types. Valid table types are 'TABLE,' 'VIEW,' 'SYSTEM TABLE,' or any valid data source-specific table type identifier. cTabletypes must be in upper-case. If you include a list of table types, separate the table types with commas.

    All table names in the data source are selected if you omit cTableTypes or if cTableTypes is the empty string.

    The table type you specify must be delimited with single quotation marks. The following example demonstrates how to specify the 'VIEW' and 'SYSTEM TABLE' table types as a string literal.

    ? SQLTABLES(handle, "'VIEW', 'SYSTEM TABLE'", "mydbresult")
    
  • cCursorName
    Specifies the name of the Visual FoxPro cursor to which the result set is sent. If you don't include a cursor name, Visual FoxPro uses the default name SQLRESULT.

    The following table shows the columns in the cursor.

    Column name Description
    TABLE_QUALIFIER Table qualifier identifier
    TABLE_OWNER Table owner identifier
    TABLE_NAME The table name as it appears in the data dictionary
    TABLE_TYPE The table type as it appears in the data dictionary
    REMARKS A description of the table

Remarks

SQLTABLES( ) returns 1 if the cursor is successfully created, 0 if SQLTABLES( ) is still executing, – 1 if a connection level error occurs, and – 2 if an environment level error occurs.

SQLTABLES( ) is one of the four functions that you can execute either synchronously or asynchronously. The setting of the SQLSETPROP( ) asynchronous option determines if these functions execute synchronously or asynchronously. In asynchronous mode, you must call SQLTABLES( ) repeatedly until it returns a value other than false (.F.), meaning the function is still executing.

Example

The following example assumes an ODBC data source called MyFoxSQLNT is available, and the user ID for the data source is "sa." SQLCONNECT( ) is issued, and its return value is stored to a variable named gnConnHandle.

If you cannot connect to the data source, SQLCONNECT( ) returns a negative number and a message is displayed.

If you successfully connect to the data source, SQLCONNECT( ) returns a positive number and a dialog is displayed. SQLTABLES( ) is used to create a cursor named mycursor that contains information about tables in the data source. LIST is used to display information about the tables.

STORE SQLCONNECT('MyFoxSQLNT', 'sa') TO gnConnHandle
IF gnConnHandle < 0
   = MESSAGEBOX('Cannot make connection', 16, 'SQL Connect Error')
ELSE
   = MESSAGEBOX('Connection made', 48, 'SQL Connect Message')
   STORE SQLTABLES(gnConnHandle, 'TABLE', 'mycursor') TO nTables
   IF nTables = 1
      SELECT mycursor
      LIST
   ENDIF
ENDIF

See Also

AERROR( ) | SQLCOLUMNS( ) | SQLCONNECT( ) | SQLGETPROP( ) | SQLSETPROP( )