Re: [sqlite] Sqlite and php
On 13 Dec 2009, at 5:27am, FrankLane wrote: > $data3 = preg_split('/\t/',$data2[$i]); // tab delimited record data into > array > > $sqlcmd = 'INSERT INTO tab (i0) VALUES ('.$data3[0].')'; Good so far. Now you should know that a normal SQL command to insert a record would look something like this: INSERT INTO tab(i0,i1,i2,i3,i4) VALUES (1,2,3,4,5) where the five values listed go into the five variables listed. So you need to turn the array currently in $data3 into a list of variables. One way to do it is this: $valuesSeparatedByCommas = preg_replace('/\t/', ',', $data2[$i]); $sqlcmd = 'INSERT INTO tab(i0,i1,i2,i3,i4) VALUES ('.$valuesSeparatedByComma.')'; another way to do it is this: $arrayOfValues = explode('/\t/',$data2[$i]); // tab delimited record data into array $valuesSeparatedByCommas = join(',', $arrayOfValues); $sqlcmd = 'INSERT INTO tab(i0,i1,i2,i3,i4) VALUES ('.$valuesSeparatedByComma.')'; > Looking in the php manual, there is no "query" function, but a lot of other > xxx_query functions. Is this a simple problem" I think you are best off using ->fetchAll for now. See http://php.net/manual/en/pdostatement.fetchall.php and scroll down to see some examples. This should allow you to prove that the database system is working and give you confidence to try some of the other functions. You will probably end up using either ->fetch() or ->fetchObject(). (Warning: I haven't actually tried any of the above code.) Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Sqlite and php
Well, Im getting closer. I can't seem to get the query function right. Running the following program gives: The first record is 1 0 0 0 0 BUSI @TOWB.1@ Ernest Blacksmith Shop INSERT INTO tab (i0) VALUES (1) INSERT INTO tab (i0) VALUES (1) INSERT INTO tab (i0) VALUES (1) INSERT INTO tab (i0) VALUES (1) INSERT INTO tab (i0) VALUES (2) INSERT INTO tab (i0) VALUES (2) query= php: Impossible to execute query. Looking in the php manual, there is no "query" function, but a lot of other xxx_query functions. Is this a simple problem" Thanks Frank L. = getMessage()); } $sqlCreateTable = 'create table tab(i0,i1,i2,i3,i4,t0,ID0,t1,t2,t3,t4,s,l,date,d)'; $dbHandle->exec($sqlCreateTable); $filename='/Users/me/TDD.txt'; $data1 = file_get_contents($filename); $data2 = preg_split('/\n/',$data1); // separate into records echo "\n The first record is " . $data2[0].''; $i = 0; while ($i <= 5) { $data3 = preg_split('/\t/',$data2[$i]); // tab delimited record data into array $sqlcmd = 'INSERT INTO tab (i0) VALUES ('.$data3[0].')'; echo $sqlcmd.""; $dbHandle->exec($sqlcmd); $i++; } $sqlcmd = 'select * from tab where i0=2'; // select some records $query = $dbHandle->query($sqlcmd,SQLITE_BOTH,$query_error); echo "query=".$query.""; if ($query_error)die("Error: $sqlite query_error"); if (!$query)die("php: Impossible to execute query."); ?> -- View this message in context: http://old.nabble.com/Sqlite-and-php-tp26754013p26763806.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] floor help (NO bug, sorry)
>I believe there is a bug here. Yes, in I my own head! We simply need to take care of integral values. The correct rounding down at 3rd decimal places using SQLite can be done so: case when cast(myValue as text) <> round(myValue) then round(myValue - 0.0005, 3) else myValue end ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Loading a Nested Set?
My "procedural language" is C#, so that is a can-do situation. But I would like to get a lot more out of set-based SQLite if possible. On Fri, Dec 11, 2009 at 11:55 PM, Igor Tandetnikwrote: > Sqlite Fool wrote: > > In a previous life, I was able to get the stuff into a MS SQL Server > > adjancency model table using TSQL constructs like WHILE and FOR to > iterate > > over parts of strings, use temp-holder variables, and then perform > inserts. > > From what I understand about SQLite, only CASE is available and only > > set-based (non-procedural) operations are possible. > > Well, you are using SQLite from your application, likely written in some > procedural language. Why don't you write procedural parts in that language, > running SQL statements as necessary? > > Igor Tandetnik > > > ___ > 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
Re: [sqlite] floor help (plus bug found)
[ I apologize if this appears twice on the list ] Hi, At 00:11 13/12/2009, you wrote: >Sir any ida how can value rounddown floor have done > >if not possible i have make small code >i requard make function please say how can add > >i send you my rounddown funtion > >please >Cose Exmaple : >value=10.666 >decimal=1 >Create roundd{value,decimal){ >if (decimal>0) >d=help requaird on decimal(10**) >Select Cast(value As integer)||substr((value-Cast(value As >integer))*10*d,1,decimal)*(1/d) As rounddown; >return rounddown; >} > > >i am c# devloper so i know padright please make for me complete >function for rounddown my arjent requairment >how add on SQLite please say >thanks advance I am forwarding your mail to the list as well because readers may be able to help you on the C# part, and for another good reason. If your question is about rounding values at the SQLite level at some fixed number of decimal place, here is an example using the sqlite3 program. Say we have a table created: CREATE TABLE Samples (myValue FLOAT); Now let us insert some values both positive and negative: INSERT INTO Samples VALUES(6206.460984); INSERT INTO Samples VALUES(259.026716); INSERT INTO Samples VALUES(652864.9244028); INSERT INTO Samples VALUES(5866.5317364); INSERT INTO Samples VALUES(13.4058616); INSERT INTO Samples VALUES(0.444); INSERT INTO Samples VALUES(0.); INSERT INTO Samples VALUES(1.0); INSERT INTO Samples VALUES(-6206.460984); INSERT INTO Samples VALUES(-259.026716); INSERT INTO Samples VALUES(-652864.9244028); INSERT INTO Samples VALUES(-5866.5317364); INSERT INTO Samples VALUES(-13.4058616); INSERT INTO Samples VALUES(-0.444); INSERT INTO Samples VALUES(-0.); INSERT INTO Samples VALUES(-1.0); Now execute a simple query to show you how the round() SQLite function works: select myValue, round(myValue, 3), round(myValue) from Samples; 6206.460984 6206.4616206.0 259.026716 259.027 259.0 652864.9244028 652864.924 652865.0 5866.53173645866.5325867.0 13.4058616 13.406 13.0 0.444 0.444 0.0 0. 0.889 1.0 1.0 1.0 1.0 -6206.460984-6206.461 -6206.0 -259.026716 -259.027-259.0 -652864.9244028 -652864.924 -652865.0 -5866.5317364 -5866.532 -5867.0 -13.4058616 -13.406 -13.0 -0.444 -0.444 0.0 -0. -0.889 -1.0 -1.0-1.0-1.0 You can see that SQLite round(myValue, 3) "rounds" to the 3rd decimal place and round(myValue) or round(myValue, 0) rounds down to integer (0 decimal places). But if you look more closely, you can also notice that the rounding direction is not correct for positive values with a fractional part when a non-null second parameter is given. I did not notice that point in my first reply because I only rounded to integers. I believe there is a bug here. Take for instance the first value above: 6206.460984 It is correctly rounded _down_ to the integer value 6206 it is wrongly rounded _up_ to the 3rd decimal place 6206.461 but the correct rounding down should be 6206.460 Rounding down negative values (integral or not) works well. Thus the correct rounding down at 3rd decimal places using SQLite can be done so: case when myValue > 0 and cast(myValue as text) <> round(myValue) then round(myValue - 0.00051, 3) else round(myValue, 3) end Let us see if that does what we want: select myValue, case when myValue > 0 and cast(myValue as text) <> round(myValue) then round(myValue - 0.00051, 3) else round(myValue, 3) end as "Correct rounding" from Samples; 6206.460984 6206.46 259.026716 259.026 652864.9244028 652864.924 5866.53173645866.531 13.4058616 13.405 0.444 0.444 0. 0.888 1 1.0 -6206.460984-6206.461 -259.026716 -259.027 -652864.9244028 -652864.924 -5866.5317364 -5866.532 -13.4058616 -13.406 -0.444 -0.444 -0. -0.889 -1 -1.0 The output is now correct in every case (I hope so) but it is finally much less practical than we would like! Working with floating point can bring unexpected problems. Now if you need to write a similar function to perform the same operation in C# then you should search MSDN C#. It is possible that someone here with some C# knowledge could help you. Anyway may I strongly suggest you read tutorials or books about your language and also read the SQLite tutorial. Also you would certainly benefit from reading about the virtues and the dark sides of floating-point. Finally such rounding could be better done at some point in the applicative code: it all depends on your application. I hope this helps. ___ sqlite-users mailing list sqlite-users@sqlite.org
Re: [sqlite] floor help (plus bug found)
Hi, At 00:11 13/12/2009, you wrote: >Sir any ida how can value rounddown floor have done > >if not possible i have make small code >i requard make function please say how can add > >i send you my rounddown funtion > >please >Cose Exmaple : >value=10.666 >decimal=1 >Create roundd{value,decimal){ >if (decimal>0) >d=help requaird on decimal(10**) >Select Cast(value As integer)||substr((value-Cast(value As >integer))*10*d,1,decimal)*(1/d) As rounddown; >return rounddown; >} > > >i am c# devloper so i know padright please make for me complete >function for rounddown my arjent requairment >how add on SQLite please say >thanks advance I am forwarding your mail to the list as well because readers may be able to help you on the C# part. If your question is about rounding values at the SQLite level at some fixed number of decimal place, here is an example using the sqlite3 program. Say we have a table created: CREATE TABLE Samples (myValue FLOAT); Now let us insert some values both positive and negative: INSERT INTO Samples VALUES(6206.460984); INSERT INTO Samples VALUES(259.026716); INSERT INTO Samples VALUES(652864.9244028); INSERT INTO Samples VALUES(5866.5317364); INSERT INTO Samples VALUES(13.4058616); INSERT INTO Samples VALUES(0.444); INSERT INTO Samples VALUES(0.); INSERT INTO Samples VALUES(1.0); INSERT INTO Samples VALUES(-6206.460984); INSERT INTO Samples VALUES(-259.026716); INSERT INTO Samples VALUES(-652864.9244028); INSERT INTO Samples VALUES(-5866.5317364); INSERT INTO Samples VALUES(-13.4058616); INSERT INTO Samples VALUES(-0.444); INSERT INTO Samples VALUES(-0.); INSERT INTO Samples VALUES(-1.0); Now execute a simple query to show you how the round() SQLite function works: select myValue, round(myValue, 3), round(myValue) from Samples; 6206.460984 6206.4616206.0 259.026716 259.027 259.0 652864.9244028 652864.924 652865.0 5866.53173645866.5325867.0 13.4058616 13.406 13.0 0.444 0.444 0.0 0. 0.889 1.0 1.0 1.0 1.0 -6206.460984-6206.461 -6206.0 -259.026716 -259.027-259.0 -652864.9244028 -652864.924 -652865.0 -5866.5317364 -5866.532 -5867.0 -13.4058616 -13.406 -13.0 -0.444 -0.444 0.0 -0. -0.889 -1.0 -1.0-1.0-1.0 You can see that SQLite round(myValue, 3) "rounds" to the 3rd decimal place and round(myValue) or round(myValue, 0) rounds down to integer (0 decimal places). But if you look more closely, you can also notice that the rounding direction is not correct for positive values with a fractional part when a non-null second parameter is given. I did not notice that point in my first reply because I only rounded to integers. I believe there is a bug here. Take for instance the first value above: 6206.460984 It is correctly rounded _down_ to the integer value 6206 it is wrongly rounded _up_ to the 3rd decimal place 6206.461 but the correct rounding down should be 6206.460 Rounding down negative values (integral or not) works well. Thus the correct rounding down at 3rd decimal places using SQLite can be done so: case when myValue > 0 and cast(myValue as text) <> round(myValue) then round(myValue - 0.00051, 3) else round(myValue, 3) end Let us see if that does what we want: select myValue, case when myValue > 0 and cast(myValue as text) <> round(myValue) then round(myValue - 0.00051, 3) else round(myValue, 3) end as "Correct rounding" from Samples; 6206.460984 6206.46 259.026716 259.026 652864.9244028 652864.924 5866.53173645866.531 13.4058616 13.405 0.444 0.444 0. 0.888 1 1.0 -6206.460984-6206.461 -259.026716 -259.027 -652864.9244028 -652864.924 -5866.5317364 -5866.532 -13.4058616 -13.406 -0.444 -0.444 -0. -0.889 -1 -1.0 The output is now correct in every case (I hope so) but it is finally much less practical than we would like! Working with floating point can bring unexpected problems. Now if you need to write a similar function to perform the same operation in C# then you should search MSDN C#. It is possible that someone here with some C# knowledge could help you. Anyway may I strongly suggest you read tutorials or books about your language and also read the SQLite tutorial. Also you would certainly benefit from reading about the virtues and the dark sides of floating-point. Finally such rounding could be better done at some point in the applicative code: it all depends on your application. I hope this helps. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] SQLite bug report - large databases only - 'database or disk is full'
Apologies for not answering earlier, I* was away. I've never used Process Monitor - the whole setup you describing is new to me - but I will try to do something about it in the coming week. It has to be a background project for me - I do not use SQLite in production. -Original Message- From: Filip NavaraTo: General Discussion of SQLite Database Sent: Thu, Dec 10, 2009 1:35 am Subject: Re: [sqlite] SQLite bug report - large databases only - 'database or disk is full' On Mon, Dec 7, 2009 at 10:21 PM, wrote: SQLite bug report Summary: -- error message: Error: near line 2: database or disk is full It happens with plenty of disk space available and with 'unlimited' database ize. It does not happen on all systems. It does not happen on small databases. I run your scripts with SQLite 3.6.21 on Windows 7 64-bit on NTFS rive and unfortunately I run out of disk space before the problem anifested. Would it be possible for you to setup Process Monitor with ilter on the database path (just the path, so both journal and the ain database file are in the log) and history depth set to 1 million the lowest value) and then capture the file accesses during the run f the reproduction scripts? It is possible to save and export the ata then for further analysis and hopefully it will give a clue on hy it happens. Best regards, ilip Navara __ qlite-users mailing list qlite-us...@sqlite.org ttp://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
Re: [sqlite] SQLite version 3.6.21
D. Richard Hipp wrote: > On Dec 8, 2009, at 9:51 AM, Andreas Schwab wrote: > >> "D. Richard Hipp"writes: >> >>> On Dec 7, 2009, at 8:41 PM, Andreas Schwab wrote: >>> D. Richard Hipp writes: > As always, please let us know if you encounter any difficulties > with > this or any other SQLite release. It's still crashing due to undefined behaviour. $ ./sqlite3 :memory: 'create table test(integer)' Segmentation fault >>> >>> I am unable to reproduce this behavior. The example above works fine >>> here. I also ran your command using valgrind and it reports no >>> problems. >> That's the very nature of undefined behaviour. You are violating >> the C >> aliasing rules, and the compiler has all freedom to wreck havoc of >> your >> code. QED. > > > No, you have not proven your thesis, you have merely stated a > conjecture. For proof, could you please indicate where, exactly, we > are violating C aliasing rules? And what compiler are you using that > is sensitive to these violations yet generates no warnings? I'm no expert on the C standard, but I very recently got a new toy: an ARM PDA running a version of Ubuntu for ARMs (a "Smart Q5", for the curious). I installed the available gcc compiler to test one of my programs which makes use of SQLite and got a segmentation fault, and also after I upgraded SQLite to 3.6.21. Even before I tried to analyze the problem, I remembered this message and applied the patch. It doesn't segfault anymore... So it seems I can confirm the bug and the fix. u...@smartq:~/src/sqlite/sqlite-3.6.21$ gcc -v Using built-in specs. Target: arm-linux-gnueabi Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv6 --with-tune=cortex-a8 --with-float=softfp --with-fpu=vfp --disable-werror --enable-checking=release --build=arm-linux-gnueabi --host=arm-linux-gnueabi --target=arm-linux-gnueabi Thread model: posix gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu8) It takes 26 minutes to compile the amalgamation source on this device, so it took me 52 minutes of compile time just to confirm this, so I'm not very inclined to do a full "make test", but if there is a real interest I can do it. It should probably be faster to use qemu for this, but I'm a bit green on this type of development. Best regards, ~Nuno Lucas > > D. Richard Hipp > d...@hwaci.com > > > > ___ > 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
Re: [sqlite] BUG: The sqlite3 shell does not call setlocale
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Alexey Pechnikov wrote: > This is standart for all i18n applications. The SQLite shell is not an i18n application, and this is deliberate. It is a developer tool. That is why for example it always uses a dot for a decimal point and not a comma even if that is what the locale does. The output is always the same wherever it is used. (Same thing applies for input.) > The SQLite virtualtables can > perform access to filesystem, read/write scv files and other - how they can > to > determine the current locale? That is indeed trickier. But even your example is hard. If I am sitting in Canada and get a German CSV file, which locale applies? Virtual tables are analogous to libraries and so cannot always rely on the hosting process. Additionally many processes these days have multiple libraries (and virtual tables if appropriate) so requiring things setup just for one is not helpful. For example if the process is serving web requests it may want the locale to match the user not the server, and potentially change on each request. In your particular scenario I'd add some sort of explicit parameter for the virtual table that allows specifying the locale, with perhaps an empty string/null meaning look at the environment variables or code page as a fallback. Roger -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkskIrwACgkQmOOfHg372QSS/gCeI6KPWCJzK54VFL4JN804ryiK YwMAoMJcgHqAXxbLreuxgLurT2diFjcw =Kq1K -END PGP SIGNATURE- ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] BUG: The sqlite3 shell does not call setlocale
Hello! On Saturday 12 December 2009 23:39:23 Roger Binns wrote: > > setlocale(LC_ALL, ""); > > Why? Yes I know what the call does, but what desirable effect does it have > on shell input and output? Pretty much all formatted output is done using > %s. The only float output is for timing commands. No input is done using > scanf. Except for the disabled by default iotrace, all fopens are in binary > mode. This is standart for all i18n applications. The SQLite virtualtables can perform access to filesystem, read/write scv files and other - how they can to determine the current locale? Best regards, Alexey Pechnikov. http://pechnikov.tel/ ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] BUG: The sqlite3 shell does not call setlocale
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Alexey Pechnikov wrote: > On unix the shell must do this initialisation: > > setlocale(LC_ALL, ""); Why? Yes I know what the call does, but what desirable effect does it have on shell input and output? Pretty much all formatted output is done using %s. The only float output is for timing commands. No input is done using scanf. Except for the disabled by default iotrace, all fopens are in binary mode. Roger -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAksj/3YACgkQmOOfHg372QQ6sACdHJfH6+fhNnJDyg8eMcApliQs t6MAoNlEtawQpNjM9T/9DjnWD41j6imc =MwgT -END PGP SIGNATURE- ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] The SQLite History extension
Hello! The SQLite History extension Link: http://mobigroup.ru/files/sqlite-ext/history/ The History SQLite extension may be used for table history logging. This version can store the user and host information obtained from environment variables or application-defined functions. See details here: http://geomapx.blogspot.com/2009/12/sqlite-versioning-extension.html Best regards, Alexey Pechnikov. http://pechnikov.tel/ ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] sqlite3-rdiff: master-slave replication for SQLite
Hello! sqlite3-rdiff - compute and apply signature-based row differences for SQLite3 databases Link: http://mobigroup.ru/files/sqlite-ext/sqlite3-rdiff Depends: tcl 8.5, sqlite3, murmurhash SQLite extension Are used the ROWID value as unique key of row and murmurhash for build signatures for each row. SYNOPSYS sqlite3-rdiff [options] signature old-file signature-file sqlite3-rdiff [options] delta signature-file new-file delta-file sqlite3-rdiff [options] patch old-file delta-file result-file See details here: http://geomapx.blogspot.com/2009/12/sqlite3-rdiff-master-slave-replication.html Best regards, Alexey Pechnikov. http://pechnikov.tel/ ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] BUG: The sqlite3 shell does not call setlocale
Hello! On unix the shell must do this initialisation: setlocale(LC_ALL, ""); Best regards, Alexey Pechnikov. http://pechnikov.tel/ ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users