LifeLua 21-08-2025
Documentation for LifeLua, a Lua interpreter for the PS Vita
Loading...
Searching...
No Matches
sqlite3

SQLite databases. More...

Detailed Description

Every function that takes a database as its first parameter can also be called as a method, e.g. db:query(sql) and db:close(). Databases are also closed automatically when they're no longer used.

local db = sqlite3.open("ux0:data/myapp/scores.db")
db:query("CREATE TABLE IF NOT EXISTS scores (name TEXT, points INTEGER)")
db:query("INSERT INTO scores VALUES ('Harommel', 1200)")
for i, row in ipairs(db:query("SELECT * FROM scores ORDER BY points DESC")) do
print(i, row.name, row.points)
end
db:close()

Functions

sqlite3 sqlite3.open (string path, number mode)
 
table sqlite3.query (sqlite3 db, string sql)
 
nil sqlite3.close (sqlite3 db)
 

Open modes

Used with sqlite3.open(). Combine several of them by adding them together.

number SQLITE_OPEN_READONLY
 Open the database for reading only.
 
number SQLITE_OPEN_READWRITE
 Open the database for reading and writing.
 
number SQLITE_OPEN_CREATE
 Create the database if it doesn't exist (use together with SQLITE_OPEN_READWRITE)
 
number SQLITE_OPEN_URI
 Allow the path to be a file: URI.
 
number SQLITE_OPEN_NOMUTEX
 Multi-thread mode.
 
number SQLITE_OPEN_FULLMUTEX
 Serialized mode (safe to use from several threads)
 

Function Documentation

◆ sqlite3.close()

nil sqlite3.close ( sqlite3 db)

Closes a database

Method form: db:close()

Parameters
dbThe database

◆ sqlite3.open()

sqlite3 sqlite3.open ( string path,
number mode )

Opens a database file

Parameters
pathPath to the database file
modeHow to open it, one or more of the open mode constants added together (optional, default: SQLITE_OPEN_READWRITE + SQLITE_OPEN_CREATE)
Returns
The database. Raises an error if it can't be opened.

◆ sqlite3.query()

table sqlite3.query ( sqlite3 db,
string sql )

Runs one or more SQL statements

Method form: db:query(sql)

Parameters
dbThe database
sqlThe SQL to run
Returns
A list of the result rows (empty if there are none). Each row is a table with the column names as keys. All values are returned as strings (use tonumber() for numbers), and SQL NULL values are nil. Raises an error if the SQL fails.