[ Previous ] [ Contents ] [ Index ] [ Next ]

Ns_DbSelect

Overview

Send a row-generating query to the database

Syntax

    Ns_Set *Ns_DbSelect(
    Ns_DbHandle *handle,
    char *sql
    );

Description

The Ns_DbSelect function executes the given SQL statement. It returns an Ns_Set where the field key names are the column names that were returned by the select statement on success. The field values are NULL until the first call to Ns_DbGetRow where they are replaced with the values of the first row fetched from the database. The set is statically allocated; do not free it with Ns_SetFree when your query is complete.

On error, Ns_DbSelect returns NULL. Detailed error message may have accumulated in an internal buffer in the Ns_DbHandle.

Examples

    Ns_DbHandle *handle;
    if ((handle = Ns_DbPoolGetHandle("aPoolName")) != NULL) {
    	Ns_Set *row;
    	row = Ns_DbSelect(handle, "select * from aTable");
    	if (row == NULL) {
    		/*... handle select error ...*/
    	}
    	while ((status = Ns_DbGetRow(handle, row)) == NS_OK) {
    		/*... process the row fetched from the database ...*/
    	}
    	if (status != NS_END_DATA) {
    		/*... handle get row error ...*/
    	}
    	Ns_DbPoolPutHandle(handle); /* done with handle */

}

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1998-99 America Online, Inc.