Reading, updating, deleting
Reading, updating, deleting
There are two ways to read, update, or delete data. You can pass a key directly to DB.Get[Async], DB.Update[Async], or DB.Delete[Async]. Or you can use a cursor to read, update, or delete the record or key-value pair at the cursor’s position. Note the following:
- For intrusive-keyed databases, you must use a cursor to read, update, or delete a record.
- Record locking is not available for direct (non-cursor) access. Using DB.Update[Async] is potentially dangerous because it will acquire a lock and overwrite a value even if someone else has updated the value in the interim.
- The order of iteration for cursor-based access is not defined for key-value pairs. For an intrusive-keyed database, the order for an unfiltered cursor is determined by the declared type of the primary key, and for a discriminated cursor, it is determined by the key passed when the cursor was opened.
To use a key to directly read, update, or delete data (non-cursor access)
- 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.
- Pass the key to DB.Get[Async], DB.Update[Async], or DB.Delete[Async].
To use a cursor to read, update, or delete data
- 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.
- Open a discriminated cursor with DB.Select[Async] or an unfiltered cursor with DB.Seek[Async]. See Using cursors for more information.
- If necessary, position the cursor using DBCursor.Seek[Async] or one of the DBCursor.Move* methods (see Using cursors). Note that you can get the GRFA for a record by using DBCursor.GetGRFA, and you can get the key for the current cursor location by using DBCursor.GetKey or DBCursor.GetKeyString.
- Use DBCursor.Get, DBCursor.GetString, DBCursor.Update[Async], or DBCursor.Delete[Async] to read, update, or delete the record at the current cursor position. Note the following:
- To use DBCursor.Update[Async], the record must be locked. Otherwise, a “Record not locked” error (NOLCK) occurs.
- If you try to modify the value of a key that was not defined as modifiable when the file was created, a “Key not same” error (KYNSAM) occurs.
- If the data area is longer than the defined maximum length of a record in the file, an “Invalid record size” error (IRCSIZ) occurs, and no data is transferred to the file.
- You cannot modify the key for a key-value pair, a primary key, or a key that is set to be non-modifiable. Instead, you must delete the record or key-value pair and the reinsert it with a new key.
- After the DBCursor.Update[Async] method is called, automatic record locks for the record are released.
- You can translate an AutoTime number into a datetime value (yyyymmddhhmissuuuuuu) by using DBKey.ConvertBytesToDateTime.