[sqlite] sqlite3 .import command
In Sqlite3 the .import command replaces the old COPY. When I try to use it to import a .csv file into a table t1 in database test.db I always get the error message Error: no such table : t1; Probably I've got something wrong with the syntax of the .import command: I used >sqlite3 test.db ".import test2.csv t1"; Unfortunately the sqlite site does not provide a working example how to use the .import command correctly. The table is existent, since >sqlite3 test.db "select * from t1"; produces correct results. The file test2.csv is existent and in the same path as sqlite3.exe on a windows system. Can somebody help me? Thx Reinhold
Re: [sqlite] expression syntax
It worked out with pre-compiled statements (using sqlite3_bind_int). But I still wonder if there is a way to set integer values (dynamic values) into DB with INSERT and UPDATE? If you don't want to use prepared statements, I believe you can get the effect you are after with calls to sqlite3_mprintf and sqlite3_exec, for example: //here's our variables char * strFoo="isn't this nice?"; int nBar=123; //use sqlite's built in string formatter - note that %q helpfully does escaping for us char * strSQL=sqlite3_mprintf("insert into mytable(col1,col2) values (%d, '%q')", bBar, strFoo); //execute our sql sqlite3_exec(db, strSQL, NULL, NULL,NULL); //and remember to free up the return value from sqlite3_mprintf sqlite3_free(strSQL); If you use this technique, you'll may want to roll your own function or class method with a signature like exec(const char* fmt, ) - easy to do, just use sqlite3_vmprintf instead to pick up the argument list. Paul
Re: [sqlite] possible workaround for bug #301
On Wed, 19 Jan 2005 10:57:13 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > If you were to guarantee that there is only one reader and only one > writer-- not just one process, but a single thread and only one > sqlite3_open() against any one file-- accessing the SQLite database, > then it should work fine. I've verified that in a very very simple test, it doesn't crash :) But I agree, this is very risky business.
Re: [sqlite] possible workaround for bug #301
On Jan 19, 2005, at 10:43 AM, Will Leshner wrote: Bug #301 says that, because fcntl isn't supported for remove volumes on OS X, SQLite can't acquire a lock, which, I think, pretty much means you can't use SQLite databases that are on AFP or SMB volumes on OS X. What would happen if I simply made the calls in os.c that acquire locks NOOPs? I realize you could never expect to share a database with such a crippled version of SQLite, but if you knew that there was only going to be one reader/writer, would it work? fcntl() is supported on removable volumes on Mac OS X -- it works fine for removable media. fcntl() is not supported for AppleShare or Samba. SQLite fails gracefully in that it will report SQLITE_BUSY for any database on those volumes. If you were to guarantee that there is only one reader and only one writer-- not just one process, but a single thread and only one sqlite3_open() against any one file-- accessing the SQLite database, then it should work fine. Risky, certainly. b.bum
[sqlite] possible workaround for bug #301
Bug #301 says that, because fcntl isn't supported for remove volumes on OS X, SQLite can't acquire a lock, which, I think, pretty much means you can't use SQLite databases that are on AFP or SMB volumes on OS X. What would happen if I simply made the calls in os.c that acquire locks NOOPs? I realize you could never expect to share a database with such a crippled version of SQLite, but if you knew that there was only going to be one reader/writer, would it work? Thanks.
Re: [sqlite] expression syntax
Thanks Ulrik, It worked out with pre-compiled statements (using sqlite3_bind_int). But I still wonder if there is a way to set integer values (dynamic values) into DB with INSERT and UPDATE? NK > Hi NK, > > [EMAIL PROTECTED] wrote: > > >Hi, > >what is the correct syntax to use for WHERE expression: > > > >if (sqlite3_exec(test_db, "CREATE TABLE ana_db (item1 integer, item2 > integer, item3 integer, item4 integer, item5 integer);", NULL, 0, NULL)) > > sqlite_error(test_db); > > > >// create index > > if (sqlite3_exec(test_db, "CREATE INDEX item1idx ON ana_db (item1);", NULL, > > 0, > NULL)) > > sqlite_error(test_db); > > > > // insert values for 1000 records > > for (ii=0; ii< 1000; ii++) > > { > > if (error_code = sqlite3_exec(test_db, "INSERT INTO ana_db VALUES > ('ii', 1, 0, 1, 100);", NULL, 0, NULL)) > > { > > sqlite_error(test_db); > > return (-1); > > } > > } > > > > // update values for 1000 records > > for (ii=0; ii< 1000; ii++) > > { > > if (error_code = sqlite3_exec(test_db, "UPDATE ana_db SET > item2=item2+1 WHERE item1='ii';", NULL, 0, NULL)) > > { > > sqlite_error(test_db); > > return (-1); > > } > >} > > > >It looks like I'm not using the right syntax in UPDATE statement, I tried > >with: > WHERE item1 = $ii, w/out success. > >What am I doing wrong? > > > >Thanks, > > > >NK > > > > > > you want the sqlite3_bind_int API. Look it up on the www.sqlite.org > website. > > HTH > > Ulrik > > > > -- > Ulrik Petersen, MA, B.Sc. > University of Aalborg, Denmark > Homepage: http://ulrikp.org > >
[sqlite] MyGeneration is looking for Volunteers for our new .NET architecture
MyGeneration is a Code Generator / OR Mapper that supports SQLite (it's free). We are creating a new .NET architecture that will also support SQLite (among 10 other DBMS systems) if you are interested in becoming one of our SQLite adivsors and contributors see this site: http://www.entityspaces.net Thank you MyGeneration Software