The code snippet is shown 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;
    }

    ret = sqlite3_bind_text(stmt, 1, "1.1", strlen("1.1") + 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);
}
/********************************************************************************************/


Roger Binns wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> chandan wrote:
>   
>>    I have attached the C program along this mail.
>>     
>
> This mailing list strips all attachments, so we can't see your code :-)
>
>   
>> Am i doing anything wrong in the program?
>>     
>
> Yes.  SQLite does fundamentally work.  We'd have noticed by now if a
> simple update didn't work :-)
>
> You should look over the programming documentation on the web site
> including sample programs again.
>
> Roger
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkpF0O4ACgkQmOOfHg372QQlrQCffy0JJqpxSaDR8pg9B903eofi
> DYYAnR/gOPJLgpdC1c0CLwa0rA7IOJG0
> =MP0E
> -----END PGP SIGNATURE-----
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
>   

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to