Re: [sqlite] Increasing performance of joins with a group by clause?

2007-08-20 Thread Jef Driesen
John Machin wrote: On 19/08/2007 4:01 AM, Jef Driesen wrote: Suppose I have two related tables: CREATE TABLE events ( id INTEGER PRIMARY KEY NOT NULL, place_id INTEGER ); CREATE TABLE places ( id INTEGER PRIMARY KEY NOT NULL, name TEXT ); INSERT INTO places (id, name

[sqlite] When to use SQLITE_STATIC and SQLITE_TRANSIENT?

2007-08-10 Thread Jef Driesen
When using sqlite3_bind_text() (or a similar function) with SQLITE_STATIC, how long does the pointer have to remain valid? As long as the sqlite3_stmt is not finalized? It is clear to me the following will cause no problem: sqlite3_bind_text (stmt, column, "some text", -1, SQLITE_STATIC);

[sqlite] Can an autogenerated integer primary key become negative or zero?

2007-08-10 Thread Jef Driesen
Suppose I have a simple table with an integer primary key: CREATE TABLE table ( id INTEGER PRIMARY KEY NOT NULL, name TEXT ); and insert values without supplying a value for the primary key: INSERT INTO table (name) VALUES (@name); Is it guaranteed that the primary key is always

[sqlite] Re: sqlite_finalize() releases resources?

2007-07-04 Thread Jef Driesen
Dan Kennedy wrote: On Wed, 2007-07-04 at 09:58 +0200, Jef Driesen wrote: Igor Tandetnik wrote: Mario Figueiredo wrote: I'm a tad bit confused with sqlite3_finalize() usage when the query fails. As it is, I'm assuming it releases resources and I use it in this context

[sqlite] Re: sqlite_finalize() releases resources?

2007-07-04 Thread Jef Driesen
Igor Tandetnik wrote: Mario Figueiredo wrote: I'm a tad bit confused with sqlite3_finalize() usage when the query fails. As it is, I'm assuming it releases resources and I use it in this context: rc = sqlite3_prepare_v2(/* ... */); if (rc != SQLITE_OK) {

[sqlite] Re: sqlite3_reset (or sqlite3_finalize) and error reporting?

2007-05-29 Thread Jef Driesen
Scott McDonald wrote: Jef Driesen wrote: Scott McDonald wrote: Jef Driesen wrote: I have some questions on the usage of sqlite3_reset (or sqlite3_finalize) after sqlite3_step. In the legacy interface I use sqlite3_reset after sqlite3_step to obtain a more specific error code

[sqlite] Re: sqlite3_reset (or sqlite3_finalize) and error reporting?

2007-05-22 Thread Jef Driesen
Scott McDonald wrote: Jef Driesen wrote: I have some questions on the usage of sqlite3_reset (or sqlite3_finalize) after sqlite3_step. In the legacy interface I use sqlite3_reset after sqlite3_step to obtain a more specific error code for SQLITE_ERROR (to be able to detect schema errors

[sqlite] Re: Can I execute queries from an sqlite3_update_hook callback function?

2007-05-15 Thread Jef Driesen
Igor Tandetnik wrote: Jef Driesen wrote: I'm trying to execute a query from the callback function that is registered with sqlite3_update_hook. But sqlite3_prepare_v2 always returns SQLITE_MISUSE. Is it not allowed to execute queries from the callback function? I'm was trying to use

[sqlite] Can I execute queries from an sqlite3_update_hook callback function?

2007-05-08 Thread Jef Driesen
I'm trying to execute a query from the callback function that is registered with sqlite3_update_hook. But sqlite3_prepare_v2 always returns SQLITE_MISUSE. Is it not allowed to execute queries from the callback function? I'm was trying to use the callback function as a notification mechanism to

[sqlite] Re: Some questions on hierarchical data (nested set model)

2007-04-25 Thread Jef Driesen
A. Pagaltzis wrote: * Jef Driesen <[EMAIL PROTECTED]> [2007-04-11 16:10]: I managed to solve this problem now. I had to write my solution (see below) in pseudo sql code (e.g some extra non-sql code was required) because sqlite does not support stored procedures. It think it is

[sqlite] sqlite3_reset (or sqlite3_finalize) and error reporting?

2007-04-19 Thread Jef Driesen
I have some questions on the usage of sqlite3_reset (or sqlite3_finalize) after sqlite3_step. In the legacy interface I use sqlite3_reset after sqlite3_step to obtain a more specific error code for SQLITE_ERROR (to be able to detect schema errors and automatically reprepare the statement,

[sqlite] Re: SQLite and nested transactions

2007-04-13 Thread Jef Driesen
Dennis Cote wrote: Jef Driesen wrote: I can give you the example of an application using sqlite as the on-disk file format. As mentioned on the sqlite website [1], the traditional File/Open operation does an sqlite3_open() and executes a BEGIN TRANSACTION. File/Save does a COMMIT followed

[sqlite] Re: SQLite and nested transactions

2007-04-12 Thread Jef Driesen
Dennis Cote wrote: [EMAIL PROTECTED] wrote: It appears that my requirements are to be able to do the following: BEGIN parent; insert into t values ('a'); BEGIN child; insert into t values ('b'); insert into t values ('c'); ROLLBACK child; // child aborts insert

[sqlite] Re: Some questions on hierarchical data (nested set model)

2007-04-11 Thread Jef Driesen
Jef Driesen wrote: I want to store a tree in an sqlite database. My first choice was the adjacency list model: CREATE TABLE tree ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, parent_id INTEGER ); But this method requires multiple queries to display the entire tree

[sqlite] Re: Some questions on hierarchical data (nested set model)

2007-04-10 Thread Jef Driesen
A. Pagaltzis wrote: Hi Jef, * Jef Driesen [2007-04-06 11:20]: Q1. Which is more efficient? Two simple queries or one self join? I have seen two different types of queries to retrieve a tree. The first one uses two very simple queries: SELECT lft, rgt FROM tree WHERE name = @name; SELECT

[sqlite] Re: Some questions on hierarchical data (nested set model)

2007-04-10 Thread Jef Driesen
Dennis Cote wrote: Jef Driesen wrote: I want to store a tree in an sqlite database. My first choice was the adjacency list model: CREATE TABLE tree ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, parent_id INTEGER ); But this method requires multiple queries to display the entire

[sqlite] Some questions on hierarchical data (nested set model)

2007-04-06 Thread Jef Driesen
I want to store a tree in an sqlite database. My first choice was the adjacency list model: CREATE TABLE tree ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, parent_id INTEGER ); But this method requires multiple queries to display the entire tree (or a subtree) in my GUI (a gtk+

[sqlite] Re: sqlite3_update_hook and transactions

2007-03-12 Thread Jef Driesen
Dan Kennedy wrote: On Mon, 2007-03-12 at 10:51 +0100, Jef Driesen wrote: I was planning to use the sqlite3_update_hook function to notify my GUI about changes. The idea was that every part of the GUI can update itself when a database change is detected. But during testing, I encountered some

[sqlite] sqlite3_update_hook and transactions

2007-03-12 Thread Jef Driesen
I was planning to use the sqlite3_update_hook function to notify my GUI about changes. The idea was that every part of the GUI can update itself when a database change is detected. But during testing, I encountered some problems with this approach together with transactions. When I group some

[sqlite] Re: Do I need to use sqlite3_close after a failed sqlite3_open?

2007-01-30 Thread Jef Driesen
Jef Driesen wrote: [EMAIL PROTECTED] wrote: Jef Driesen wrote: I did. sqlite3_close is called automatically for SQLITE_NOMEM, but not for other cases. So I guess sqlite3_close is still needed. But then it shouldn't return an error, or am I wrong? I don't think any error other than

[sqlite] Re: Do I need to use sqlite3_close after a failed sqlite3_open?

2007-01-30 Thread Jef Driesen
Jef Driesen wrote: Do I need to use sqlite3_close if the call to sqlite3_open indicated an error? The documentation for sqlite3_open says "An sqlite3* handle is returned in *ppDb, even if an error occurs." So I assumed the answer is yes. But if I try this code (on a non-exi

Re: [sqlite] Do I need to use sqlite3_close after a failed sqlite3_open?

2007-01-26 Thread Jef Driesen
[EMAIL PROTECTED] wrote: "Jef Driesen" <[EMAIL PROTECTED]> wrote: I did. sqlite3_close is called automatically for SQLITE_NOMEM, but not for other cases. So I guess sqlite3_close is still needed. But then it shouldn't return an error, or am I wrong? I don't think any

Re: [sqlite] Do I need to use sqlite3_close after a failed sqlite3_open?

2007-01-26 Thread Jef Driesen
Jay Sprenkle wrote: On 1/24/07, Jef Driesen <[EMAIL PROTECTED]> wrote: Do I need to use sqlite3_close if the call to sqlite3_open indicated an error? The documentation for sqlite3_open says "An sqlite3* handle is returned in *ppDb, even if an error occurs." So I assumed the ans

[sqlite] Do I need to use sqlite3_close after a failed sqlite3_open?

2007-01-24 Thread Jef Driesen
Do I need to use sqlite3_close if the call to sqlite3_open indicated an error? The documentation for sqlite3_open says "An sqlite3* handle is returned in *ppDb, even if an error occurs." So I assumed the answer is yes. But if I try this code (on a non-existing file and no write permissions):