On 17.05.2011 11:22 StyveA said the following:
>
> Hello everyone,
>
> I don't understand why when I use the sqlite3_prepare_v2() function, some
> bind_xxx, and then commit, the data stored in my database are redundant..
>
> To be more precise, when I run my code (see below), I obtain this in my
> database :
>
> 1|s|||
> 2|s|t||
> 3|s|t|y|
> 4|s|t|y|ve
>
> ====================================
> ============ Part of the code ===========
>
>    sprintf(insert_data,"INSERT INTO %s(pid, class_id, instance_id, dataset)
> VALUES(?,?,?,?)", table_name);
>    const char   *zSql = insert_data;
>
>
>    sqlite3_exec(db, "BEGIN", NULL, NULL, NULL);
>    if( sqlite3_prepare_v2(db, zSql, strlen(zSql)+1,&ppStmt, pzTail) !=
> SQLITE_OK )
>    {
>      sqlite3_close(db);
>      exit(1);
>    }
>
>      if(ppStmt)
>    {
>
>        sqlite3_bind_blob(ppStmt, 1,&pid_value, sizeof(pid_value),
> SQLITE_TRANSIENT);

>        sqlite3_step(ppStmt);
>        sqlite3_reset(ppStmt);
remove these

>        sqlite3_bind_blob(ppStmt, 2,&class_id_value, sizeof(class_id_value),
> SQLITE_TRANSIENT);

>        sqlite3_step(ppStmt);
>        sqlite3_reset(ppStmt);
remove these


>        sqlite3_bind_blob(ppStmt, 3,&instance_id_value,
> sizeof(instance_id_value), SQLITE_TRANSIENT);

>        sqlite3_step(ppStmt);
>        sqlite3_reset(ppStmt);
remove these


>        sqlite3_bind_blob(ppStmt, 4,&dataset_struct, sizeof(dataset_struct),
> SQLITE_TRANSIENT);
>        sqlite3_step(ppStmt);
>        sqlite3_finalize(ppStmt);
>        sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);
>    }
> ====================================
> ====================================
>
>
> Is there an error in the code? Or is it impossible to submit all data in one
> time without specifying the PRIMARY_ID?

You need to
prepare
bind all variables (not just one)
step
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to