Xbasic

sql_update Function

Syntax

p result = sql_update(A connection,c tablename,c fieldValuePairs [,c primaryKey [, c primaryKeyValue [, L execute]]])

Arguments

connectionCharacter SQL::Connection

An open SQL::connection object, a connection string, or a named connection string.

tablenameCharacter

Name of the table to update.

fieldValuePairsCharacter

Fields to update with corresponding values. A cr-lf list of the form fieldname=value. Or a JSON string (see example). Date values must be specified using yyyy/mm/dd format.

primaryKeyCharacter

Name of primary key field. If primaryKey is multi column use ||| to delimit (e.g. OrderNumber|||PartNumber)

primaryKeyValueCharacter

Value of primary key. If primaryKey is multi-column, use ||| to delimit (e.g. 10245|||23)

executeLogical

If false, the SQL is not executed. However, you can still examine the result.sql and result.arguments properties to see what SQL was generated.

Returns

resultPointer

An object with the following properties:

errorLogical

If .t., an error occurred. Otherwise .f..

errorTextCharacter

A detailed description of the error - if any occurred.

sqlCharacter

The SQL that was generated to execute the update.

ArgumentsCharacter

The XML arguments generated for the update.

Description

Updates a record in a SQL table.

Discussion

This function is just a wrapper around the Xbasic AlphaDAO commands to execute a SQL update statement, but it convenient to use for simple cases.

The record to update is specified by primary key, not by a generalized WHERE clause. This limitation is intentional so a to eliminate the possibility of unintentionally updating multiple records in the database. If you need to update multiple records you will need to write your own Xbasic code.
dim cn as sql::Connection

cn.open("::Name::myconnstring")
tablename = "mytable"
fieldsValuePairs = <<%str%
name=fred smith

date of birth=1952/12/18

salary=78000
%str%
 

'You can also specify field values using JSON
fieldsValuePairs = <<%str%
{
    "name" : "fred smith",
    "date of birth" : "1954/11/25",

    "salary" : "78000"
}
%str%

primaryKey = "id"
primarykeyValue = "1"

p = sql_update(cn,tablename,fieldsValuePairs,primaryKey,primaryKeyvalue)

See Also