slStmExec

Executes an SQL statement.

Syntax:

slStmExec ( stm-handle [, ptr-row [, options] ] )

Parameters:

(s) stm-handle: SQLite extender statement object handle.

(s) ptr-row: [optional] WIL pointer to a variable that contains one row of data upon function return. Use the WIL ampersand(&) operator to create the pointer to a variable.

(i) options: [optional] (@slheader|@slMap|@slWILTypes) modifies content of the variable pointed by the ptr-row parameter. See below.

Returns:

(1) 1 if the function produced a result set and 0 when all rows have been returned and the statement has completed.

Use stStmExec to execute a prepared SQL statement returned as statement object handle by the slStatement extender function. The function returns one rows at a time from the statement's result set. This means you must call the function repeatedly to obtain the full result set from the statement object's execution. The function returns zero(0) on the first function call after the call that returned the final result row or when the statement does not produce any results. It also automatically resets the statement to the initial state on the call after the last call that produces a row from a result set.

 

Stm-Handle

The unique identifier representing  a handle to a prepared SQL statement returned from a call to the slStatement function.

  

Ptr-row

This optional parameter must contain a WIL pointer to a variable that receives one row of the a statement's result set as a WIL array or WIL map.. The function returns an empty array or map (WIL array or map with no elements) when the supplied the statement does not return any output.

Notes:

 

Options

An optional parameter modifies the content of the ptr-row parameter. The @slWILTypes option can be combined with the @slHeader or @slMap option using the bit-wise or (|) operator.

Option

Meaning

@slHeader

Causes the output variable pointed to by the ptr-row parameter to contain a 2 row array with the first containing column titles and the second containing one row of column values..

@slMap

Causes the output variable pointed to by the ptr-row parameter to contain a WIL map with column titles as map keys and column values as map values.  The option overrides the @slHeader option.

@slWILTypes

Causes the output variable pointed to by the ptr-row parameter to contain array or map  values converted from text to native WIL variable types..  Since SQLite and WIL are both type-flexible, the only significant effect of this option is that SQLite BLOB data is returned in a binary buffer. This makes BLOB values easier to processes under certain conditions but also requires you to either copy or free the binary buffer handle before the next call to the function with the same pointer variable.  

 

Example:
AddExtender('ilcsl44i.dll', 0, 'ilcsl64i.dll')
; Create a db object handle to Northwind DB
db = slConnect("C:\Examples\northwind.db")
SQL = "SELECT CategoryName, Picture FROM Categories WHERE CategoryName = ?1 OR CategoryName = ?2;"
; Create a map of SQL parameter values and compile the
; statement with parameter values set
SQLparam[0] = "Beverages"
SQLparam[1] = "Seafood"
stm = slStatement(db, SQL, SQLparam)
; Execute the statement
While slStmExec(stm, &Row, @slWILTypes)
   BinaryWrite(Row[1],"C:\Examples\":row[0]:".jpg")
   BinaryFree(Row[1])
EndWhile
See Also:

slConnect,  slStatementslStmExecAllslStmExecManyslStmReset