Module: Extralite
- Defined in:
- lib/extralite.rb,
lib/extralite/version.rb,
ext/extralite/query.c,
ext/extralite/database.c,
ext/extralite/iterator.c,
ext/extralite/changeset.c
Overview
Extralite is a Ruby gem for working with SQLite databases
Defined Under Namespace
Classes: Blob, BusyError, Changeset, Database, Error, InterruptError, Iterator, ParameterError, Query, SQLError
Constant Summary collapse
- SQLITE_STATUS_MEMORY_USED =
0
- SQLITE_STATUS_PAGECACHE_USED =
1
- SQLITE_STATUS_PAGECACHE_OVERFLOW =
2
- SQLITE_STATUS_SCRATCH_USED =
3
- SQLITE_STATUS_SCRATCH_OVERFLOW =
4
- SQLITE_STATUS_MALLOC_SIZE =
5
- SQLITE_STATUS_PARSER_STACK =
6
- SQLITE_STATUS_PAGECACHE_SIZE =
7
- SQLITE_STATUS_SCRATCH_SIZE =
8
- SQLITE_STATUS_MALLOC_COUNT =
9
- SQLITE_DBSTATUS_LOOKASIDE_USED =
0
- SQLITE_DBSTATUS_CACHE_USED =
1
- SQLITE_DBSTATUS_SCHEMA_USED =
2
- SQLITE_DBSTATUS_STMT_USED =
3
- SQLITE_DBSTATUS_LOOKASIDE_HIT =
4
- SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE =
5
- SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL =
6
- SQLITE_DBSTATUS_CACHE_HIT =
7
- SQLITE_DBSTATUS_CACHE_MISS =
8
- SQLITE_DBSTATUS_CACHE_WRITE =
9
- SQLITE_DBSTATUS_DEFERRED_FKS =
10
- SQLITE_DBSTATUS_CACHE_USED_SHARED =
11
- SQLITE_DBSTATUS_CACHE_SPILL =
12
- SQLITE_STMTSTATUS_FULLSCAN_STEP =
1
- SQLITE_STMTSTATUS_SORT =
2
- SQLITE_STMTSTATUS_AUTOINDEX =
3
- SQLITE_STMTSTATUS_VM_STEP =
4
- SQLITE_STMTSTATUS_REPREPARE =
5
- SQLITE_STMTSTATUS_RUN =
6
- SQLITE_STMTSTATUS_FILTER_MISS =
7
- SQLITE_STMTSTATUS_FILTER_HIT =
8
- SQLITE_STMTSTATUS_MEMUSED =
99
- SQLITE_LIMIT_LENGTH =
0
- SQLITE_LIMIT_SQL_LENGTH =
1
- SQLITE_LIMIT_COLUMN =
2
- SQLITE_LIMIT_EXPR_DEPTH =
3
- SQLITE_LIMIT_COMPOUND_SELECT =
4
- SQLITE_LIMIT_VDBE_OP =
5
- SQLITE_LIMIT_FUNCTION_ARG =
6
- SQLITE_LIMIT_ATTACHED =
7
- SQLITE_LIMIT_LIKE_PATTERN_LENGTH =
8
- SQLITE_LIMIT_VARIABLE_NUMBER =
9
- SQLITE_LIMIT_TRIGGER_DEPTH =
10
- SQLITE_LIMIT_WORKER_THREADS =
11
- SQLITE_OK =
0
- SQLITE_ERROR =
1
- SQLITE_INTERNAL =
2
- SQLITE_PERM =
3
- SQLITE_ABORT =
4
- SQLITE_BUSY =
5
- SQLITE_LOCKED =
6
- SQLITE_NOMEM =
7
- SQLITE_READONLY =
8
- SQLITE_INTERRUPT =
9
- SQLITE_IOERR =
10
- SQLITE_CORRUPT =
11
- SQLITE_NOTFOUND =
12
- SQLITE_FULL =
13
- SQLITE_CANTOPEN =
14
- SQLITE_PROTOCOL =
15
- SQLITE_EMPTY =
16
- SQLITE_SCHEMA =
17
- SQLITE_TOOBIG =
18
- SQLITE_CONSTRAINT =
19
- SQLITE_MISMATCH =
20
- SQLITE_MISUSE =
21
- SQLITE_NOLFS =
22
- SQLITE_AUTH =
23
- SQLITE_FORMAT =
24
- SQLITE_RANGE =
25
- SQLITE_NOTADB =
26
- SQLITE_NOTICE =
27
- SQLITE_WARNING =
28
- SQLITE_ROW =
100
- SQLITE_DONE =
101
- SQLITE_ERROR_MISSING_COLLSEQ =
(SQLITE_ERROR | (1<<8))
- SQLITE_ERROR_RETRY =
(SQLITE_ERROR | (2<<8))
- SQLITE_ERROR_SNAPSHOT =
(SQLITE_ERROR | (3<<8))
- SQLITE_IOERR_READ =
(SQLITE_IOERR | (1<<8))
- SQLITE_IOERR_SHORT_READ =
(SQLITE_IOERR | (2<<8))
- SQLITE_IOERR_WRITE =
(SQLITE_IOERR | (3<<8))
- SQLITE_IOERR_FSYNC =
(SQLITE_IOERR | (4<<8))
- SQLITE_IOERR_DIR_FSYNC =
(SQLITE_IOERR | (5<<8))
- SQLITE_IOERR_TRUNCATE =
(SQLITE_IOERR | (6<<8))
- SQLITE_IOERR_FSTAT =
(SQLITE_IOERR | (7<<8))
- SQLITE_IOERR_UNLOCK =
(SQLITE_IOERR | (8<<8))
- SQLITE_IOERR_RDLOCK =
(SQLITE_IOERR | (9<<8))
- SQLITE_IOERR_DELETE =
(SQLITE_IOERR | (10<<8))
- SQLITE_IOERR_BLOCKED =
(SQLITE_IOERR | (11<<8))
- SQLITE_IOERR_NOMEM =
(SQLITE_IOERR | (12<<8))
- SQLITE_IOERR_ACCESS =
(SQLITE_IOERR | (13<<8))
- SQLITE_IOERR_CHECKRESERVEDLOCK =
(SQLITE_IOERR | (14<<8))
- SQLITE_IOERR_LOCK =
(SQLITE_IOERR | (15<<8))
- SQLITE_IOERR_CLOSE =
(SQLITE_IOERR | (16<<8))
- SQLITE_IOERR_DIR_CLOSE =
(SQLITE_IOERR | (17<<8))
- SQLITE_IOERR_SHMOPEN =
(SQLITE_IOERR | (18<<8))
- SQLITE_IOERR_SHMSIZE =
(SQLITE_IOERR | (19<<8))
- SQLITE_IOERR_SHMLOCK =
(SQLITE_IOERR | (20<<8))
- SQLITE_IOERR_SHMMAP =
(SQLITE_IOERR | (21<<8))
- SQLITE_IOERR_SEEK =
(SQLITE_IOERR | (22<<8))
- SQLITE_IOERR_DELETE_NOENT =
(SQLITE_IOERR | (23<<8))
- SQLITE_IOERR_MMAP =
(SQLITE_IOERR | (24<<8))
- SQLITE_IOERR_GETTEMPPATH =
(SQLITE_IOERR | (25<<8))
- SQLITE_IOERR_CONVPATH =
(SQLITE_IOERR | (26<<8))
- SQLITE_IOERR_VNODE =
(SQLITE_IOERR | (27<<8))
- SQLITE_IOERR_AUTH =
(SQLITE_IOERR | (28<<8))
- SQLITE_IOERR_BEGIN_ATOMIC =
(SQLITE_IOERR | (29<<8))
- SQLITE_IOERR_COMMIT_ATOMIC =
(SQLITE_IOERR | (30<<8))
- SQLITE_IOERR_ROLLBACK_ATOMIC =
(SQLITE_IOERR | (31<<8))
- SQLITE_IOERR_DATA =
(SQLITE_IOERR | (32<<8))
- SQLITE_IOERR_CORRUPTFS =
(SQLITE_IOERR | (33<<8))
- SQLITE_LOCKED_SHAREDCACHE =
(SQLITE_LOCKED | (1<<8))
- SQLITE_LOCKED_VTAB =
(SQLITE_LOCKED | (2<<8))
- SQLITE_BUSY_RECOVERY =
(SQLITE_BUSY | (1<<8))
- SQLITE_BUSY_SNAPSHOT =
(SQLITE_BUSY | (2<<8))
- SQLITE_BUSY_TIMEOUT =
(SQLITE_BUSY | (3<<8))
- SQLITE_CANTOPEN_NOTEMPDIR =
(SQLITE_CANTOPEN | (1<<8))
- SQLITE_CANTOPEN_ISDIR =
(SQLITE_CANTOPEN | (2<<8))
- SQLITE_CANTOPEN_FULLPATH =
(SQLITE_CANTOPEN | (3<<8))
- SQLITE_CANTOPEN_CONVPATH =
(SQLITE_CANTOPEN | (4<<8))
- SQLITE_CANTOPEN_DIRTYWAL =
(SQLITE_CANTOPEN | (5<<8))
- SQLITE_CANTOPEN_SYMLINK =
(SQLITE_CANTOPEN | (6<<8))
- SQLITE_CORRUPT_VTAB =
(SQLITE_CORRUPT | (1<<8))
- SQLITE_CORRUPT_SEQUENCE =
(SQLITE_CORRUPT | (2<<8))
- SQLITE_CORRUPT_INDEX =
(SQLITE_CORRUPT | (3<<8))
- SQLITE_READONLY_RECOVERY =
(SQLITE_READONLY | (1<<8))
- SQLITE_READONLY_CANTLOCK =
(SQLITE_READONLY | (2<<8))
- SQLITE_READONLY_ROLLBACK =
(SQLITE_READONLY | (3<<8))
- SQLITE_READONLY_DBMOVED =
(SQLITE_READONLY | (4<<8))
- SQLITE_READONLY_CANTINIT =
(SQLITE_READONLY | (5<<8))
- SQLITE_READONLY_DIRECTORY =
(SQLITE_READONLY | (6<<8))
- SQLITE_ABORT_ROLLBACK =
(SQLITE_ABORT | (2<<8))
- SQLITE_CONSTRAINT_CHECK =
(SQLITE_CONSTRAINT | (1<<8))
- SQLITE_CONSTRAINT_COMMITHOOK =
(SQLITE_CONSTRAINT | (2<<8))
- SQLITE_CONSTRAINT_FOREIGNKEY =
(SQLITE_CONSTRAINT | (3<<8))
- SQLITE_CONSTRAINT_FUNCTION =
(SQLITE_CONSTRAINT | (4<<8))
- SQLITE_CONSTRAINT_NOTNULL =
(SQLITE_CONSTRAINT | (5<<8))
- SQLITE_CONSTRAINT_PRIMARYKEY =
(SQLITE_CONSTRAINT | (6<<8))
- SQLITE_CONSTRAINT_TRIGGER =
(SQLITE_CONSTRAINT | (7<<8))
- SQLITE_CONSTRAINT_UNIQUE =
(SQLITE_CONSTRAINT | (8<<8))
- SQLITE_CONSTRAINT_VTAB =
(SQLITE_CONSTRAINT | (9<<8))
- SQLITE_CONSTRAINT_ROWID =
(SQLITE_CONSTRAINT |(10<<8))
- SQLITE_CONSTRAINT_PINNED =
(SQLITE_CONSTRAINT |(11<<8))
- SQLITE_CONSTRAINT_DATATYPE =
(SQLITE_CONSTRAINT |(12<<8))
- SQLITE_NOTICE_RECOVER_WAL =
(SQLITE_NOTICE | (1<<8))
- SQLITE_NOTICE_RECOVER_ROLLBACK =
(SQLITE_NOTICE | (2<<8))
- SQLITE_WARNING_AUTOINDEX =
(SQLITE_WARNING | (1<<8))
- SQLITE_AUTH_USER =
(SQLITE_AUTH | (1<<8))
- SQLITE_OK_LOAD_PERMANENTLY =
(SQLITE_OK | (1<<8))
- SQLITE_OK_SYMLINK =
(SQLITE_OK | (2<<8))
- VERSION =
Extralite version
'2.8.2'
Class Method Summary collapse
-
.on_progress(**opts) { ... } ⇒ Extralite::Database
Installs or removes a global progress handler that will be executed periodically while a query is running.
-
.runtime_status(*args) ⇒ Object
Returns runtime status values for the given op as an array containing the current value and the high water mark value.
-
.sqlite3_version ⇒ String
Returns the sqlite3 library version used by Extralite.
Class Method Details
.on_progress(**opts) { ... } ⇒ Extralite::Database
Installs or removes a global progress handler that will be executed periodically while a query is running. This method can be used to support switching between fibers and threads or implementing timeouts for running queries.
This method sets the progress handler settings and behaviour for all
subsequently created Database
instances. Calling this method will have no
effect on already existing Database
instances
The period
parameter specifies the approximate number of SQLite
virtual machine instructions that are evaluated between successive
invocations of the progress handler. A period of less than 1 removes the
progress handler. The default period value is 1000.
The optional tick
parameter specifies the granularity of how often the
progress handler is called. The default tick value is 10, which means that
Extralite's underlying progress callback will be called every 10 SQLite VM
instructions. The given progress proc, however, will be only called every
period
(cumulative) VM instructions. This allows the progress handler to
work correctly also when running simple queries that don't include many
VM instructions. If the tick
value is greater than the period value it is
automatically capped to the period value.
The mode
parameter controls the progress handler mode, which is one of the
following:
:normal
(default): the progress handler proc is invoked on query progress.:once
: the progress handler proc is invoked only once, when preparing the query.:at_least_once
: the progress handler proc is invoked when prearing the query, and on query progress.
The progress handler is called also when the database is busy. This lets the
application perform work while waiting for the database to become unlocked,
or implement a timeout. Note that setting the database's busy_timeout after
setting a progress handler may lead to undefined behaviour in a concurrent
application. When busy, the progress handler proc is passed true
as the
first argument.
When the progress handler is set, the gvl release threshold value is set to -1, which means that the GVL will not be released at all when preparing or running queries. It is the application's responsibility to let other threads or fibers run by calling e.g. Thread.pass:
Extralite.on_progress do
do_something_interesting
Thread.pass # let other threads run
end
1312 1313 1314 1315 1316 1317 1318 |
# File 'ext/extralite/database.c', line 1312
VALUE Extralite_on_progress(int argc, VALUE *argv, VALUE self) {
VALUE opts;
rb_scan_args(argc, argv, "00:", &opts);
global_progress_handler = parse_progress_handler_opts(opts);
return self;
}
|
.runtime_status(op) ⇒ Array<Integer> .runtime_status(op, reset) ⇒ Array<Integer>
Returns runtime status values for the given op as an array containing the current value and the high water mark value. To reset the high water mark, pass true as reset.
You can use the various Extralite::SQLITE_STATUS_xxx
constants with this
method:
Extralite.runtime_status(Extralite::SQLITE_STATUS_MEMORY_USED)
For more information see the SQLite docs: https://sqlite.org/c3ref/c_status_malloc_count.html
949 950 951 952 953 954 955 956 957 958 959 |
# File 'ext/extralite/database.c', line 949
VALUE Extralite_runtime_status(int argc, VALUE* argv, VALUE self) {
VALUE op, reset;
sqlite3_int64 cur, hwm;
rb_scan_args(argc, argv, "11", &op, &reset);
int rc = sqlite3_status64(NUM2INT(op), &cur, &hwm, RTEST(reset) ? 1 : 0);
if (rc != SQLITE_OK) rb_raise(cError, "%s", sqlite3_errstr(rc));
return rb_ary_new3(2, LONG2FIX(cur), LONG2FIX(hwm));
}
|
.sqlite3_version ⇒ String
Returns the sqlite3 library version used by Extralite.
106 107 108 |
# File 'ext/extralite/database.c', line 106 VALUE Extralite_sqlite3_version(VALUE self) { return rb_str_new_cstr(sqlite3_version); } |