Actually if you need to re-use the prepared statement, it's much more
efficient to simply call sqlite_reset() on it instead of finalize.
As long as the statement is not currently step()'ing and is in the reset
state, the database will not be locked.
Example:
select_stmt = db.execute("SELECT * FROM people")
# use some, but not all of the rows in select_stmt
-->db.reset(select_stmt)
create_stmt = db.execute("CREATE TABLE other (a,b)") # error:
--># step through the select_stmt again
Robert
> -----Original Message-----
> From: Paolo Vernazza [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 08, 2005 9:09 AM
> To: [email protected]
> Subject: Re: [sqlite] create table question
>
> Charles Mills wrote:
>
> >>> I am trying to create a table after creating a select statement
> >>> which selects records from an existing table. Is this
> possible? I
> >>> get a SQLITE_LOCKED / "database table is locked" error when I
> >>> attempt this.
> >>>
> >>> In psuedo code the logic is as follows:
> >>>
> >>> select_stmt = db.execute("SELECT * FROM people")
> >>> # use some, but not all of the rows in select_stmt
> >>> create_stmt = db.execute("CREATE TABLE other (a,b)") # error:
> >>> database table is locked
> >>>
> >>> Why does this happen?
> >>>
> >>> Anyway around this?
> >>
> >>
> >> You must finalize select_stmt before running again db.execute
> >
> >
> > Right. I have an instance where I would like to keep the
> select_stmt
> > _open_ (or not finalized) while I create a new table. Is
> this possible?
>
> While you are reding the DB, you can't update it, sqlite support many
> simultaneous readers but only one write; so you can't create
> a new table
> while your select statement is running.
> I thin you must do somthing like this:
>
> select_stmt = db.execute("SELECT * FROM people")
> # use some, but not all of the rows in select_stmt
> sqltorun += "CREATE TABLE other (a,b);"
> select_stmt.finalize()
> create_stmt = db.execute(sqltorun)
>
> Paolo
>