SQL Yoga version 1.1.0 build 4 :: Visit website

Printer friendly version

command sqlquery_update

Updates a record in a table.

command sqlquery_update pTable, pConditions, pParamsA
Simple parameter. pTable The name of the table to update. If you need to pass in a Database or Connection object that isn't the default then pass in SQL Query object.
Simple parameter. pConditions The search conditions. This can be an array of search parameters, a primary key value or an exact string to assign to the WHERE clause. You can pass in an empty value for pConditions if there is no primary key for the table.
Simple parameter. pParamsA An array of key value pairs used to perform the update.

This command will perform an UPDATE based on the parameters you pass in.

## Update lesson with id of 2 
put 0 into theValuesA["draft"]
sqlquery_update "lessons", 2, theValuesA
put the result into theError

## Update lesson with id of 2 
sqlquery_update "lessons", "id = 2", theValuesA
put the result into theError

## Update lessons with an id of 12 and 15
put "id is in :1" into theConditionsA["conditions"]
put "12,15" into theConditionsA["condition bindings"][1]
sqlquery_update "lessons", theConditionsA, theValuesA
put the result into theError

An alternative to passing in an array for pParamsA is to pass in combinations of "key", "value" parameters. For example, the following code would set the draft field in the database to 0.

sqlquery_update "lessons", 15, "draft", 0 


Error string in 'the result', number of affected rows in 'it'.