NAME
SQLselect - execute a select statement inside tcl

SYNOPSIS
SQLselect [ -noheaders ][ -1d ] result_array select_statement

DESCRIPTION

The SQLselect command executes the SQL select statement. The output of the select is returned as a Tcl array in result_array. The return value of SQLselect is the number of rows returned by the select, not including the column header row. SQL errors are handled by appending the SQL error message to the results and returning TCL_ERROR.

This command is a specialized form of SQLexec.

This command uses a private, statically allocates SQL Data Area (SQLDA). The private SQLDA is allocated during the first call to SQLselect or SQLexec.

result_array is a Tcl 2 dimensional array. Row 0 contains the column headers for the select. The other rows contain the data in the columns.

OPTIONS

-noheaders
    Don't include the column headers in the result_array. Usually the column headers are at row 0. If -noheaders is used then result_array will start at row 1.

-1d result_array will be a one dimensional Tcl array. Usually, result_array is returned a two dimensional Tcl array, even if there is only one column of data. Note that if -1d is used, and the select statement returns two or more columns of data, then an error message will be printed and SQLselect will return TCL_ERROR.

EXAMPLE

This command will select all the columns in table vertex2 of database dbdict:
        SQLopendb dbdict
        SQLselect results * from vertex2
        # Print the header of the first column.
        puts stdout results(0,0)
        # Print the data of the first row, second column.
        puts stdout results(1,2)
        # Print all of the results
        parray results
        SQLclosedb

KEYWORDS
database, select

SEE ALSO
SQLexec(3)

BUGS
It would be nice if SQLselect could return arrays that were keyed on the column name, rather than an integer. (e.g. If the column headers were named 'id', 'x' and 'y', the the result_array for row number 1 would look like result_array(1,id), result_array(1,x), and result_array(1,y)).

Note that Ingres 6.4 does not allow interleaved access to two open cursors. Commands like SQLfetch and SQLselect both access two different cursors. The code below probably won't work:
        SQLdeclareCursor curs
        SQLprepareCursor curs "select * from cust_orders";
        SQLdescribeCursor curs
        SQLopenCursor -readonly curs;
        SQLfetch curs row
        SQLselect res_array * from cust_info
        SQLcloseCursor curs