slExecute

Executes SQL statements.

Syntax:

slExecute ( db-handle , SQL-statements [, options] )

Parameters:

(s) db-handle: SQLite extender database object handle.

(s) SQL-statements: one or more plain text SQL statements.

(i) options: [optional] @slHeader or @slNoOutput (see below).

Returns:

(a) result-set: a one or two dimension array containing the result set when applicable; otherwise, an empty array.

This function processes one or more SQL statements and returns a result-set when the SQL statement(s) produce one and the @slNoOutput option is not used. Unlike some other extender function the function does not accept preprocessed or compiled statements. The SQL-statements parameter can contain more the one properly formatted SQL statements. The function stops execution if non-SQL content is encountered in the parameter. When this happens the function may or may not produce an error message. This depends on the type of non-SQL iniformation encountered. When the result-set from the SQL statement is a single column, the function returns one dimension (rank 1) array; otherwise, the function returns a two dimension (rank 2) array.

 

Note:A collection of SQL statements is sometimes referred to an "SQL script" in SQL references.

 

DB-Handle

The unique identifier returned from a call to the slConnect function.

  

SQL-statements

Text in a WIL variable or string literal containing one or more plan-text SQL statements. Each statement must follow standard SQL syntax rules including the semicolon ";" terminator after each statement. You can also use SQLite SQL dialect specific statements including SQLite PRAGMA SQL extension to SQL and SQLite JSON functions. You can use PRAGMA statements to change the behavior of SQLite which in turn affects the behavior and output of extender functions. PAGMA statements can also be used to collect schema information about a database.  See the SQLite Website for more information.

 

Options

An optional parameter used to modify or prevent the function's output.

Option

Meaning

@slHeader

Add the name of each column as the first row of the returned array when applicable. The names only apply to the first statement query results in a multiple statements query.

@slNoOutput

Prevents the creation of an output array. Use this option to increase function performance when you are not interested in statement result sets. The option overrides the @slHeader option.

 

Example 1:
AddExtender('ilcsl44i.dll', 0, 'ilcsl64i.dll')
; Create the Northwind SQLite extender sample DB.
; Note: account executing the script must have
; read/write access to the targeted file system folder
; which is "C:\Examples" in this script
out = "C:\Examples\northwind.db"
Terminate(FileExist(out),'Northwind DB', 'File aready exists')
; Load the SQL script into a variable
SQL = FileGet('C:\Examples\NorthWind.sql')
; Get a database object handle for the DB
northwinddb = slConnect(out)
; Create the DB
slExecute(northwinddb, SQL, @SlNoOutput)
slClose(northwinddb) ; Clean up
Example 2:
AddExtender('ilcsl44i.dll', 0, 'ilcsl64i.dll')
; Obtain a list of table names in the Northwind
; database
SQL = "PRAGMA table_list;"
northwinddb = slConnect("C:\Examples\northwind.db")
tables =  slExecute(northwinddb, SQL)
slClose(northwinddb)
; Table_list results have 7 columns. Table names are
; in the second column (see SQLite Website for more
; information about pragmas)
nmax = ArrInfo(tables, 1)-1
list = ""
For i=0  To nmax
   list := tables[i,1]:@lf
Next
; Display the result
Message("Tables in Northwind Database", list)
See Also:

slConnect,  slClose