Connection.opentablesrs — get a list of database tables


Recordset Connection.opentablesrs ( );  


This method returns a Recordset which enumerates all the tables in the database that are at least readable by the current user. Depending on the data source the returned recordset may also list views, sequences and other such objects. You should use Connection.getmetacolumn() to get the names of the relevant columns in the returned recordset.

On error null is returned; use error() to get the error message.

Example 64. Connection.opentablesrs Example

// Get a list of all tables in the database.  Ignore views and other objects.
string nameCol = conn.getmetacolumn(RSP_DB_META_TABLENAME);
string typeCol = conn.getmetacolumn(RSP_DB_META_TABLETYPE);
string type = "TABLE";

// This array will be filled with table names
string[] tables;

Recordset rs = conn.opentablesrs();
if(rs == null)
    %><p>Error: <%=htmlencode(error())%></p><%
    int count = 0;
        // Get the table type if that column is available
        if(typeCol != "")
            type = upper(rs.getstring(typeCol));
        if(type == "TABLE")
            tables.resize(++count, rs.getstring(nameCol));;

See Also

Data sources and database access in RSP is explained in the section called “Accessing Databases”