DatabaseUpdate()

Syntax

Result = DatabaseUpdate(#Database, Request$)
Description
Executes a modification query on the given database. This command doesn't return any record. To perform a 'SELECT' like query, use DatabaseQuery().

Parameters

#Database The database to use.
Request$ The query to execute.

Return value

Returns nonzero if the query was successful or zero if it failed (due to a SQL error or a badly-formatted query).

Remarks

This function is similar to DatabaseQuery() but is independent from the NextDatabaseRow() function. Therefore it's not possible to do a 'SELECT' like query with this function. This function is useful for updating records in the database. In the event of an error, the error text can be retrieved with DatabaseError().

The update request can contain place holders for bind variables. Such variables must be set before calling the function using SetDatabaseString(), SetDatabaseLong() etc. After executing the update, the bound variables are cleared and have to be set again for future calls. The syntax for specifying bind variables in SQL is dependent on the database. The example below demonstrate the syntax.

Example

  ; First, connect to a database with an employee table
  ;
  If DatabaseQuery(#Database, "SELECT * FROM employee") ; Get all the records in the 'employee' table
  
    While NextDatabaseRow(#Database) ; Loop for each records
      
      ; Update the 'checked' field for each records, assuming the 'id' field is 
      ; the first one in the 'employee' table
      ;
      DatabaseUpdate(#Database, "UPDATE employee SET checked=1 WHERE id="+GetDatabaseString(#Database, 0)) 
    Wend
    
    FinishDatabaseQuery(#Database)
  EndIf

Example: Bind variables with SQLite

  ; SQLite and ODBC shares the same syntax for bind variables. It is indicated by the '?' character
  ;
  SetDatabaseLong(0, 0, 1)
  SetDatabaseString(0, 1, "test")
  DatabaseUpdate(0, "UPDATE employee SET checked=? WHERE id=?")
<- DatabaseQuery() - Database Index - ExportDatabase() ->