Pages Navigation Menu

Inserting

Inserting a record or key-value pair

To insert a record or a key-value pair,

  1. Open a KitaroDB database using DB.Open[Async]. Note that there is no need to open a KitaroDB database if you have just created it in your program. See Creating a KitaroDB database.
  2. Pass the record or key-value pair to DB.Insert[Async]. This method can take an array of bytes or a string.

Note the following:

  • A record is not locked by default after it is inserted.
  • For key-value pair databases, the key and value combined cannot exceed the maximum record length, which is set when the database is created.

Note the following for intrusive-keyed databases:

  • DB.Insert[Async] ensures that new key values are unique for keys that don’t allow duplicates. If you attempt to insert a duplicate key when it is prohibited, a “Duplicate key specified” error (NODUPS) occurs.
  • If the data area is longer than the maximum record length for the database (which is set when the database is created), an “Invalid record size” error (IRCSIZ) occurs, and no data is transferred to the file.
  • On an insert operation, all indexes have the new record’s key values inserted, unless a key is NULL according to the definition of the key.
  • When you insert a record in an intrusive-keyed database, you can use the grfa parameter for DB.Insert[Async] to get the GRFA for the record.