Documents > BPS V2 Script API
bps::SqlValues Class Reference

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

List of all members.

Public Member Functions

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

Properties

String columns
 The column names as comma separated list.
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=placeholder as comma separated list.
String tags
 The value placeholders as comma separated list.
Array values
 List of the values.

Detailed Description

Convenience class to help composing insert and update statements.

 var q = new bps.Query(ds);

 // insert example
 var key = ds.nextKey('departments');
 var vals = new bps.SqlValues;
 vals.insert('c_key', key);
 vals.insert('c_id', '0003');
 vals.insert('c_name', 'Fruit and vegetables');
 q.prepare(
     String("insert into t_departments (%1) values (%2)").arg(vals.columns).arg(vals.tags)
 );
 q.execute(vals.values);

 // update example
 rec.insert('c_id', 'F02');
 rec.insert('c_name', 'Fruit, vegetables and flowers');
 q.prepare(
     String("update t_departments set %1 where c_key=?").arg(vals.pairs)
 );
 q.execute(vals.values.concat(key));

Member Function Documentation

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

Insert a key/value pair.

Parameters:
[in]aKeyThe key to insert
[in]aValueThe value to insert
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.
String bps::SqlValues::toString ( ) const
Returns:
Returns "SqlValues(key=val, key2=val2, ...)"
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.