Column numbering for binding starts at 0 Not 1. sqlite3_bind_blob(state,1,c1,1,SQLITE_TRANSIENT);
smlacc1 leador <[EMAIL PROTECTED]> wrote: Hi, I'm having some trouble with blobs. I have 4 blobs tht I want to insert into a db, and it works fine when I execute each insert as a single commit. However, when i try to use transactions to input blocks of 255 inserts, blob 4 gets inputted in the position of blob3, blob 3 in position of blob 2 etc etc. Very strange. I've written some code to explain what I mean. The code takes a long time to finish, so if you want to try it, compile it, then execute for a few seconds before ctrl-c'ing it to quit. It should give you enough data to see what I mean. In example 1, the fields are where they should be. In code 2, the fields all get shifted left by 1 column. But the code is identical except for where the "begin" and "commit" statements are located. Anyone know what could be the problem? Im using sqlite v3, th specific version is the one that came with fedora core 8 - 3.4.2. The code is in "c". here are 2 pieces of code - 1 using transactions, 1 without - but otherwise identical. Any help much apreciated. What I'm trying to acheive would be way too slow without transactions..... ------------------------------------ #include #include #include sqlite3* db; sqlite3_stmt *state; void execblobsql(const char* statement,int v1,int v2,int v3,int v4){ char c1[1]; c1[0] = v1; char c2[1]; c2[0] = v2; char c3[1]; c3[0] = v3; char c4[1]; c4[0] = v4; sqlite3_exec (db, "BEGIN", NULL, NULL, NULL); sqlite3_prepare(db,statement,-1,&state,NULL); sqlite3_bind_blob(state,1,c1,1,SQLITE_TRANSIENT); sqlite3_bind_blob(state,2,c2,1,SQLITE_TRANSIENT); sqlite3_bind_blob(state,3,c3,1,SQLITE_TRANSIENT); sqlite3_bind_blob(state,4,c4,1,SQLITE_TRANSIENT); sqlite3_step(state); sqlite3_finalize(state); sqlite3_exec(db, "COMMIT", NULL, NULL, NULL); } int main (){ sqlite3_open("./blobs.db", &db); if (db == 0){ printf ("database could not be opened.\n"); return 1; } char *errmsg; sqlite3_exec(db,"create table blobs (b1 BLOB, b2 BLOB, b3 BLOB, b4 BLOB)",0,0,&errmsg); char stata[] = "insert into blobs values (?1 ,?2 ,?3 ,?4)"; int looper1 = 0; int looper2 = 0; int looper3 = 0; int looper4 = 0; while (looper1 < 256){ while (looper2 < 256){ while (looper3 < 256){ /* sqlite3_exec (db, "BEGIN", NULL, NULL, NULL); sqlite3_prepare(db,stata,-1,&state,NULL);*/ while (looper4 < 256){ execblobsql(stata, looper1, looper2, looper3, looper4); looper4++; } looper3++; looper4=0; /* sqlite3_finalize(state); sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);*/ } looper2++; looper3=0; looper4=0; } looper1++; looper2=0; looper3=0; looper4=0; } } ------------------------------------ #include #include #include sqlite3* db; sqlite3_stmt *state; void execblobsql(const char* statement,int v1,int v2,int v3,int v4){ char c1[1]; c1[0] = v1; char c2[1]; c2[0] = v2; char c3[1]; c3[0] = v3; char c4[1]; c4[0] = v4; /* sqlite3_exec (db, "BEGIN", NULL, NULL, NULL); sqlite3_prepare(db,statement,-1,&state,NULL);*/ sqlite3_bind_blob(state,1,c1,1,SQLITE_TRANSIENT); sqlite3_bind_blob(state,2,c2,1,SQLITE_TRANSIENT); sqlite3_bind_blob(state,3,c3,1,SQLITE_TRANSIENT); sqlite3_bind_blob(state,4,c4,1,SQLITE_TRANSIENT); sqlite3_step(state); /* sqlite3_finalize(state); sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);*/ } int main (){ sqlite3_open("./blobs.db", &db); if (db == 0){ printf ("database could not be opened.\n"); return 1; } char *errmsg; sqlite3_exec(db,"create table blobs (b1 BLOB, b2 BLOB, b3 BLOB, b4 BLOB)",0,0,&errmsg); char stata[] = "insert into blobs values (?1 ,?2 ,?3 ,?4)"; int looper1 = 0; int looper2 = 0; int looper3 = 0; int looper4 = 0; while (looper1 < 256){ while (looper2 < 256){ while (looper3 < 256){ sqlite3_exec (db, "BEGIN", NULL, NULL, NULL); sqlite3_prepare(db,stata,-1,&state,NULL); while (looper4 < 256){ execblobsql(stata, looper1, looper2, looper3, looper4); looper4++; } looper3++; looper4=0; sqlite3_finalize(state); sqlite3_exec(db, "COMMIT", NULL, NULL, NULL); } looper2++; looper3=0; looper4=0; } looper1++; looper2=0; looper3=0; looper4=0; } } _______________________________________________ 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