BPS Script API  2.24.4
bps::SqlValues Class Reference

Convenience class to help composing select, insert and update statements. More...

Public Member Functions

void clear ()
 Clear the list.
 
void insert (String aKey, Mixed aValue)
 Insert a key/value pair. More...
 
Number remove (String aKey)
 Removes the value with the given key. More...
 
 SqlValues ()
 Default constructor.
 
String toString () const
 
Mixed value (String aName)
 Get the named columns value. More...
 

Properties

String columns
 The column names as comma separated list.
 
String condPairs
 Pairs of "column=?", "column is null" or "(column is null or column='')" respectively as "and" separated list, as used for select conditions.
 
Boolean isEmpty
 True if there are no columns.
 
Array keys
 List of the keys.
 
Object object
 The internal object holding the values.
 
String pairs
 Pairs of "column=?" or "column=null" respectively as comma separated list, as used for update statements.
 
String tags
 The value placeholders as comma separated list.
 
Array values
 List of the values.
 

Detailed Description

Convenience class to help composing select, insert and update statements.

Empty strings are handled like NULL in context of inserts and updates. In select conditions the database column is compared to both, NULL or '', if the string value is empty. This special handling is necessary because for Oracle NULL and '' are the same, however for PostgreSQL they are not.

var vals = new bps.SqlValues;
vals.insert('c_x', 123); // non-null example value
vals.insert('c_y', null); // null example value
vals.insert('c_z', ''); // empty strings also handled like NULL
// select condition example
q.prepare(
String("select c_foo from t_table where %1").arg(vals.condPairs)
// select c_foo from t_table where c_x=? and c_y is null and (c_z is null or c_z='')
);
q.execute(vals.values); // 123
// update example
q.prepare(
String("update t_table set %1 where c_key=?").arg(vals.pairs)
// update t_table set c_x=?, c_y=null, c_z=null where c_key=?
);
q.execute(vals.values.concat(456)); // 123 456
// insert example
q.prepare(
String("insert into t_table (%1) values (%2)")
.arg(vals.columns)
.arg(vals.tags)
// insert into t_table (c_x, c_y, c_z) values (?, null, null)
);
q.execute(vals.values); // 123
BPS Script engine enhancements to the String prototype.
Definition: Engine.js:44
Convenience class to help composing select, insert and update statements.
Definition: bps.SqlValues.js:42
void insert(String aKey, Mixed aValue)
Insert a key/value pair.
The bps extension is a namespace assembling general BPS properties and functions.
Definition: bps.AsyncIO.js:1

Member Function Documentation

◆ insert()

void bps::SqlValues::insert ( String  aKey,
Mixed  aValue 
)

Insert a key/value pair.

Parameters
[in]aKeyThe key to insert
[in]aValueThe value to insert

◆ remove()

Number bps::SqlValues::remove ( String  aKey)

Removes the value with the given key.

Parameters
[in]aKeyThe key of the pair to remove.
Returns
Number of items removed which is usually 1 but will be 0 if the key isn't in the map.

◆ toString()

String bps::SqlValues::toString ( ) const
Returns
Returns "SqlValues(key=val, key2=val2, ...)"

◆ value()

Mixed bps::SqlValues::value ( String  aName)

Get the named columns value.

Parameters
[in]aNameName of the column to get the value for.
Returns
The value, or null in case no such column name is found.

The documentation for this class was generated from the following file: