SQLITE(3lua)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’– NAME πŸ’–

sqlite β€” access SQLite3 files from Lua, and honestly? It's giving iconic database energy πŸ’…

✨ SYNOPSIS ✨

local sqlite = require 'sqlite'

err = sqlite.initialize()
sqlite.shutdown()
db, err = sqlite.open(file [, flags])
version = sqlite.libversion()
version = sqlite.libversion_number()
id = sqlite.sourceid()

err = sqlite.close(db)
stmt, err = sqlite.prepare(db, sql)
err = sqlite.exec(db, sql)
err = sqlite.errcode(db)
msg = sqlite.errmsg(db)
res = sqlite.get_autocommit(db)
res = sqlite.changes(db)

err = sqlite.bind(stmt, pidx, value)
count = sqlite.bind_parameter_count(stmt)
pidx = sqlite.bind_parameter_index(stmt, name)
name = sqlite.bind_parameter_name(stmt, pidx)
err = sqlite.step(stmt)
value = sqlite.column(stmt, cidx)
sqlite.reset(stmt)
sqlite.clear_bindings(stmt)
sqlite.finalize(stmt)
name = sqlite.column_name(stmt, cidx)
count = sqlite.column_count(stmt)

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so the sqlite Lua binding gives you access to SQLite3 files. That's it. That's the vibe check. πŸ’–

🌸 GENERAL FUNCTIONS 🌸

  • err = sqlite.initialize() β€” Initializes the SQLite3 library. But bestie, workstation applications using SQLite normally do not need to invoke this function, so don't @ me if you skip it.
  • sqlite.shutdown() β€” Deallocates any resources that were allocated by sqlite.initialize(). Again, workstation applications using SQLite normally do not need to invoke this function.
  • db, err = sqlite.open(file [, flags]) β€” Opens a database, optionally passing flags. When called without flags, the database will be opened for reading and writing and it will be created if it does not yet exist. The following flags are defined:
    • sqlite.OPEN_READONLY β€” The database is opened in read-only mode. If the database does not already exist, an error is returned. No cap.
    • sqlite.OPEN_READWRITE β€” The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned. Periodt.
    • sqlite.OPEN_CREATE β€” The database is opened for reading and writing, and is created if it does not already exist. Slay.
  • version = sqlite.libversion() β€” Returns the SQLite3 library version number as a string. Cute.
  • version = sqlite.libversion_number() β€” Returns the SQLite3 library version number as a number. Also cute.
  • id = sqlite.sourceid() β€” Returns the SQLite3 library source id as a string. Very demure.

πŸŽ€ DATABASE FUNCTIONS πŸŽ€

Database functions operate on database objects returned by sqlite.open(). Like, they're the main character energy of your database. πŸ’…

  • err = sqlite.close(db) β€” Closes an open database. Like with all remaining database functions, this function can also be called using the Lua "colon" syntactic sugar as db:close(). So db:close() is literally the same thing, bestie.
  • stmt, err = sqlite.prepare(db, sql) β€” Returns a prepared statement. Super useful, iykyk.
  • err = sqlite.exec(db, sql) β€” Directly executes an SQL statement. ⚠️ Be careful when creating SQL on the fly (SQL injection attacks). Like, fr fr, don't do that.
  • err = sqlite.errcode(db) β€” Returns the numeric error code. Numbers are giving math but okay.
  • msg = sqlite.errmsg(db) β€” Returns the error message as a string. Way more readable, ngl.
  • res = sqlite.get_autocommit(db) β€” Returns the autocommit flag. Idk what you'll do with it but it's there.
  • res = sqlite.changes(db) β€” This function returns the number of database rows that were changed or inserted or deleted by the most recently completed SQL statement on the database. That's it. That's the whole vibe.

