SQLExecQuery

Syntax

SQLExecQuery(ConnectNum, Query$)

Remarks

Sends a query to a data source using an existing connection and stores the entire query result in memory.

Note

Unlike SQLExecQuery, SQLQueryExec does not store the entire query result in memory. To avoid resource problems when creating complex database solutions using the ODBC add-in library, use SQLQueryExec.

Before calling SQLExecQuery, a connection must be established with a data source using SQLOpen. A successful call to SQLOpen returns a unique connection ID number. SQLExecQuery uses that connection ID number to send SQL language queries to the data source.

SQLExecQuery only executes a query; results generated from the query are
not returned. Retrieving results is handled by the SQLRetrieveColumns, SQLRetrieveItem$, and SQLRetrieveRows functions. If SQLExecQuery is called using an existing connection ID number, all pending results on that connection will automatically be discarded. The connection ID will then refer
to the new query and its results.

Argument

Explanation

ConnectNum

The unique connection ID of the data source you want to query returned by a previously executed SQLOpen function. If ConnectNum is not valid, SQLExecQuery returns 0 (zero).

Query$

The SQL language query that is to be executed on the data source. The query should follow SQL grammar; the Help file for the appropriate ODBC driver also describes any SQL language limitations or modifications for the given DBMS.

If SQLExecQuery is unable to execute Query$ on the specified data source, SQLExecQuery returns 0 (zero). The exact error can be obtained from the error functions.


If SQLExecQuery is able to successfully execute the query on the specified connection, it will return one of three values, depending on the type of SQL statement that was executed.

SQL statement

Return value

SELECT

The number of result columns available

UPDATE, INSERT or DELETE

The number of rows affected by the statement

Other

A positive value


If there was an error executing the query, SQLExecQuery returns a negative error value.

Example

The following example sends a simple SELECT query to an established data source connection during asynchronous processing. While SQLExecQuery continues to return the value –2, the query is still being processed; the macro should wait for a final return value from SQLExecQuery before determining whether an error occurred.


ret = -2
While ret = -2
    ret = SQLExecQuery(connect_num, "select * from authors")
Wend
If ret <= 0 Then Goto ParseErrors