Switch to: V9V8V7V6V5

KEYVALUE INSERT

Syntax

KEYVALUE keyvalue_name [OF TABLE table_name | OF LINK link_name]
     INSERT ( vext_keyvalue_list )
     [FOR RECORD { UINT | vext_link_list_of_records } ]
vext_keyvalue_list
    :    vext_keyvalue, ...
 
vext_keyvalue
    :    vext_key COLON vext_value
 
vext_key_list
    :    vext_key, ...
 
vext_key
    :    character_string_literal
    |    variable_name
    |    dynamic_parameter_specification
 
vext_value
    :    character_string_literal
    |    variable_name
    |    dynamic_parameter_specification
    |    TRUE
    |    FALSE
vext_link_list_of_records
    :   ( vext_link_value, ... )
 
vext_link_value
    :   UINT | dynamic_parameter_specification

Description

This command is analog of INSERT for tables. You can use it to insert one or many KEY:VALUE pairs into KeyValue store.

If the KEY already exists, then this command returns error that UNIQUE violation happened.

This command works for any kind of KeyValues, just specify FOR TABLE or FOR LINK if you are working with that KeyValue kind.

Notice, that you can use SQL Binding for both Keys and Values. Although most probably you will use that for Values mostly.

FOR RECORD

This is a special form of the command for KeyValue FOR TABLE or FOR LINK, when we know that KEY starts with RecID of the table or with pairs of RecIDs from the BinaryLink. This special form is just a syntax sugar, but it can be very helpful and simplify coding on few levels.

If you specify FOR RECORD clause, then you can and should skip RecID from all keys of this command.

Notice, that you can use SQL Binding in this clause to specify RecIDs of record.

Example

KEYVALUE kv1 INSERT
(
    '545.name' : 'Bob',
    '545.age'  : 29
);

Example

Example OF TABLE usage.

KEYVALUE kvMoreFields OF TABLE T1 INSERT
(
    '545.name' : 'Bob',
    '545.age'  : 29
);

Example

Example of FOR RECORD usage. Notice that 545 now not present in the Keys.

KEYVALUE kv1 INSERT
(
    'name' : 'Bob',
    'age'  : 29
)
FOR RECORD 545;

Example

Example of SQL Binding with KEYVALUE SET command.

dim cmd as String =
"KEYVALUE kv1 INSERT
(
    'name' : ?,
    'age'  : ?
)
FOR RECORD ?"
 
dim stmt as VSqlStatement = db.CreateStatement( cmd )
 
stmt.bind_string( "Bob" )
stmt.bind_uint32( 29 )
stmt.bind_uint32( 545 )
 
stmt.Execute()

See Also