struct _sql_db_s {
sqlite3 * db; /* Database pointer */
int transaction; /* Do we have a transaction open? */
- SCP_t head_cursor; /* List of open cursors */
- int count;
};
struct _sql_dbcursor_s {
- DBC * name; /* Which DBC am I emulating? */
/*@only@*/ /*@relnull@*/
char * cmd; /* SQL command string */
SQL_MEM * memory;
int count;
- struct _sql_dbcursor_s * next;
};
struct _sql_mem_s {
/*@*/
{
DB * db = dbcursor->dbp;
- SQL_DB * sqldb;
- SCP_t scp;
+ SQL_DB * sqldb = (SQL_DB *)db->app_private;
+ SCP_t scp = (SCP_t)dbcursor->internal;
SQL_MEM * item;
- assert(db != NULL);
- sqldb = (SQL_DB *)db->app_private;
- assert(sqldb != NULL && sqldb->db != NULL);
- scp = sqldb->head_cursor;
-
- /* Find our version of the db3 cursor */
- while ( scp != NULL && scp->name != dbcursor ) {
- scp = scp->next;
- }
-
- assert(scp != NULL);
+assert(scp != NULL);
item = xmalloc(sizeof(*item));
item->mem_ptr = xmalloc(len);
-#if 0
- /* Only keep two pointers per cursor */
- if ( scp->memory ) {
- if ( scp->memory->next ) {
- scp->memory->next->mem_ptr = _free(scp->memory->next->mem_ptr);
-
- scp->memory->next = _free(scp->memory->next);
-
- scp->count--;
- }
- }
-#endif
-
item->next = scp->memory;
-
scp->memory = item;
- scp->count++;
return item->mem_ptr;
}
{
DB * db = dbi->dbi_db;
/*@i@*/ SQL_DB * sqldb = (SQL_DB *)db->app_private;
- SCP_t scp = sqldb->head_cursor;
+ SCP_t scp = (SCP_t)dbcursor->internal;
SCP_t prev = NULL;
int rc = 0;
assert(sqldb->db != NULL);
- /* Find our version of the db3 cursor */
- while ( scp != NULL && scp->name != dbcursor ) {
- prev = scp;
- scp = scp->next;
- }
if (_debug)
fprintf(stderr, "==> %s(%p)\n", __FUNCTION__, scp);
curr_mem = next_mem;
loc_count++;
}
-
- if ( scp->count != loc_count)
- rpmMessage(RPMMESS_DEBUG, "Alloced %ld -- free %ld\n",
- scp->count, loc_count);
- }
-
- /* Remove from the list */
- if (prev == NULL) {
- sqldb->head_cursor = scp->next;
- } else {
- prev->next = scp->next;
}
- sqldb->count--;
-
/*@-kepttrans@*/
scp = scpFree(scp);
/*@=kepttrans@*/
if (db && db->app_private && ((SQL_DB *)db->app_private)->db) {
sqldb = (SQL_DB *)db->app_private;
- assert(sqldb != NULL && sqldb->db != NULL);
+assert(sqldb != NULL && sqldb->db != NULL);
/* Commit, don't open a new one */
rc = sql_commitTransaction(dbi, 1);
/* close all cursors */
-/*@-infloops@*/
- while ( sqldb->head_cursor ) {
- (void) sql_cclose(dbi, sqldb->head_cursor->name, 0);
- }
-/*@=infloops@*/
-
- if (sqldb->count)
- rpmMessage(RPMMESS_DEBUG, "cursors %ld\n", sqldb->count);
+ /* HACK: unlear whether sqlite cursors need to be chained and closed. */
(void) sqlite3_close(sqldb->db);
(void) sqlite3_busy_handler(sqldb->db, &sql_busy_handler, dbi);
sqldb->transaction = 0; /* Initialize no current transactions */
- sqldb->head_cursor = NULL; /* no current cursors */
db->app_private = sqldb;
dbi->dbi_db = db;
scp = scpNew();
if (_debug)
fprintf(stderr, "==> %s(%s) tag %d type %d scp %p\n", __FUNCTION__, tagName(dbi->dbi_rpmtag), dbi->dbi_rpmtag, tagType(dbi->dbi_rpmtag), scp);
- scp->name = dbcursor;
- scp->next = sqldb->head_cursor;
- sqldb->head_cursor = scp;
- sqldb->count++;
+ dbcursor->internal = (DBC_INTERNAL *)scp;
/* If we're going to write, start a transaction (lock the DB) */
if (flags == DB_WRITECURSOR) {
DB * db = dbi->dbi_db;
/*@i@*/ SQL_DB * sqldb = (SQL_DB *)db->app_private;
SCP_t scp;
- int copen_done = 0;
int rc = 0;
assert(sqldb->db != NULL);
dbg_keyval(__FUNCTION__, dbi, dbcursor, key, data, flags);
-/* XXX modern rpm always uses copen/cclose. */
-assert(dbcursor != NULL);
- if ( dbcursor == NULL ) {
- rc = sql_copen ( dbi, NULL, &dbcursor, 0 );
- copen_done = 1;
- }
-
/* Find our version of the db3 cursor */
- scp = sqldb->head_cursor;
-/* XXX no need to chain cursors with copen/cclose. */
-assert(scp != NULL && scp->name == dbcursor);
- while ( scp != NULL && scp->name != dbcursor ) {
- scp = scp->next;
- }
-
+assert(dbcursor != NULL);
+ scp = (SCP_t)dbcursor->internal;
assert(scp != NULL);
if (noisy)
fprintf(stderr, "\tcget(%s) scp %p\n", dbi->dbi_subfile, scp);
fprintf(stderr, "\tcget(%s) not found\n", dbi->dbi_subfile);
}
- if (copen_done)
- /*@-temptrans@*/ (void) sql_cclose(dbi, dbcursor, 0); /*@=temptrans@*/
-
return rc;
}
/*@modifies *dbcursor, fileSystem @*/
{
DB * db = dbi->dbi_db;
- SQL_DB * sqldb;
+ SQL_DB * sqldb = (SQL_DB *)db->app_private;
/* unused */
rpmMessage(RPMMESS_ERROR, "sql_cpget() not implemented\n");
- assert(db != NULL);
- sqldb = (SQL_DB *)db->app_private;
- assert(sqldb != NULL && sqldb->db != NULL);
+assert(sqldb->db != NULL);
return EINVAL;
}