SQLite Forum

sqlite3_bind_parameter_count question
Login

sqlite3_bind_parameter_count question

(1) By anonymous on 2021-11-24 10:42:53 [link] [source]

Hello. I've encountered inconsistent behaviour with SQLite and wanted to get some clarification here.

Basically, sqlite3_bind_parameter_count returns incorrect count for an SQL with multiple statements(separated by semicolon)

Example:

CREATE TABLE IF NOT EXISTS test(id);
INSERT INTO test VALUES(?);
INSERT INTO test VALUES(?);

Calling sqlite3_prepare_v2 and then sqlite3_bind_parameter_count yields 0 parameter count, while it should be 2.

Is this intended behaviour? If so, how do I get the actual parameter count?

(2) By Stephan Beal (stephan) on 2021-11-24 11:09:07 in reply to 1 [link] [source]

Is this intended behaviour?

Reread the docs for the prepare APIs. They only prepare single statements. Any statement after the first one is ignored.

(4) By ddevienne on 2021-11-24 12:29:53 in reply to 2 [link] [source]

More precisely, look at the last out param of sqlite3_prepare_v2(..., pzTail),
which tells you where SQLite stopped when preparing the 1st statement of your SQL script.
Which allows you to prepare the next statement in your script, and so on...

(5) By anonymous on 2021-11-24 16:16:57 in reply to 4 [link] [source]

Thanks for replies. Should've read the docs more carefully.

(3) By Gunter Hick (gunter_hick) on 2021-11-24 11:36:14 in reply to 1 [source]

Prepare each statement separately.