chandan wrote:
> I am really sorry, The correct code is given below:
>
> /********************************************************************************/
> #include <stdio.h>
> #include <stdlib.h>
> #include <stdint.h>
> #include <string.h>
> #include <sqlite3.h>
>
> const char *create_and_insert = "create table some_tbl (id int primary
> key, version text check (version in (\"1.0\")));"
> "insert into some_tbl (id) values (1);";
> const char *update_sql = "update some_tbl set version = ? where id = ?";
>
> int32_t main(int32_t argc, char *argv[])
> {
> sqlite3 *db;
> char *err_msg;
> sqlite3_stmt *stmt;
> int32_t ret;
>
> if (argc != 2) {
> fprintf(stderr, "Usage: %s <database name>.\n", argv[0]);
> goto out1;
> }
>
> db = NULL;
> ret = sqlite3_open(argv[1], &db);
> if (ret != SQLITE_OK) {
> fprintf(stderr, "Unable to open database.\n");
> goto out1;
> }
>
> err_msg = NULL;
> ret = sqlite3_exec(db, create_and_insert, NULL, NULL, &err_msg);
> if (ret != SQLITE_OK) {
> fprintf(stderr, "sqlite3_exec: %s.\n", err_msg);
> sqlite3_free(err_msg);
> }
>
> stmt = NULL;
> ret = sqlite3_prepare_v2(db, update_sql, strlen(update_sql) + 1,
> &stmt, NULL);
> if (ret != SQLITE_OK) {
> fprintf(stderr, "sqlite3_stmt: %s", sqlite3_errmsg(db));
> goto out2;
> }
>
> /* The second argument indicates the posistion of the column */
> ret = sqlite3_bind_text(stmt, 1, "1.0", strlen("1.0") + 1,
> SQLITE_TRANSIENT);
> if (ret != SQLITE_OK) {
> fprintf(stderr, "sqlite3_bind_text: %s",
> sqlite3_errmsg(db));
> goto out3;
> }
>
> ret = sqlite3_bind_int(stmt, 2, 0);
> if (ret != SQLITE_OK) {
> fprintf(stderr, "sqlite3_bind_int: %s",
> sqlite3_errmsg(db));
> goto out3;
> }
>
> ret = sqlite3_step(stmt);
> if (ret != SQLITE_DONE) {
> fprintf(stderr, "sqlite3_step: %s",
> sqlite3_errmsg(db));
> goto out3;
> }
>
> ret = sqlite3_finalize(stmt);
> if (ret != SQLITE_OK) {
> fprintf(stderr, "sqlite3_finalize: %s",
> sqlite3_errmsg(db));
> }
>
> ret = sqlite3_close(db);
> if (ret != SQLITE_OK) {
> fprintf(stderr, "Unable to close the database.\n");
> }
>
> exit(0);
>
> out3:
> ret = sqlite3_finalize(stmt);
> if (ret != SQLITE_OK) {
> fprintf(stderr, "sqlite3_finalize: %s",
> sqlite3_errmsg(db));
> }
> out2:
> ret = sqlite3_close(db);
> out1:
> exit(1);
> }
> /*********************************************************************************/
>
> Simon Slavin wrote:
>
>> On 27 Jun 2009, at 8:47am, chandan wrote:
>>
>>
>>
>>> const char *create_and_insert = "create table some_tbl (id int primary
>>> key, version text check (version in (\"1.0\")));"
>>> "insert into some_tbl (id) values (1);";
>>> const char *update_sql = "update some_tbl set version = ? where id
>>> = ?";
>>>
>>>
>> I note you then do
>>
>> ret = sqlite3_bind_int(stmt, 2, 0);
>>
>> doesn't this look for id=2 ?
>>
The value "2" indicates the position of the ? in the SQL statement.
Since the value of id is 0(zero), i am binding the value 0 to the second ?.
>>
>>
>>
>> To diagnose your problem, first try the whole thing as text: execute
>> the command
>>
>> update some_tbl set version = '1.0' where id = 1
>>
When i execute the above the query using sqlite3_exec() the database is
updated correctly without any issues.
>> and see if it works. If it doesn't, try it in sqlite3 command-line
>> tool and see if that works.
>>
>> Simon.
>> _______________________________________________
>> sqlite-users mailing list
>> [email protected]
>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>>
>>
>>
>
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
>
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users