Hello,

I am a new SQLite user. I look at the documentation and there are a couple of things which are not clear to me and I could not find info in documentation or google. I could probably write some code to test and find answers to the following questions but it actually might be better to ask them here so hopefully they will be answered and serve as a reference for people with similar questions and maybe find their way into documentation.

1. sqlite3_prepare(
                sqlite3 *db,
                const char *zSql,
                int nBytes,
                sqlite3_stmt **ppStmt,
                const char **pzTail);

A. what happens to the zSql? Is it copied or it is assumed that this is a static text? Suppose I call sqlite3_prepare in one place and immediately release dynamically allocated text. sqlite3_prepare parses only the first statement. Then I call sqlite3_step as many times as needed. Will it crash when trying to parse next statements in next steps?

B. Is pzTail of any use? I can see that inside the library code it is checked against NULL before assigning the output text pointer but the documentation does not state explicitly that this parameter is optional. I don't want to rely on internal implementation (which may change in future release) when the docs don't say it is optional. It would be nice to clarify this.

2. int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
In case of text in a column, is it supposed to return the byte count of text only or the byte count of text plus the terminating 0 byte (2 bytes if unicode)?


3. const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
I assume that text returned from the above functions are 0-terminated. It is not stated explicitly in documentation. Should I use value returned from sqlite3_column_bytes()/sqlite3_column_bytes16 or use strlen()/16 bit unicode equivalent?


4. Can I use sqlite3_column_xxx family of functions when sqlite3_step() returns SQLITE_DONE or SQLITE_OK? I assume it can be done only after SQLITE_ROW is returned. It would be good to clarify this. When SQLITE_DONE is returned? Suppose I run a query searching for some column value in DB. SQLite finds a matching row and returns SQLITE_ROW. Then I check for more using sqlite3_step() and suppose there are no more results. Will it return SQLITE_DONE and still point to previous row? Next, suppose there is one more result and it finds the last matching row (different from previous) will it return SQLITE_ROW or will it return SQLITE_DONE meaning: "one more row found and I am sure it is the last you can get"?

Thanks,
Tom
Abracode
http://www.abracode.com/



Reply via email to