Data Structures | Defines | Typedefs | Functions | Variables

rpmdb/sqlite.c File Reference

#include "system.h"
#include <rpmio.h>
#include <rpmlog.h>
#include <rpmmacro.h>
#include <rpmurl.h>
#include <rpmtag.h>
#include <rpmdb.h>
#include <sqlite3.h>
#include "debug.h"
Include dependency graph for sqlite.c:

Go to the source code of this file.

Data Structures

struct  _sql_db_s
struct  _sql_dbcursor_s
union  _dbswap

Defines

#define _RPMDB_INTERNAL
#define UINT32_T   rpmuint32_t
#define _DBSWAP(_a)

Typedefs

typedef struct _sql_db_s SQL_DB
typedef struct _sql_dbcursor_sSCP_t

Functions

static void enterChroot (dbiIndex dbi)
static void leaveChroot (dbiIndex dbi)
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 SCP_t scpFree (SCP_t scp)
static SCP_t scpNew (DB *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_startTransaction (dbiIndex dbi)
static int sql_endTransaction (dbiIndex dbi)
static int sql_commitTransaction (dbiIndex dbi, int flag)
static int sql_busy_handler (void *dbi_void, int time)
static int sql_initDB (dbiIndex dbi)
 Verify the DB is setup.
static int sql_cclose (dbiIndex dbi, DBC *dbcursor, unsigned int flags)
 Close database cursor.
static int sql_close (dbiIndex dbi, unsigned int flags)
 Close index database, and destroy database handle.
static int sql_open (rpmdb rpmdb, rpmTag rpmtag, dbiIndex *dbip)
 Return handle for an index database.
static int sql_sync (dbiIndex dbi, unsigned int flags)
 Flush pending operations to disk.
static int sql_copen (dbiIndex dbi, DB_TXN *txnid, DBC **dbcp, unsigned int flags)
 Open database cursor.
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.
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.
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.
static int sql_byteswapped (dbiIndex dbi)
 Is database byte swapped?
static int sql_associate (dbiIndex dbi, dbiIndex dbisecondary, int(*callback)(DB *, const DBT *, const DBT *, DBT *), unsigned int flags)
 Associate secondary database with primary.
static int sql_join (dbiIndex dbi, DBC **curslist, DBC **dbcp, unsigned int flags)
 Return join cursor for list of cursors.
static int sql_cdup (dbiIndex dbi, DBC *dbcursor, DBC **dbcp, unsigned int flags)
 Duplicate a database cursor.
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.
static int sql_ccount (dbiIndex dbi, DBC *dbcursor, unsigned int *countp, unsigned int flags)
 Retrieve count of (possible) duplicate items using dbcursor->c_count.
static int sql_stat (dbiIndex dbi, unsigned int flags)
 Save statistics in database handle.

Variables

static int _debug = 0
static unsigned int endian = 0x11223344
static const char * sqlCwd = NULL
static int sqlInRoot = 0
struct _dbiVec sqlitevec

Define Documentation

#define _DBSWAP (   _a )
Value:
{ unsigned char _b, *_c = (_a).uc; \
    _b = _c[3]; _c[3] = _c[0]; _c[0] = _b; \
    _b = _c[2]; _c[2] = _c[1]; _c[1] = _b; \
  }

Definition at line 120 of file sqlite.c.

Referenced by sql_bind_key(), and sql_step().

#define _RPMDB_INTERNAL

Definition at line 44 of file sqlite.c.

#define UINT32_T   rpmuint32_t

Definition at line 54 of file sqlite.c.

Referenced by sql_cget().


Typedef Documentation

typedef struct _sql_dbcursor_s* SCP_t

Definition at line 70 of file sqlite.c.

typedef struct _sql_db_s SQL_DB

Definition at line 69 of file sqlite.c.


Function Documentation

static void dbg_keyval ( const char *  msg,
dbiIndex  dbi,
DBC dbcursor,
DBT key,
DBT data,
unsigned int  flags 
) [static]

Definition at line 207 of file sqlite.c.

References _debug, __db_dbt::data, dbg_scp(), and __db_dbt::size.

Referenced by sql_cdel(), sql_cget(), and sql_cput().

static void dbg_scp ( void *  ptr ) [static]
static void enterChroot ( dbiIndex  dbi ) [static]
static void leaveChroot ( dbiIndex  dbi ) [static]
static SCP_t scpFree ( SCP_t  scp ) [static]
static SCP_t scpNew ( DB dbp ) [static]
static SCP_t scpReset ( SCP_t  scp ) [static]
static SCP_t scpResetAv ( SCP_t  scp ) [static]
static SCP_t scpResetKeys ( SCP_t  scp ) [static]

Definition at line 232 of file sqlite.c.

References _debug, _free(), __db_dbt::data, dbg_scp(), _sql_dbcursor_s::keys, and _sql_dbcursor_s::nkeys.

Referenced by scpFree(), and sql_cget().

static int sql_associate ( dbiIndex  dbi,
dbiIndex  dbisecondary,
int(*)(DB *, const DBT *, const DBT *, DBT *)  callback,
unsigned int  flags 
) [static]

Associate secondary database with primary.

Parameters:
dbiindex database handle
dbisecondarysecondary index database handle
callbackcreate secondary key from primary (NULL if DB_RDONLY)
flagsDB_CREATE or 0
Returns:
0 on success

Definition at line 1435 of file sqlite.c.

References _debug.

static int sql_bind_data ( dbiIndex  dbi,
SCP_t  scp,
int  pos,
DBT data 
) [static]

Definition at line 589 of file sqlite.c.

References __db_dbt::data, _sql_dbcursor_s::pStmt, and __db_dbt::size.

Referenced by sql_cdel(), and sql_cput().

static int sql_bind_key ( dbiIndex  dbi,
SCP_t  scp,
int  pos,
DBT key 
) [static]
static int sql_busy_handler ( void *  dbi_void,
int  time 
) [static]

Definition at line 677 of file sqlite.c.

References _, rpmlog(), and RPMLOG_WARNING.

Referenced by sql_open().

static int sql_byteswapped ( dbiIndex  dbi ) [static]

Is database byte swapped?

Parameters:
dbiindex database handle
Returns:
0 no

Definition at line 1380 of file sqlite.c.

References D_, _sql_db_s::db, endian, enterChroot(), leaveChroot(), rpmlog(), RPMLOG_DEBUG, RPMLOG_WARNING, scpFree(), scpNew(), and _dbswap::uc.

static int sql_cclose ( dbiIndex  dbi,
DBC dbcursor,
unsigned int  flags 
) [static]

Close database cursor.

Parameters:
dbiindex database handle
dbcursordatabase cursor
flags(unused)
Returns:
0 on success

Definition at line 821 of file sqlite.c.

References _debug, _free(), DB_WRITECURSOR, enterChroot(), _sql_dbcursor_s::ldata, leaveChroot(), _sql_dbcursor_s::lkey, scpFree(), sql_commitTransaction(), and sql_endTransaction().

Referenced by sql_copen().

static int sql_ccount ( dbiIndex  dbi,
DBC dbcursor,
unsigned int *  countp,
unsigned int  flags 
) [static]

Retrieve count of (possible) duplicate items using dbcursor->c_count.

Parameters:
dbiindex database handle
dbcursordatabase cursor
countpaddress of count
flags(unused)
Returns:
0 on success

Definition at line 1518 of file sqlite.c.

References _debug.

static int sql_cdel ( dbiIndex  dbi,
DBC dbcursor,
DBT key,
DBT data,
unsigned int  flags 
) [static]

Delete (key,data) pair(s) using db->del or dbcursor->c_del.

Parameters:
dbiindex database handle
dbcursordatabase cursor (NULL will use db->del)
keydelete key value/length/flags
datadelete data value/length/flags
flags(unused)
Returns:
0 on success

Definition at line 1115 of file sqlite.c.

References _sql_db_s::db, dbg_keyval(), enterChroot(), leaveChroot(), rpmlog(), RPMLOG_WARNING, scpFree(), scpNew(), sql_bind_data(), sql_bind_key(), and sql_step().

static int sql_cdup ( dbiIndex  dbi,
DBC dbcursor,
DBC **  dbcp,
unsigned int  flags 
) [static]

Duplicate a database cursor.

Parameters:
dbiindex database handle
dbcursordatabase cursor
Return values:
dbcpaddress of new database cursor
Parameters:
flagsDB_POSITION for same position, 0 for uninitialized
Returns:
0 on success

Definition at line 1474 of file sqlite.c.

References _debug.

static int sql_cget ( dbiIndex  dbi,
DBC dbcursor,
DBT key,
DBT data,
unsigned int  flags 
) [static]

Retrieve (key,data) pair using db->get or dbcursor->c_get.

Parameters:
dbiindex database handle
dbcursordatabase cursor (NULL will use db->get)
keyretrieve key value/length/flags
dataretrieve data value/length/flags
flags(unused)
Returns:
0 on success

Definition at line 1156 of file sqlite.c.

References _debug, _free(), __db_dbt::data, _sql_db_s::db, DB_DBT_MALLOC, DB_NOTFOUND, DB_SET, dbg_keyval(), enterChroot(), __db_dbt::flags, leaveChroot(), RPMDBI_PACKAGES, rpmlog(), RPMLOG_WARNING, scpReset(), scpResetAv(), scpResetKeys(), __db_dbt::size, sql_bind_key(), sql_step(), UINT32_T, xcalloc(), and xmalloc().

static int sql_close ( dbiIndex  dbi,
unsigned int  flags 
) [static]

Close index database, and destroy database handle.

Parameters:
dbiindex database handle
flags(unused)
Returns:
0 on success

Definition at line 860 of file sqlite.c.

References _free(), D_, _sql_db_s::db, DB_PRIVATE, enterChroot(), leaveChroot(), rpmGenPath(), rpmlog(), RPMLOG_DEBUG, sql_commitTransaction(), Unlink(), and urlPath().

Referenced by sql_open().

static int sql_commitTransaction ( dbiIndex  dbi,
int  flag 
) [static]

Definition at line 652 of file sqlite.c.

References _debug, _sql_db_s::db, sql_startTransaction(), and _sql_db_s::transaction.

Referenced by sql_cclose(), sql_close(), and sql_sync().

static int sql_copen ( dbiIndex  dbi,
DB_TXN txnid,
DBC **  dbcp,
unsigned int  flags 
) [static]

Open database cursor.

Parameters:
dbiindex database handle
txniddatabase transaction handle
Return values:
dbcpaddress of new database cursor
Parameters:
flagsDB_WRITECURSOR or 0
Returns:
0 on success

Definition at line 1077 of file sqlite.c.

References _debug, DB_WRITECURSOR, enterChroot(), leaveChroot(), RPM_MASK_TYPE, scpNew(), sql_cclose(), sql_startTransaction(), tagName(), and tagType().

static int sql_cpget ( dbiIndex  dbi,
DBC dbcursor,
DBT key,
DBT pkey,
DBT data,
unsigned int  flags 
) [static]

Retrieve (key,data) pair using dbcursor->c_pget.

Parameters:
dbiindex database handle
dbcursordatabase cursor
keysecondary retrieve key value/length/flags
pkeyprimary retrieve key value/length/flags
dataprimary retrieve data value/length/flags
flagsDB_NEXT, DB_SET, or 0
Returns:
0 on success

Definition at line 1496 of file sqlite.c.

References _debug.

static int sql_cput ( dbiIndex  dbi,
DBC dbcursor,
DBT key,
DBT data,
unsigned int  flags 
) [static]

Store (key,data) pair using db->put or dbcursor->c_put.

Parameters:
dbiindex database handle
dbcursordatabase cursor (NULL will use db->put)
keystore key value/length/flags
datastore data value/length/flags
flags(unused)
Returns:
0 on success

Definition at line 1338 of file sqlite.c.

References _sql_db_s::db, dbg_keyval(), enterChroot(), leaveChroot(), rpmlog(), RPMLOG_WARNING, scpFree(), scpNew(), sql_bind_data(), sql_bind_key(), and sql_step().

static int sql_endTransaction ( dbiIndex  dbi ) [static]

Definition at line 630 of file sqlite.c.

References _debug, _sql_db_s::db, and _sql_db_s::transaction.

Referenced by sql_cclose().

static int sql_initDB ( dbiIndex  dbi ) [static]
static int sql_join ( dbiIndex  dbi,
DBC **  curslist,
DBC **  dbcp,
unsigned int  flags 
) [static]

Return join cursor for list of cursors.

Parameters:
dbiindex database handle
curslistNULL terminated list of database cursors
Return values:
dbcpaddress of join database cursor
Parameters:
flagsDB_JOIN_NOSORT or 0
Returns:
0 on success

Definition at line 1454 of file sqlite.c.

References _debug.

static int sql_open ( rpmdb  rpmdb,
rpmTag  rpmtag,
dbiIndex dbip 
) [static]

Return handle for an index database.

Parameters:
rpmdbrpm database
rpmtagrpm tag
Return values:
*dbipindex database handle
Returns:
0 on success

Definition at line 908 of file sqlite.c.

References _free(), Chmod(), D_, _sql_db_s::db, DB_PRIVATE, enterChroot(), leaveChroot(), rpmGenPath(), rpmioMkpath(), rpmlog(), RPMLOG_DEBUG, sql_busy_handler(), sql_close(), sql_initDB(), sqlitevec, stpcpy(), tagName(), _sql_db_s::transaction, urlPath(), xcalloc(), and xstrdup().

static int sql_startTransaction ( dbiIndex  dbi ) [static]

Definition at line 608 of file sqlite.c.

References _debug, _sql_db_s::db, and _sql_db_s::transaction.

Referenced by sql_commitTransaction(), and sql_copen().

static int sql_step ( dbiIndex  dbi,
SCP_t  scp 
) [static]
static int sql_sync ( dbiIndex  dbi,
unsigned int  flags 
) [static]

Flush pending operations to disk.

Parameters:
dbiindex database handle
flags(unused)
Returns:
0 on success

Definition at line 1056 of file sqlite.c.

References enterChroot(), leaveChroot(), and sql_commitTransaction().


Variable Documentation

int _debug = 0 [static]
unsigned int endian = 0x11223344 [static]

Definition at line 127 of file sqlite.c.

Referenced by sql_byteswapped(), and sql_initDB().

const char* sqlCwd = NULL [static]

Definition at line 130 of file sqlite.c.

Referenced by enterChroot(), and leaveChroot().

int sqlInRoot = 0 [static]

Definition at line 132 of file sqlite.c.

Referenced by enterChroot(), and leaveChroot().

struct _dbiVec sqlitevec