dbPrepareSQL

Top  Previous  Next

Syntax

INT = dbPrepareSQL(pConnection as POINTER,statement as STRING)

Description

Prepares an SQL statement for later execution with dbExecute.

Parameters

pConnection - A pointer to a database returned by dbConnect or dbConnectDSN.

statement - The SQL statement to prepare.

Return value

A handle to the prepared SQL statement or NULL if a statement handle could not be allocated.

Remarks

A prepared SQL statement is one that has been validated by the driver and converted to the necessary internal representation ready for execution.

Prepared statements are used to perform many duplicate updates or insertions into a database table. Using a prepared statement allows simply updating the bound parameters and calling dbExecute for each iteration. The main advantage over direct execution with dbExecSQL is speed of updates and insertions.

See Also: dbExecute, dbFreeSQL

Example usage

hstmt = dbPrepareSQL(pdb,"INSERT INTO Addresses (FirstName,LastName,Address) VALUES(?,?,?)")
IF hstmt
    dbBindParameter(hstmt,1,first,255)
    dbBindParameter(hstmt,2,last,255)
    dbBindParameter(hstmt,3,street,255)
    'after the variables are bound you can insert as many records as needed with one statement
    first = "Lisa"
    last = "Jones"
    street = "123 Niagara"
    dbExecute(hstmt)
    '
    first = "Tammy"
    last = "Miller"
    street = "123 America St"
    dbExecute(hstmt)
    '
dbFreeSQL(hstmt)
ENDIF