Hi Daniele,

Daniele Nicolucci (Jollino) wrote:

Il giorno 22 gen 2005, alle 18:16, Ulrik Petersen ha scritto:

As you can see, sqlite3_bind_text is used for all columns. You would have to write some ad-hoc code inside the loop that checked whether the value in azCol[i] was "null" or "NULL", and then used sqlite3_bind_null if that was the case, instead of sqlite3_bind_text.


Ok, I guess I'll have to live without having an auto-increment field or find a way to fill it in the csv file with explicit values... my C skills are almost null so I don't even attempt to do that.
Or I could write a simple script to generate INSERTs from csv files and keep the field. I'll play with it.

The attached patch will do for you want you want. Apply it to the 3.0.8 sources like this:


$ cd sqlite3
$ patch -p1 < /path/to/patch/patch.txt

then recompile. I've tested this against your example table and your example data, and it works for me, i.e., the nulls get translated into sqlite3_bind_null calls, so that the autoincrement works as expected.

HTH

Ulrik P.

--
Ulrik Petersen, MA, B.Sc.
University of Aalborg, Denmark



Only in sqlite-3.0.8-nullimport/: config.h
Only in sqlite-3.0.8-nullimport/: config.log
Only in sqlite-3.0.8-nullimport/: config.status
Only in sqlite-3.0.8: doc
Only in sqlite-3.0.8-nullimport/: libtool
Only in sqlite-3.0.8-nullimport/: Makefile
Only in sqlite-3.0.8-nullimport/: sqlite3.pc
diff -cr sqlite-3.0.8/src/shell.c sqlite-3.0.8-nullimport/src/shell.c
*** sqlite-3.0.8/src/shell.c    2004-10-08 15:03:07.000000000 +0200
--- sqlite-3.0.8-nullimport/src/shell.c 2005-01-22 18:31:11.000000000 +0100
***************
*** 1091,1097 ****
          break;
        }
        for(i=0; i<nCol; i++){
!         sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
        }
        sqlite3_step(pStmt);
        rc = sqlite3_reset(pStmt);
--- 1091,1102 ----
          break;
        }
        for(i=0; i<nCol; i++){
!       if (strcmp(azCol[i], "NULL") == 0
!           || strcmp(azCol[i], "null") == 0) {
!         sqlite3_bind_null(pStmt, i+1);
!       } else {
!         sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
!       }
        }
        sqlite3_step(pStmt);
        rc = sqlite3_reset(pStmt);
Only in sqlite-3.0.8-nullimport/src: shell.c~

Reply via email to