rpm
5.4.14
|
#include "system.h"
#include <sqlite3.h>
#include <rpmsql.h>
#include <rpmlog.h>
#include <rpmmacro.h>
#include <rpmurl.h>
#include <rpmtag.h>
#include <rpmdb.h>
#include "debug.h"
Go to the source code of this file.
Data Structures | |
struct | key_s |
struct | _sql_dbcursor_s |
Macros | |
#define | _RPMSQL_INTERNAL |
#define | _RPMDB_INTERNAL |
#define | UINT32_T uint32_t |
#define | SQLDBDEBUG(_dbi, _list) if (((_dbi) && (_dbi)->dbi_debug) || (_sqldb_debug)) fprintf _list |
#define | _DBT_ENTRY(_v) { DB_DBT_##_v, #_v, } |
#define | _KEYDATA(_K, _P, _D, _R) fmtKDR(_K, _P, _D, _R) |
#define | cvtdberr(_dbi, _msg, _error) Xcvtdberr(_dbi, _msg, _error, _sqldb_debug, __FUNCTION__, __FILE__, __LINE__) |
#define | SCPDEBUG(_dbi, _list) if (_scp_debug) fprintf _list |
#define | scpUnlink(_scp) ((SCP_t)rpmioUnlinkPoolItem((rpmioItem)(_scp), __FUNCTION__, __FILE__, __LINE__)) |
#define | scpLink(_scp) ((SCP_t)rpmioLinkPoolItem((rpmioItem)(_scp), __FUNCTION__, __FILE__, __LINE__)) |
#define | scpFree(_scp) ((SCP_t)rpmioFreePoolItem((rpmioItem)(_scp), __FUNCTION__, __FILE__, __LINE__)) |
Typedefs | |
typedef struct key_s | KEY |
typedef struct _sql_dbcursor_s * | SCP_t |
Functions | |
static const char * | tblName (uint32_t v, KEY *tbl, size_t ntbl) |
static const char * | fmtBits (uint32_t flags, KEY tbl[], size_t ntbl, char *t) |
static char * | fmtDBT (const DBT *K, char *te) |
static const char * | fmtKDR (const DBT *K, const DBT *P, const DBT *D, const DBT *R) |
static int | Xcvtdberr (dbiIndex dbi, const char *msg, int error, int printit, const char *func, const char *fn, unsigned ln) |
SCP_t | scpUnlink (SCP_t scp) |
Unreference a SCP wrapper instance. More... | |
SCP_t | scpLink (SCP_t scp) |
Reference a SCP wrapper instance. More... | |
SCP_t | scpFree (SCP_t scp) |
Destroy a SCP wrapper. More... | |
static void | dbg_scp (void *ptr) |
static void | dbg_keyval (const char *msg, dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags) |
static SCP_t | scpResetKeys (SCP_t scp) |
static SCP_t | scpResetAv (SCP_t scp) |
static SCP_t | scpReset (SCP_t scp) |
static void | scpFini (void *_scp) |
static SCP_t | scpGetPool (rpmioPool pool) |
static SCP_t | scpNew (void *dbp) |
static int | sql_step (dbiIndex dbi, SCP_t scp) |
static int | sql_bind_key (dbiIndex dbi, SCP_t scp, int pos, DBT *key) |
static int | sql_bind_data (dbiIndex dbi, SCP_t scp, int pos, DBT *data) |
static int | sql_exec (dbiIndex dbi, const char *cmd, int(*callback)(void *, int, char **, char **), void *context) |
static int | sql_busy_handler (void *_dbi, int time) |
static int | sql_initDB_cb (void *_dbi, int argc, char **argv, char **cols) |
static int | sql_initDB (dbiIndex dbi) |
Verify the DB is setup. More... | |
static int | sql_cclose (dbiIndex dbi, DBC *dbcursor, unsigned int flags) |
Close database cursor. More... | |
static int | sql_close (dbiIndex dbi, unsigned int flags) |
Close index database, and destroy database handle. More... | |
static int | sql_open (rpmdb rpmdb, rpmTag rpmtag, dbiIndex *dbip) |
Return handle for an index database. More... | |
static int | sql_sync (dbiIndex dbi, unsigned int flags) |
Flush pending operations to disk. More... | |
static int | sql_exists (dbiIndex dbi, DBT *key, unsigned int flags) |
Return whether key exists in a database. More... | |
static int | sql_seqno_cb (void *_dbi, int argc, char **argv, char **cols) |
static int | sql_seqno (dbiIndex dbi, int64_t *seqnop, unsigned int flags) |
Return next sequence number. More... | |
static int | sql_copen (dbiIndex dbi, DB_TXN *txnid, DBC **dbcp, unsigned int flags) |
Open database cursor. More... | |
static int | sql_cdel (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags) |
Delete (key,data) pair(s) using db->del or dbcursor->c_del. More... | |
static int | sql_cget (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags) |
Retrieve (key,data) pair using db->get or dbcursor->c_get. More... | |
static int | sql_cput (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, unsigned int flags) |
Store (key,data) pair using db->put or dbcursor->c_put. More... | |
static int | sql_byteswapped (dbiIndex dbi) |
Is database byte swapped? More... | |
static int | sql_associate (dbiIndex dbi, dbiIndex dbisecondary, int(*callback)(DB *, const DBT *, const DBT *, DBT *), unsigned int flags) |
Associate secondary database with primary. More... | |
static int | sql_associate_foreign (dbiIndex dbi, dbiIndex dbisecondary, int(*callback)(DB *, const DBT *, DBT *, const DBT *, int *), unsigned int flags) |
Associate secondary database with primary. More... | |
static int | sql_join (dbiIndex dbi, DBC **curslist, DBC **dbcp, unsigned int flags) |
Return join cursor for list of cursors. More... | |
static int | sql_cdup (dbiIndex dbi, DBC *dbcursor, DBC **dbcp, unsigned int flags) |
Duplicate a database cursor. More... | |
static int | sql_cpget (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *pkey, DBT *data, unsigned int flags) |
Retrieve (key,data) pair using dbcursor->c_pget. More... | |
static int | sql_ccount (dbiIndex dbi, DBC *dbcursor, unsigned int *countp, unsigned int flags) |
Retrieve count of (possible) duplicate items using dbcursor->c_count. More... | |
static int | sql_stat_cb (void *_dbi, int argc, char **argv, char **cols) |
static int | sql_stat (dbiIndex dbi, unsigned int flags) |
Save statistics in database handle. More... | |
Variables | |
int | _sqldb_debug = 0 |
static KEY | DBTflags [] |
static size_t | nDBTflags = sizeof(DBTflags) / sizeof(DBTflags[0]) |
int | _scp_debug = 0 |
rpmioPool | _scpPool = NULL |
static const char | _Packages_sql_init [] |
static const char * | tagTypes [] |
static size_t | ntagTypes = sizeof(tagTypes) / sizeof(tagTypes[0]) |
static const char | seqno_inc_cmd [] |
struct _dbiVec | sqlitevec |
#define _KEYDATA | ( | _K, | |
_P, | |||
_D, | |||
_R | |||
) | fmtKDR(_K, _P, _D, _R) |
Definition at line 219 of file sqlite.c.
Referenced by sql_cdel(), sql_cget(), sql_cpget(), sql_cput(), and sql_exists().
#define cvtdberr | ( | _dbi, | |
_msg, | |||
_error | |||
) | Xcvtdberr(_dbi, _msg, _error, _sqldb_debug, __FUNCTION__, __FILE__, __LINE__) |
Definition at line 247 of file sqlite.c.
Referenced by scpReset(), sql_bind_data(), sql_bind_key(), sql_cdel(), sql_cget(), sql_cput(), sql_exec(), sql_open(), and sql_step().
#define SCPDEBUG | ( | _dbi, | |
_list | |||
) | if (_scp_debug) fprintf _list |
Definition at line 295 of file sqlite.c.
Referenced by scpFini(), scpReset(), scpResetAv(), and scpResetKeys().
#define scpFree | ( | _scp | ) | ((SCP_t)rpmioFreePoolItem((rpmioItem)(_scp), __FUNCTION__, __FILE__, __LINE__)) |
Definition at line 328 of file sqlite.c.
Referenced by sql_cclose(), sql_cdel(), and sql_cput().
#define scpLink | ( | _scp | ) | ((SCP_t)rpmioLinkPoolItem((rpmioItem)(_scp), __FUNCTION__, __FILE__, __LINE__)) |
Definition at line 316 of file sqlite.c.
Referenced by scpNew(), sql_cdel(), and sql_cput().
#define scpUnlink | ( | _scp | ) | ((SCP_t)rpmioUnlinkPoolItem((rpmioItem)(_scp), __FUNCTION__, __FILE__, __LINE__)) |
#define SQLDBDEBUG | ( | _dbi, | |
_list | |||
) | if (((_dbi) && (_dbi)->dbi_debug) || (_sqldb_debug)) fprintf _list |
Definition at line 70 of file sqlite.c.
Referenced by sql_associate(), sql_associate_foreign(), sql_busy_handler(), sql_byteswapped(), sql_cclose(), sql_ccount(), sql_cdel(), sql_cdup(), sql_cget(), sql_close(), sql_copen(), sql_cpget(), sql_cput(), sql_exec(), sql_exists(), sql_initDB(), sql_initDB_cb(), sql_join(), sql_open(), sql_seqno(), sql_seqno_cb(), sql_stat(), sql_stat_cb(), sql_step(), and sql_sync().
#define UINT32_T uint32_t |
Definition at line 61 of file sqlite.c.
Referenced by sql_cget().
typedef struct _sql_dbcursor_s* SCP_t |
|
static |
Definition at line 342 of file sqlite.c.
References __db_dbt::data, dbg_scp(), fprintf(), NULL, RPMTAG_NAME, and __db_dbt::size.
Referenced by sql_cdel(), sql_cget(), and sql_cput().
Definition at line 331 of file sqlite.c.
References _sql_dbcursor_s::ac, _sql_dbcursor_s::all, _sql_dbcursor_s::av, _sql_dbcursor_s::avlen, fprintf(), _sql_dbcursor_s::nalloc, _sql_dbcursor_s::nc, _sql_dbcursor_s::nr, ptr, and _sql_dbcursor_s::rx.
Referenced by dbg_keyval(), scpReset(), scpResetAv(), and scpResetKeys().
|
static |
|
static |
Definition at line 146 of file sqlite.c.
References __db_dbt::data, DB_DBT_MULTIPLE, ellipsis, __db_dbt::flags, fmtBits(), i, nb, nDBTflags, __db_dbt::size, sprintf(), te, void, and xisprint().
Referenced by fmtKDR().
Definition at line 461 of file sqlite.c.
References _free(), _sql_dbcursor_s::av, _sql_dbcursor_s::avlen, NULL, SCPDEBUG, scpReset(), and scpResetKeys().
Referenced by scpGetPool().
Destroy a SCP wrapper.
scp | SCP wrapper |
Definition at line 477 of file sqlite.c.
References _sql_dbcursor_s::_item, _scpPool, memset(), NULL, rpmioGetPool(), rpmioNewPool(), and scpFini().
Referenced by scpNew().
Reference a SCP wrapper instance.
scp | SCP wrapper |
Definition at line 493 of file sqlite.c.
References _sql_dbcursor_s::ldata, _sql_dbcursor_s::lkey, NULL, scpGetPool(), scpLink, and _sql_dbcursor_s::used.
Referenced by sql_copen().
Definition at line 428 of file sqlite.c.
References _free(), _sql_dbcursor_s::cmd, cvtdberr, dbg_scp(), NULL, _sql_dbcursor_s::pStmt, _sql_dbcursor_s::rx, SCPDEBUG, scpResetAv(), and xx.
Referenced by scpFini(), and sql_cget().
Definition at line 390 of file sqlite.c.
References _free(), _sql_dbcursor_s::ac, _sql_dbcursor_s::av, _sql_dbcursor_s::avlen, dbg_scp(), memset(), _sql_dbcursor_s::nalloc, _sql_dbcursor_s::nc, _sql_dbcursor_s::nr, NULL, SCPDEBUG, and xx.
Referenced by scpReset(), and sql_cget().
Definition at line 367 of file sqlite.c.
References _free(), __db_dbt::data, dbg_scp(), ix, _sql_dbcursor_s::keys, _sql_dbcursor_s::nkeys, NULL, and SCPDEBUG.
Referenced by scpFini(), and sql_cget().
Unreference a SCP wrapper instance.
scp | SCP wrapper |
|
static |
Associate secondary database with primary.
dbi | index database handle |
dbisecondary | secondary index database handle |
callback | create secondary key from primary (NULL if DB_RDONLY) |
flags | DB_CREATE or 0 |
Definition at line 1628 of file sqlite.c.
References rc, and SQLDBDEBUG.
|
static |
Associate secondary database with primary.
dbi | index database handle |
dbisecondary | secondary index database handle |
callback | create secondary key from primary (NULL if DB_RDONLY) |
flags | DB_CREATE or 0 |
Definition at line 1647 of file sqlite.c.
References rc, and SQLDBDEBUG.
Definition at line 730 of file sqlite.c.
References assert(), cvtdberr, __db_dbt::data, NULL, _sql_dbcursor_s::pStmt, rc, and __db_dbt::size.
Referenced by sql_cdel(), and sql_cput().
Definition at line 662 of file sqlite.c.
References assert(), cvtdberr, __db_dbt::data, i, NULL, _sql_dbcursor_s::pStmt, rc, RPM_BIN_TYPE, RPM_I18NSTRING_TYPE, RPM_MASK_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, RPM_UINT16_TYPE, RPM_UINT32_TYPE, RPM_UINT64_TYPE, RPM_UINT8_TYPE, RPMDBI_PACKAGES, __db_dbt::size, and tagType().
Referenced by sql_cdel(), sql_cget(), and sql_cput().
Definition at line 760 of file sqlite.c.
References _, rc, rpmlog(), RPMLOG_WARNING, SQLDBDEBUG, and void.
Referenced by sql_open().
Is database byte swapped?
dbi | index database handle |
Definition at line 1609 of file sqlite.c.
References rc, and SQLDBDEBUG.
Close database cursor.
dbi | index database handle |
dbcursor | database cursor |
flags | (unused) |
Definition at line 1061 of file sqlite.c.
References _free(), _sql_dbcursor_s::ldata, _sql_dbcursor_s::lkey, rc, scpFree, and SQLDBDEBUG.
Referenced by sql_copen().
|
static |
Retrieve count of (possible) duplicate items using dbcursor->c_count.
dbi | index database handle |
dbcursor | database cursor |
countp | address of count |
flags | (unused) |
Definition at line 1730 of file sqlite.c.
References rc, and SQLDBDEBUG.
|
static |
Delete (key,data) pair(s) using db->del or dbcursor->c_del.
dbi | index database handle |
dbcursor | database cursor (NULL will use db->del) |
key | delete key value/length/flags |
data | delete data value/length/flags |
flags | (unused) |
Definition at line 1348 of file sqlite.c.
References _KEYDATA, assert(), _sql_dbcursor_s::cmd, cvtdberr, dbg_keyval(), NULL, _sql_dbcursor_s::pStmt, _sql_dbcursor_s::pzErrmsg, rc, rpmlog(), RPMLOG_WARNING, scpFree, scpLink, sql_bind_data(), sql_bind_key(), sql_step(), and SQLDBDEBUG.
Duplicate a database cursor.
dbi | index database handle |
dbcursor | database cursor |
dbcp | address of new database cursor |
flags | DB_POSITION for same position, 0 for uninitialized |
Definition at line 1686 of file sqlite.c.
References rc, and SQLDBDEBUG.
|
static |
Retrieve (key,data) pair using db->get or dbcursor->c_get.
dbi | index database handle |
dbcursor | database cursor (NULL will use db->get) |
key | retrieve key value/length/flags |
data | retrieve data value/length/flags |
flags | (unused) |
Definition at line 1394 of file sqlite.c.
References _free(), _KEYDATA, _sql_dbcursor_s::all, assert(), _sql_dbcursor_s::av, _sql_dbcursor_s::avlen, _sql_dbcursor_s::cmd, cvtdberr, __db_dbt::data, DB_DBT_MALLOC, DB_NOTFOUND, DB_SET, dbg_keyval(), exit, __db_dbt::flags, ix, _sql_dbcursor_s::keys, _sql_dbcursor_s::ldata, _sql_dbcursor_s::lkey, _sql_dbcursor_s::nkeys, _sql_dbcursor_s::nr, NULL, _sql_dbcursor_s::pStmt, _sql_dbcursor_s::pzErrmsg, rc, RPMDBI_PACKAGES, rpmlog(), RPMLOG_WARNING, _sql_dbcursor_s::rx, scpReset(), scpResetAv(), scpResetKeys(), __db_dbt::size, sql_bind_key(), sql_step(), SQLDBDEBUG, UINT32_T, _sql_dbcursor_s::used, void, xcalloc(), and xmalloc.
Close index database, and destroy database handle.
dbi | index database handle |
flags | (unused) |
Definition at line 1089 of file sqlite.c.
References _free(), D_, DB_PRIVATE, if(), NULL, rc, rpmGenPath(), rpmlog(), RPMLOG_DEBUG, rpmsqlFree(), SQLDBDEBUG, Unlink(), urlPath(), void, and xx.
Referenced by sql_open().
Open database cursor.
dbi | index database handle |
txnid | database transaction handle |
dbcp | address of new database cursor |
flags | DB_WRITECURSOR or 0 |
Definition at line 1317 of file sqlite.c.
References rc, RPM_MASK_TYPE, scpNew(), sql_cclose(), SQLDBDEBUG, tagName(), and tagType().
|
static |
Retrieve (key,data) pair using dbcursor->c_pget.
dbi | index database handle |
dbcursor | database cursor |
key | secondary retrieve key value/length/flags |
pkey | primary retrieve key value/length/flags |
data | primary retrieve data value/length/flags |
flags | DB_NEXT, DB_SET, or 0 |
Definition at line 1708 of file sqlite.c.
References _KEYDATA, NULL, rc, and SQLDBDEBUG.
|
static |
Store (key,data) pair using db->put or dbcursor->c_put.
dbi | index database handle |
dbcursor | database cursor (NULL will use db->put) |
key | store key value/length/flags |
data | store data value/length/flags |
flags | (unused) |
Definition at line 1566 of file sqlite.c.
References _KEYDATA, assert(), _sql_dbcursor_s::cmd, cvtdberr, dbg_keyval(), NULL, _sql_dbcursor_s::pStmt, _sql_dbcursor_s::pzErrmsg, rc, rpmlog(), RPMLOG_WARNING, scpFree, scpLink, sql_bind_data(), sql_bind_key(), sql_step(), and SQLDBDEBUG.
|
static |
Definition at line 745 of file sqlite.c.
References _free(), cvtdberr, NULL, rc, and SQLDBDEBUG.
Referenced by sql_initDB(), sql_seqno(), and sql_stat().
Verify the DB is setup.
. if not initialize it
Create the table.. create the db_info
Definition at line 912 of file sqlite.c.
References _free(), DB_EXCL, exit, int, N, name, NULL, rc, RPM_MASK_TYPE, RPMDBI_PACKAGES, RPMDBI_SEQNO, rpmGenPath(), rpmioMkpath(), RPMTAG_PUBKEYS, sprintf(), sql_exec(), sql_initDB_cb(), SQLDBDEBUG, and tagType().
Referenced by sql_open().
Definition at line 894 of file sqlite.c.
References NULL, rc, and SQLDBDEBUG.
Referenced by sql_initDB().
Return join cursor for list of cursors.
dbi | index database handle |
curslist | NULL terminated list of database cursors |
dbcp | address of join database cursor |
flags | DB_JOIN_NOSORT or 0 |
Definition at line 1666 of file sqlite.c.
References rc, and SQLDBDEBUG.
Return handle for an index database.
rpmdb | rpm database |
rpmtag | rpm tag |
*dbip | index database handle |
Definition at line 1131 of file sqlite.c.
References _free(), cvtdberr, D_, DB_PRIVATE, dbi, exit, NULL, rc, rpmGenPath(), rpmioMkpath(), rpmlog(), RPMLOG_DEBUG, rpmsqlNew(), s, sql_busy_handler(), sql_close(), sql_initDB(), SQLDBDEBUG, sqlitevec, tagName(), urlPath(), void, xstrdup(), and xx.
Definition at line 1276 of file sqlite.c.
References NULL, rc, and SQLDBDEBUG.
Referenced by sql_seqno().
Definition at line 1742 of file sqlite.c.
References NULL, rc, and SQLDBDEBUG.
Referenced by sql_stat().
Definition at line 511 of file sqlite.c.
References _sql_dbcursor_s::ac, assert(), _sql_dbcursor_s::av, _sql_dbcursor_s::avlen, _sql_dbcursor_s::cmd, cvtdberr, fprintf(), i, _sql_dbcursor_s::nalloc, nb, _sql_dbcursor_s::nc, _sql_dbcursor_s::nr, NULL, _sql_dbcursor_s::pStmt, rc, SQLDBDEBUG, strcmp(), t, xmalloc, xrealloc, and xstrdup().
Referenced by sql_cdel(), sql_cget(), and sql_cput().
Flush pending operations to disk.
dbi | index database handle |
flags | (unused) |
Definition at line 1237 of file sqlite.c.
References rc, and SQLDBDEBUG.
|
static |
Definition at line 475 of file sqlite.c.
Referenced by scpGetPool().
|
static |
|
static |
struct _dbiVec sqlitevec |
Definition at line 1793 of file sqlite.c.
Referenced by sql_open().