Home  Contents

sql:setValue

Sql Core4 Lua Commands

SYNOPSIS

  1. db:setValue(key, value)
  2. value = db:getValue(key)

DESCRIPTION

Applications often need to store configuration settings. Such settings are usually organized in Key, Value pairs.

These two functions are frontends for storing such pairs into a database. The settings are always stored in a table called Settings inside the database which has just two columns: Key and Value. When missing, the table is automatically created on the first call to setValue().

To store a setting, call the first form. When the function returns, the data has been safely committed to the database. if the value is absent or nil, the item is removed from the table.

The second form retrieves a setting. If there is nothing stored unter key, the function returns nil (also, calling sql:lastError() in that case returns nil too, to indicate no error.)

RETURN VALUE

The first form returns true on success and nil on error. The second form returns the queried value on success and also nil on error. In case of an error, the error can be retrieved using sql:lastError().