Григорий Григоренко <grigore...@mail.ru> wrote:
> I am using prepared stmts to cache selected record for later use. I have a 
> wrapper class, that has methods like AsString(name),
> AsFloat(name) etc to extract data for a column name. 
> 
> I prepare, bind and then do Sqlite3_step() to get record. Later I use 
> sqlite3_column_XXX() to access data.
> 
> My concern is - do open selective prepared stmts depend on something in db or 
> lock something in db?

Yes, until you call sqlite3_reset or sqlite3_finalize. For as long as the 
statement is "active" (meaning, sqlite3_reset or sqlite3_finalize has not been 
called after the most recent sqlite3_step call), it holds a read transaction 
open.

> Var Alice := Db.SelectRecord('SELECT * FROM client WHERE client_name = ?', [  
> 'alice' ]);
> 
> 1. If I drop record for "alice" from db and then access column data in 
> prepared stmt will it work OK?

If the select statement wasn't reset or finalized, you won't be able to delete 
a record from the database (or, in WAL journaling mode, you would be able to, 
but the reader would still see original data).

> 2. Can I drop client table while having such prepared stmt not closed?

What do you mean by "closed" here?

> 3. If I have a lot of such stmts (100 or more) will it somehow affect 
> performance of SQLite or waste lots of memory?

No, not really. There is a reasonably small data structure associated with a 
prepared statement, on the order of a few hundred bytes perhaps.

> Are there some kind of cursors for each selecting prepared stmt? 

In a sense. After a call to sqlite3_step and before a call of sqlite3_reset or 
sqlite3_finalize, you might think of a statement handle as a form of a cursor. 
Each subsequent sqlite3_step call advances this cursor forward by one row.

> 4. If there is a cursor, maybe there is a way to disconnect a cursor from 
> stmt keeping the single record still available?

No, short of making a copy of every column's value.
-- 
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to