🐚 STATEMENT FUNCTIONS 🐚

  • err = sqlite.bind(stmt, pidx, value) β€” Binds value to the parameter pidx in the prepared statement stmt. Kinda like matching your outfit to your nails πŸ’…
  • count = sqlite.bind_parameter_count(stmt) β€” Returns the number of parameters in the prepared statement stmt. A little headcount, if you will.
  • pidx = sqlite.bind_parameter_index(stmt, name) β€” Returns the parameter index for name in the prepared statement stmt. It's giving "where's the parameter" energy.
  • name = sqlite.bind_parameter_name(stmt, pidx) β€” Returns the parameter name for the parameter index pidx in the prepared statement stmt. Reverse uno card.
  • err = sqlite.step(stmt) β€” Executes prepared statement stmt. This is the moment of truth, bestie.
  • value = sqlite.column(stmt, cidx) β€” Returns the value at column cidx in the prepared statement stmt. Gimme the tea β˜•
  • sqlite.reset(stmt) β€” The sqlite.reset() function is called to reset a prepared statement object back to its initial state, ready to be re-executed. Like a refresh but for statements.
  • sqlite.clear_bindings(stmt) β€” Contrary to the intuition of many, sqlite.reset() does not reset the bindings on a prepared statement. Use this routine to reset all host parameters to NULL. Lowkey a gotcha, so remember it.
  • sqlite.finalize(stmt) β€” The sqlite.finalize() function is called to delete a prepared statement. Say bye bye πŸ‘‹
  • name = sqlite.column_name(stmt, cidx) β€” Returns the name assigned to a particular column in the result set of a SELECT statement. Very "what's your name, what's your sign" energy.
  • count = sqlite.column_count(stmt) β€” Returns the number of columns in the result set returned by the prepared statement stmt. This routine returns 0 if stmt is an SQL statement that does not return data (for example an UPDATE). Like when there's literally nothing to show, it gives you a zero.

πŸ’€ ERROR CODES πŸ’€

Most functions return an error code, the following error codes are defined. Buckle up, bestie, there's a lot.

  • sqlite.OK β€” Successful result. πŸŽ‰
  • sqlite.ERROR β€” SQL error or missing database. 😭
  • sqlite.INTERNAL β€” Internal logic error in SQLite. Like when the app is having a bad day.
  • sqlite.PERM β€” Access permission denied. Rude.
  • sqlite.ABORT β€” Callback routine requested an abort. 🚩
  • sqlite.BUSY β€” The database file is locked. It's giving "in a meeting" energy.
  • sqlite.LOCKED β€” A table in the database is locked. Not the whole file, just a table. Very specific.
  • sqlite.NOMEM β€” Out of memory. πŸ’€
  • sqlite.READONLY β€” Attempt to write a readonly database. Sweetie, no.
  • sqlite.INTERRUPT β€” Operation terminated by sqlite3_interrupt(). Rude but valid.
  • sqlite.IOERR β€” Some kind of disk I/O error occurred. The disk said "not today".
  • sqlite.CORRUPT β€” The database disk image is malformed. 😬
  • sqlite.NOTFOUND β€” Unknown opcode in sqlite3_file_control(). Like a mystery flavor.
  • sqlite.FULL β€” Insertion failed because database is full. No room at the inn.
  • sqlite.CANTOPEN β€” Unable to open the database file. The door is locked and you don't have the key.
  • sqlite.PROTOCOL β€” Database lock protocol error. The vibes are off.
  • sqlite.EMPTY β€” Database is empty. Ghost town. πŸ‘»
  • sqlite.SCHEMA β€” The database schema changed. Plot twist.
  • sqlite.TOOBIG β€” String or BLOB exceeds size limit. Too much, bestie.
  • sqlite.CONSTRAINT β€” Abort due to constraint violation. You broke the rules.
  • sqlite.MISMATCH β€” Data type mismatch. Like wearing flip-flops to a formal.
  • sqlite.MISUSE β€” Library used incorrectly. Skill issue.
  • sqlite.NOLFS β€” Uses OS features not supported on host. Your OS said no.
  • sqlite.AUTH β€” Authorization denied. Blocked.
  • sqlite.FORMAT β€” Auxiliary database format error. The format is not formatting.
  • sqlite.RANGE β€” 2nd parameter to sqlite.bind() out of range. Parameter 2 specifically. Note that.
  • sqlite.NOTADB β€” File opened that is not a database file. That's not a database, that's a random file.
  • sqlite.ROW β€” sqlite.step() has another row ready. There's more tea β˜•
  • sqlite.DONE β€” sqlite.step() has finished executing. The end. Periodt. πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘

lua(1), luac(1), sqlite3(1), intro(3lua) β€” go check these out bestie, they're literally the friends of this page.

🌈 HISTORY 🌈

An sqlite manual appeared in NetBSD 7.0. She's been around. Respect the legacy.

🫢 AUTHORS 🫢

The sqlite Lua binding was written by Marc Balmer <mbalmer@NetBSD.org>. Legend behavior.


Okay so that's the page, bestie! It came from Debian on October 28, 2013, and it's the SQLITE(3lua) page β€” catch you on the flip side! πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from
  • nixpkgs unstable: netbsd-source 11.0
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms