Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Andres Riancho
Roger,

On Mon, Sep 8, 2014 at 12:26 AM, Roger Binns rog...@rogerbinns.com wrote:
 On 07/09/14 19:11, Andres Riancho wrote:
 * I'm setting [4] PRAGMA synchronous=OFF for increased
 performance. Can this trigger malformed errors?

 Read the doc:

   https://sqlite.org/pragma.html#pragma_synchronous

 TLDR: yes

 To improve write performance use WAL:

   https://sqlite.org/wal.html

 Realise that SQLite can only be safe if at various points the data it wants
 on the storage is actually completely written out and unaffected by power
 failures etc.  You can go a lot faster by not doing that, but then the data
 isn't safe.

Well, I should have explained my use case a little bit more.

In my project we use the database to store data during the process
life, and then remove it when the process finishes. This will never be
done by w3af:
 * Process #1: Store something in sqlite
 * Shutdown
 * Process #3: Read data from sqlite

The flow always looks like:
 * Process #1: Store something in sqlite
 * Process #1: Read data from sqlite
 ...
 * Process #1: Store something in sqlite
 * Process #1: Read data from sqlite
 * Process #1; Close DB and remove file

I got this into account when I decided to go with sync=OFF. For me if
I have a power failure, it doesn't matter much, since Process #1
will die, and there is no way for a new process of w3af to read the DB
(broken or not).

With this in mind, sync=OFF still looks like something that could
cause database malformed errors?

 Roger
 ___
 sqlite-users mailing list
 sqlite-users@sqlite.org
 http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



-- 
Andrés Riancho
Project Leader at w3af - http://w3af.org/
Web Application Attack and Audit Framework
Twitter: @w3af
GPG: 0x93C344F3
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Andres Riancho
Simon,

On Sun, Sep 7, 2014 at 11:39 PM, Simon Slavin slav...@bigfraud.org wrote:

 On 8 Sep 2014, at 3:11am, Andres Riancho andres.rian...@gmail.com wrote:

I'm using sqlite as the database backend for an open source
 project and it works perfectly 99% of the time; however some users
 have reported database disk image is malformed errors [1][2].

 There are two possibilities:

 A) The database really is malformed
 B) The client's copy of SQLite is returning that code by mistake.

 Can you have one of these clients send you a copy of their database after 
 they have received this message ?  Then you can try and open it yourself and 
 see whether it really is malformed.

Let's say that it is possible for me to do that (ask users to submit
their DBs and actually get one), I receive it and then:
 1- Open - Get database malformed error
 2- Open - Can read the database

In any of the cases, I can't imagine what to do next.

 All the incidents like this I can remember have been the result of bad memory 
 management or using stale pointers.  It's likely that you will eventually 
 find that some other process is overwriting SQLite's memory or writing to the 
 database file.

Oh, so you believe that maybe if the database is really malformed I'll
find garbage that shouldn't be there using a hex editor, and by
understanding what that garbage is (lets say log messages that should
go to stderr) I can fix the issue on my software? That would be an
outcome of #2 above?

  But it's possible you've found a genuine bug in SQLite and we'll try to help.

Well, this should be really unlikely, right?

 Simon
 ___
 sqlite-users mailing list
 sqlite-users@sqlite.org
 http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



-- 
Andrés Riancho
Project Leader at w3af - http://w3af.org/
Web Application Attack and Audit Framework
Twitter: @w3af
GPG: 0x93C344F3
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Andres Riancho
Off-list some guys contacted me and mentioned APSW [0], another
wrapper around sqlite for python, and said that it might be worth
giving it a try. Do you guys believe that a change in wrapper could
improve my situation? Thanks!

[0] https://github.com/rogerbinns/apsw

On Sun, Sep 7, 2014 at 11:11 PM, Andres Riancho
andres.rian...@gmail.com wrote:
 List,

 I'm using sqlite as the database backend for an open source
 project and it works perfectly 99% of the time; however some users
 have reported database disk image is malformed errors [1][2].

 At the moment the w3af project has a really clean wrapper around
 sqlite [3] which allows many threads to talk with the sqlite database
 by:
 * Making sure only one SQLiteExecutor thread has an open
 connection to the DB
 * All the client threads queue the queries and the thread with
 the connection runs them

 The DB stores a considerable amount of rows, in a short period of
 time, but I don't believe that's an issue.

 I've read through the how to corrupt document [0] and nothing
 seemed to match with what I'm doing. So, my questions are:

 * Do you see anything wrong with my wrapper? [3]
 * Is it possible to debug database disk image is malformed
 (at the python level, maybe an attribute of the exception?) to better
 understand what is causing the issues?
 * I'm setting [4] PRAGMA synchronous=OFF for increased
 performance. Can this trigger malformed errors?

 Not a sqlite expert... am I missing something big?

 [0] https://www.sqlite.org/howtocorrupt.html
 [1] 
 https://github.com/andresriancho/w3af/search?q=database+disk+image+is+malformedtype=Issuesutf8=%E2%9C%93
 [2] https://github.com/andresriancho/w3af/issues/4905
 [3] 
 https://github.com/andresriancho/w3af/blob/master/w3af/core/data/db/dbms.py
 [4] 
 https://github.com/andresriancho/w3af/blob/master/w3af/core/data/db/dbms.py#L293

 Regards,
 --
 Andrés Riancho
 Project Leader at w3af - http://w3af.org/
 Web Application Attack and Audit Framework
 Twitter: @w3af
 GPG: 0x93C344F3



-- 
Andrés Riancho
Project Leader at w3af - http://w3af.org/
Web Application Attack and Audit Framework
Twitter: @w3af
GPG: 0x93C344F3
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQLite and Windows 95

2014-09-08 Thread BlackWingCat
Hi.

http://blog.livedoor.jp/blackwingcat/archives/1813730.html
I compiled SQLite 3.7.17 and 3.8.0.2 for Windows 95 before.

If you want to know the reason why it would not work on Win95, see the
following article.
http://blog.livedoor.jp/blackwingcat/archives/1804729.html




--
View this message in context: 
http://sqlite.1065341.n5.nabble.com/SQLite-and-Windows-95-tp5271p77748.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


[sqlite] Whats the SQLite Encryption Algo?

2014-09-08 Thread Tom Ashley
I noticed that in C# I can set a password using SetPassword. Does this
encrypt the entire database? If so, What algorithm precisely does it use?

Thanks
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] System.Data.SQLite - issues

2014-09-08 Thread Chris Abbott
 manish.kukreti@... writes:

 
 Hi,
 Below are the two issues I would like to report for SQLite .Net client.
 1. SQLiteDataReader.GetString() method:
 The method fails with Invalid cast exception when you try to retrieve a 
number stored in a text field.
 
 2. SQLiteDataReader.GetValue performance in version 1.0.93:
 This method is considerably slower in this version. While benchmarking, the 
fetch was about 7-8 times
 slower. First I thought it was the NGQP (since I upgraded from version 3.7 
to 3.8.5), but while trying to
 break it down, it appeared the issue was with this fetch method.
 
 Thanks,
 Manish Kukreti 
 

Platform: VS2010, .NET 4 target platform.

I've also noticed a drastic degradation in speed with this release over 
1.0.86. We have a mobile device detection system which runs detections mostly 
from cache, but also from an SQLite memory instance. A single-thread batch job 
over 100,000 user-agents goes from average 130 seconds to over 250 with this 
update, which is a horrific decrease in speed. It's a bad enough effect to 
necessitate a downgrade.

Chris

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Whats the SQLite Encryption Algo?

2014-09-08 Thread Simon Slavin

On 8 Sep 2014, at 9:16am, Tom Ashley tomashley...@gmail.com wrote:

 I noticed that in C# I can set a password using SetPassword. Does this
 encrypt the entire database? If so, What algorithm precisely does it use?

See this

http://www.hwaci.com/sw/sqlite/see.html

and get back to us if you have questions.  The basic answer is that you have to 
pay extra to be able to encrypt your databases.  But if anyone has encrypted 
their database you don't have to pay extra for the bit that does decryption.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Richard Hipp
See the essay at:

   http://www.sqlite.org/affcase1.html

Comments, criticism, and feedback are welcomed.
-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Does the Connection string support UNC paths?

2014-09-08 Thread jose isaias cabrera


a...@zator.com wrote...





 Mensaje original 
De: Chris developm...@thegifnet.com
Para:  sqlite-users@sqlite.org
Fecha:  Sat, 6 Sep 2014 23:46:19 -0500
Asunto:  [sqlite] Does the Connection string support UNC paths?



I am old database programmer that just came across SQLite and am working 
on

a small project for a PVR that uses SQLite as it's db provider.  I try
specifying a UNC path to the database for the datasource in the connection
string and I get the following error, unable to open database file.   .
When I look at the exception generated, I see an errorcode = 14.  However,
if I map a network drive, I can open the file and work with it.  I am
running Windows 7 x64 Pro and system.data.sqlite version 1.0.93.0 with dot
net framework 4.0 and Visual Studio 2010.



Obviously SQLite supports UNC paths because I am using SQLite database
browser to open the same database using a UNC path.



Also, a full pathname, can start with a double backslash (\\), indicating 
the global root, followed by a server name and a share name to indicate 
the path to a network file server.


Just a little suggestion: UNC paths are slower than connecting that same 
path to a drive.  If you are going to use it a lot, I suggest for you to 
connect that path to a drive and it will be much faster.  We have a system 
using SQLite with a SharedDB and connecting that path to a drive is much 
faster.  Ihth.


josé 


___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Simon Slavin

On 8 Sep 2014, at 11:47am, Andres Riancho andres.rian...@gmail.com wrote:

 On Sun, Sep 7, 2014 at 11:39 PM, Simon Slavin slav...@bigfraud.org wrote:
 
 There are two possibilities:
 
 A) The database really is malformed
 B) The client's copy of SQLite is returning that code by mistake.
 
 Can you have one of these clients send you a copy of their database after 
 they have received this message ?  Then you can try and open it yourself and 
 see whether it really is malformed.
 
 Let's say that it is possible for me to do that (ask users to submit
 their DBs and actually get one), I receive it and then:
 1- Open - Get database malformed error
 2- Open - Can read the database
 
 In any of the cases, I can't imagine what to do next.

For diagnostic purposes mainly.  Just see whether you get (1) or (2).  If you 
get (2) then you know your fault is messing up your program's memory rather 
than writing gibberish over the database file.  It just tells you part of your 
code to check more carefully.

 All the incidents like this I can remember have been the result of bad 
 memory management or using stale pointers.  It's likely that you will 
 eventually find that some other process is overwriting SQLite's memory or 
 writing to the database file.
 
 Oh, so you believe that maybe if the database is really malformed I'll
 find garbage that shouldn't be there using a hex editor, and by
 understanding what that garbage is (lets say log messages that should
 go to stderr) I can fix the issue on my software? That would be an
 outcome of #2 above?

An outcome of #1.  Exactly.  Sometimes the thing you find written over your 
database file tells you what went wrong.  For instance, years ago I once found 
a configuration file corrupted with text including the string Account slavin 
logged off..  Since that string didn't get created before a certain point in 
my program it told me which part of the program was messing up its memory 
handling.  It turned out that I was referring to a pass-by-reference variable 
as if it was pass-by-value.

 But it's possible you've found a genuine bug in SQLite and we'll try to help.
 
 Well, this should be really unlikely, right?

We hope so.  It's tempting to write things like SQLite has billions of happy 
installations there are no bugs in it you idiot. but a few obscure bugs are 
found every year.  Nevertheless they tend to be bugs that require an odd or 
unlikely combination of things to trigger them rather than basic file handling 
faults.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread John McKown
On Mon, Sep 8, 2014 at 7:35 AM, Richard Hipp d...@sqlite.org wrote:
 See the essay at:

http://www.sqlite.org/affcase1.html

 Comments, criticism, and feedback are welcomed.
 --
 D. Richard Hipp
 d...@sqlite.org

A very good presentation of an good idea. Although I am not a
developer or historian of ODP, it is basically an offshoot of
OpenOffice. Which may explain why the output is in zip format.
Open/Libre Office is Java based. And Java has always had zip file
processing integrated into its standard library. I guess that the
developers wanted to just use what was universally available, and not
depend on other 3rd party libraries, such as SQLite.

The above does not mean that I think it should not be considered, but
it does mean that, to an extent, Open/Libre Office would be bound to
SQLite as well as Java. Which the developers may not want to do. I do
hope that they would consider it. Of course, this would either mean
dual path in the code for zip ODP files vs. SQLite ODP files or a
complete break with compatibility with the old file structure. Which
may be too Microsoft-ish for them.


-- 
There is nothing more pleasant than traveling and meeting new people!
Genghis Khan

Maranatha! 
John McKown
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Teg
Hello Richard,

Monday, September 8, 2014, 8:35:30 AM, you wrote:

RH See the essay at:

RHhttp://www.sqlite.org/affcase1.html

RH Comments, criticism, and feedback are welcomed.

I  use  Sqlite  as  a  container  for  images because it's superior to
CBR/CBZ  files (which are rar and zip files).  I think this is a great
idea.


Finally, let us reiterate that this essay is a thought experiment. The
OpenDocument format is well-established and already well-designed.
Nobody really believes that OpenDocument should be changed to use
SQLite as its container instead of ZIP. Nor is this article a
criticism of OpenDocument for not choosing SQLite as its container
since OpenDocument predates SQLite. Rather, the point of this article
is to use OpenDocument as a concrete example of how SQLite can be used
to build better application file formats for future projects.

It  might  be too late in the game but, I would have preferred this to
zips for sure. 


Teg mailto:t...@djii.com

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Query help

2014-09-08 Thread Clemens Ladisch
Joseph L. Casale wrote:
  SELECT x.id, x.col
   FROM table_a x
 EXCEPT
 SELECT y.id, y.col
   FROM table_b y
 JOIN table_a .

This query is not complete, but as far as I can tell, it is intended to
return table_a rows that do not have a matching table_b row.  Is this
correct?

 now I need to return row ids for each record on the left and these
 certainly don't match the row ids from the right hand side.

There are two ways to rewrite this query, with a correlated subquery:

 SELECT *
 FROM table_a AS x
 WHERE NOT EXISTS (SELECT 1
   FROM table_b AS y
   WHERE x.id  = y.id
 AND x.col = y.col)

or with an outer join:

 SELECT x.*
 FROM  table_a AS x
 LEFT JOIN table_b AS y USING (id, col)
 WHERE y.id IS NULL


Regards,
Clemens
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Request to change int parameter to size_t parameter / potential bug on iOS (64 bit)

2014-09-08 Thread Nelson, Erik - 2
 Roger Binns wrote on Sunday, September 07, 2014 2:30 PM
 On 07/09/14 11:19, Richard Hipp wrote:
  Please use a cast to silence the compiler warnings.
 (int)sizeof(...)
  instead of just sizeof(...).
 
 That isn't safe for correctly written 64 bit apps.  For example they
 could end up with data items that are bigger than 2GB correctly using
 (s)size_t.
 The silencing cast above would then truncate it to a negative 32 bit
 number or truncated 31 bit number, which has differing meanings in the
 SQLite 3 APIs, and certainly never matches the callers intention.
 
 The only safe thing for a correctly written 64 bit app to do is ensure
 that all size values are less than 2GB, and then the warning can be
 silenced in a cast.
 

If the Boost C++ libraries are available, there's a numeric_cast that does 
casting and checks for overflow in the process.

It's not worth adding all of Boost for just this little bit, but if you have it 
around, may be worth taking a look.

--
This message, and any attachments, is for the intended recipient(s) only, may 
contain information that is privileged, confidential and/or proprietary and 
subject to important terms and conditions available at 
http://www.bankofamerica.com/emaildisclaimer.   If you are not the intended 
recipient, please delete this message.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Query help

2014-09-08 Thread Joseph L. Casale
 There are two ways to rewrite this query, with a correlated subquery:
 
  SELECT *
  FROM table_a AS x
  WHERE NOT EXISTS (SELECT 1
FROM table_b AS y
WHERE x.id  = y.id
  AND x.col = y.col)
 
 or with an outer join:
 
  SELECT x.*
  FROM  table_a AS x
  LEFT JOIN table_b AS y USING (id, col)
  WHERE y.id IS NULL

Hi Clemens,
Totally missed the boat on those two.

Much appreciated,
jlc
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] A weird issue in android c++ app that uses sqlite3

2014-09-08 Thread Sunny Shankar
Hi Everyone

We have been working on an android app which uses cocos2dx. We use sqlite3
for storing data locally on the device.
We use c++ code to connect and use the database. Recently we used
transactions, it runs fine on iOS platform
(cocos2dx apps are cross platform) but it fails on android.

This is weird because only update queries in the transaction fail and that
too if you run multiple updates in a loop.
Every other query (insert, delete, select) runs fine in loop. We are not
using multiple threads, so whatever runs, runs
on the main thread neither we are opening multiple connections to the
database. The same code works if you turn off
the transaction. We don't want to give up transactions. One solution is to
use insert or replace query instead of update
which is insert or insert-delete but I am not sure what will happen if the
table is having foreign key relationship. We can
drop the foreign key constraint if we assume the data is proper.

For each query we prepare a statement, step through it and then finalize it
so every statement is finalized even if the query
fails. For pragma setting and begin and end transaction we are using
sqlite_exec which wraps the above process.

Here is a test log:-

09-03 19:36:35.175: D/cocos2d-x debug info(30445): PRAGMA foreign_keys=ON
09-03 19:36:35.175: D/cocos2d-x debug info(30445): begin transaction
09-03 19:36:35.180: D/cocos2d-x debug info(30445): select Test_ID, ID_Type
from TestTable
09-03 19:36:35.185: D/cocos2d-x debug info(30445): enter loop
09-03 19:36:35.185: D/cocos2d-x debug info(30445): update TestTable set
ID_Type = 2 where Test_ID = 133
09-03 19:36:35.185: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.185: D/cocos2d-x debug info(30445): insert into
TestTable(Test_ID) values(1)
09-03 19:36:35.185: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.185: D/cocos2d-x debug info(30445): delete from TestTable
where Test_ID = 1
09-03 19:36:35.185: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.190: D/cocos2d-x debug info(30445): select Test_ID, ID_Type
from TestTable
09-03 19:36:35.190: D/cocos2d-x debug info(30445): update TestTable set
ID_Type = 2 where Test_ID = 135
09-03 19:36:35.195: D/cocos2d-x debug info(30445): Error 14 update
TestTable set ID_Type = 2 where Test_ID = 135
09-03 19:36:35.195: D/cocos2d-x debug info(30445): insert into
TestTable(Test_ID) values(1)
09-03 19:36:35.195: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.195: D/cocos2d-x debug info(30445): delete from TestTable
where Test_ID = 1
09-03 19:36:35.195: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.195: D/cocos2d-x debug info(30445): select Test_ID, ID_Type
from TestTable
09-03 19:36:35.195: D/cocos2d-x debug info(30445): update TestTable set
ID_Type = 1 where Test_ID = 140
09-03 19:36:35.195: D/cocos2d-x debug info(30445): Error 14 update
TestTable set ID_Type = 1 where Test_ID = 140
09-03 19:36:35.200: D/cocos2d-x debug info(30445): insert into
TestTable(Test_ID) values(1)
09-03 19:36:35.200: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.200: D/cocos2d-x debug info(30445): delete from TestTable
where Test_ID = 1
09-03 19:36:35.200: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.200: D/cocos2d-x debug info(30445): select Test_ID, ID_Type
from TestTable
09-03 19:36:35.200: D/cocos2d-x debug info(30445): update TestTable set
ID_Type = 1 where Test_ID = 141
09-03 19:36:35.200: D/cocos2d-x debug info(30445): Error 14 update
TestTable set ID_Type = 1 where Test_ID = 141
09-03 19:36:35.205: D/cocos2d-x debug info(30445): insert into
TestTable(Test_ID) values(1)
09-03 19:36:35.205: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.205: D/cocos2d-x debug info(30445): delete from TestTable
where Test_ID = 1
09-03 19:36:35.205: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.205: D/cocos2d-x debug info(30445): select Test_ID, ID_Type
from TestTable
09-03 19:36:35.205: D/cocos2d-x debug info(30445): update TestTable set
ID_Type = 1 where Test_ID = 142
09-03 19:36:35.205: D/cocos2d-x debug info(30445): Error 14 update
TestTable set ID_Type = 1 where Test_ID = 142
09-03 19:36:35.215: D/cocos2d-x debug info(30445): insert into
TestTable(Test_ID) values(1)
09-03 19:36:35.215: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.215: D/cocos2d-x debug info(30445): delete from TestTable
where Test_ID = 1
09-03 19:36:35.215: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.215: D/cocos2d-x debug info(30445): select Test_ID, ID_Type
from TestTable
09-03 19:36:35.215: D/cocos2d-x debug info(30445): update TestTable set
ID_Type = 0 where Test_ID = 144
09-03 19:36:35.215: D/cocos2d-x debug info(30445): Error 14 update
TestTable set ID_Type = 0 where Test_ID = 144
09-03 19:36:35.220: D/cocos2d-x debug info(30445): insert into
TestTable(Test_ID) values(1)
09-03 19:36:35.220: D/cocos2d-x debug info(30445): Executed
09-03 19:36:35.220: D/cocos2d-x debug info(30445): delete from TestTable
where Test_ID = 1
09-03 19:36:35.220: 

Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Simon Slavin

On 8 Sep 2014, at 1:35pm, Richard Hipp d...@sqlite.org wrote:

 See the essay at:
 
   http://www.sqlite.org/affcase1.html

You would need to provide some short and simple 'viewer' code which can be used 
to extract a 'Quick View' or 'Thumbnail' file from the database, so the GUI 
Shell can show it to the user when they're browsing files.  Generally speaking 
you never modify just a single file in such a document because you need to 
modify the thumbnail file when any change is made to the content.

Given that SQLite code is public anyway, and this would need no writing and no 
locking, it wouldn't be hard, but it would need to be done.

Also I doubt your compression figures are accurate for big files.  A typical 
.docx document on my computer is 32K long but expands to 87K unzipped plus 576K 
for the 'Quick View' file.  But I don't have to time to look into this in 
detail.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Roger Binns
On 08/09/14 03:29, Andres Riancho wrote:
 In my project we use the database to store data during the process
 life, and then remove it when the process finishes.

It sounds like what you could use temporary tables and let SQLite do the
work for you.

 With this in mind, sync=OFF still looks like something that could
 cause database malformed errors?

The problem with synchronous off is that all your code has to be perfect,
not to mention the operating system and hardware.  While you might be
reasonably convinced right now that interactions between all the parts of
code and database are safe, all it takes is some changes in the future to
invalidate that.

I strongly recommend not playing with fire.

Roger

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Simon Slavin

On 8 Sep 2014, at 6:27pm, Roger Binns rog...@rogerbinns.com wrote:

 The problem with synchronous off is that all your code has to be perfect,

Hmmm.  How about this.  Stop turning synchronous off for a month or two and see 
if people stop reporting the fault.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] System.Data.SQLite - issues

2014-09-08 Thread Joe Mistachkin

Chris Abbott wrote:
 
 I've also noticed a drastic degradation in speed with this release over 
 1.0.86. 


This issue should be fixed in 1.0.94.0.  Please try with the pre-release
bits available at:


https://system.data.sqlite.org/index.html/doc/preRelease/www/downloads.wiki

--
Joe Mistachkin

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Roger Binns
On 08/09/14 03:49, Andres Riancho wrote:
 Off-list some guys contacted me and mentioned APSW [0], another
 wrapper around sqlite for python, and said that it might be worth
 giving it a try. Do you guys believe that a change in wrapper could
 improve my situation? Thanks!

(Disclosure: I am the APSW author)

It seems like you are randomly fishing around for things hoping for some
magic.  There is no magic.

When deployed to a non-trivial number of places there will be some
corruption no matter what.  Most machines do not run ECC, cosmic rays,
random quality hardware, bad cables etc will cause problems eventually.

Changing SQLite settings (eg pragma synchronous=off) to deliberately lose
durability is playing with fire.  It is only safe if you can prove your code
is (and always will be) bug free.

APSW is a better wrapper for SQLite.  If you use a recent version then you
will also be using a recent version of SQLite which will have more defensive
code in it based on real world experience.

  http://rogerbinns.github.io/apsw/pysqlite.html

Roger

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Andres Riancho
On Mon, Sep 8, 2014 at 2:27 PM, Roger Binns rog...@rogerbinns.com wrote:
 On 08/09/14 03:29, Andres Riancho wrote:
 In my project we use the database to store data during the process
 life, and then remove it when the process finishes.

 It sounds like what you could use temporary tables and let SQLite do the
 work for you.

Was completely unaware of that feature, will take a look.

 With this in mind, sync=OFF still looks like something that could
 cause database malformed errors?

 The problem with synchronous off is that all your code has to be perfect,

My code IS perfect (??)

 not to mention the operating system and hardware.  While you might be
 reasonably convinced right now that interactions between all the parts of
 code and database are safe, all it takes is some changes in the future to
 invalidate that.

 I strongly recommend not playing with fire.

Ok, makes sense. Merging Simon's answer:

 Hmmm.  How about this.  Stop turning synchronous off for a month or two and 
 see if people stop reporting the fault.

Yep, that's a great idea.

 Roger

 ___
 sqlite-users mailing list
 sqlite-users@sqlite.org
 http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



-- 
Andrés Riancho
Project Leader at w3af - http://w3af.org/
Web Application Attack and Audit Framework
Twitter: @w3af
GPG: 0x93C344F3
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Andres Riancho
On Mon, Sep 8, 2014 at 2:37 PM, Roger Binns rog...@rogerbinns.com wrote:
 On 08/09/14 03:49, Andres Riancho wrote:
 Off-list some guys contacted me and mentioned APSW [0], another
 wrapper around sqlite for python, and said that it might be worth
 giving it a try. Do you guys believe that a change in wrapper could
 improve my situation? Thanks!

 (Disclosure: I am the APSW author)

 It seems like you are randomly fishing around for things hoping for some
 magic.  There is no magic.

Damn. I really like magic.

 When deployed to a non-trivial number of places there will be some
 corruption no matter what.  Most machines do not run ECC, cosmic rays,
 random quality hardware, bad cables etc will cause problems eventually.

 Changing SQLite settings (eg pragma synchronous=off) to deliberately lose
 durability is playing with fire.  It is only safe if you can prove your code
 is (and always will be) bug free.

 APSW is a better wrapper for SQLite.  If you use a recent version then you
 will also be using a recent version of SQLite which will have more defensive
 code in it based on real world experience.

   http://rogerbinns.github.io/apsw/pysqlite.html

Thanks for the input. My plan will be to comment the line that sets
sync=off and see how the application behaves. If the bug reports drop
to zero (or near zero), we'll know that was the reason. If the errors
still appear, I might experiment with apsw.

 Roger

 ___
 sqlite-users mailing list
 sqlite-users@sqlite.org
 http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



-- 
Andrés Riancho
Project Leader at w3af - http://w3af.org/
Web Application Attack and Audit Framework
Twitter: @w3af
GPG: 0x93C344F3
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Python - database disk image is malformed

2014-09-08 Thread Richard Hipp
On Mon, Sep 8, 2014 at 1:56 PM, Andres Riancho andres.rian...@gmail.com
wrote:

 On Mon, Sep 8, 2014 at 2:27 PM, Roger Binns rog...@rogerbinns.com wrote:
 
  It sounds like what you could use temporary tables and let SQLite do the
  work for you.

  Hmmm.  How about this.  Stop turning synchronous off for a month or two
 and see if people stop reporting the fault.

 Yep, that's a great idea.


FWIW, temporary tables *always* operate as if synchronous=off, regardless
of the actually synchronous setting

-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Final preparations for the release of System.Data.SQLite v1.0.94.0 have begun...

2014-09-08 Thread Joe Mistachkin
 
Pre-release packages are now available at:

https://system.data.sqlite.org/index.html/doc/preRelease/www/downloads.wiki

If you have any issues with these packages, please report them via this
mailing
list (and/or by creating a ticket on https://system.data.sqlite.org/;)
prior to
Friday, September 12th.

Thanks.

--
Joe Mistachkin

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Roger Binns
On 08/09/14 05:35, Richard Hipp wrote:
 See the essay at:
 
http://www.sqlite.org/affcase1.html
 
 Comments, criticism, and feedback are welcomed.

BTW historically Microsoft used a file system for Office files before the
XML stuff (ie even in the first versions from over 20 years ago).  Back then
the file system was a variant of FAT.  The underlying format of the files
was also optimised for modifications, recording things as a series of chunks
rather than as contiguous content.  The reason I mention all this is because
the obvious solution for an XML world is to do the ZIP file approach
allowing much compatibility for existing code and formats, not because it is
the best solution out there.

Incremental update is hard

That isn't strictly true.  ZIP files (unlike the majority of formats) store
the central directory of content at the end of the file.  You can update a
zip file by appending the updated content, and then appending the new
central directory but with the file name pointing to the updated content not
the older version.  That does then require some form of garbage collection,
but space is way larger these days.  It also seems possible to leave space
after a file before the next one as room to grow thereby not needing a full
rewrite on small changes.

As to SQLite, I think the biggest issue is dealing with corrupted content.
A zip file has a file as a unit of content with each one separately
compressed and checksummed.  If you corrupted a random byte of a zip file
you could easily determine that it has happened and isolate which file is
affected.  You may even be able to recover from it (eg it was a small picture).

SQLite has no way of finding corrupted content nor isolating it.  The
integrity check pragma might find something if the corruption happened
somewhere in metadata, but other than that you are unlikely to discover it.
 Previous riding of that high horse (rejected):

  http://www.sqlite.org/src/tktview?name=72b01a982a

Zip also has encryption as standard which SQLite doesn't.

Overall I'd suggest keeping most of the content but changing the focus to
Best practises when using SQLite as an application file format.  ie if
someone is sold on SQLite as the format then what should they do.  As an
example I have found that versioning and undo/redo are the most important
things to get right up front.  Showing the triggers to use for undo/redo
would be helpful.  Suggesting a thumbnail entry is good too, etc.

Roger
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Nico Williams
And now that SQLite3 has recursive queries, building a mapping of
XML-SQL is relatively easy, which might make it even easier to switch
to SQLite3.

(Speaking of which, a XPath to SQL compiler would be really nice.  I
haven't sat down to think about whether that'd be feasible, but my
impression is that it should be.  An XSLT interpreter that used SQL
should be feasible as well.)

There's also your UnQL, no?
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Final preparations for the release of System.Data.SQLite v1.0.94.0 have begun...

2014-09-08 Thread Eric DAVID
Hi, 

The issue I found about indexes on another column than the primary key is
now corrected, I obtain the desired results. Thank you for your efficiency
and your quickness.

Eric DAVID  

-Message d'origine-
De : sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] De la part de Joe Mistachkin
Envoyé : lundi 8 septembre 2014 21:15
À : 'General Discussion of SQLite Database'
Cc : sqlite-...@sqlite.org
Objet : Re: [sqlite] Final preparations for the release of
System.Data.SQLite v1.0.94.0 have begun...

 
Pre-release packages are now available at:

https://system.data.sqlite.org/index.html/doc/preRelease/www/downloads.wiki

If you have any issues with these packages, please report them via this
mailing list (and/or by creating a ticket on
https://system.data.sqlite.org/;)
prior to
Friday, September 12th.

Thanks.

--
Joe Mistachkin

___
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] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Nico Williams
It'd also be good to have JSON and XML support, possibly as an
loadable extension.  That way XPath and similar expressions matching
document snippets in SQL string values could be used in SQL queries.

I've played with building a JSON extension for SQLite3 using jq's
excellent JSON C library.  The biggest problem with that work is
that the extension has to serialize values to JSON (and, of course,
parse) in many cases where it could be avoided with some help from
SQLite3.

It'd be *very* convenient if SQLite3 had a value type that corresponds
to loadable extensions' private types, and a protocol for releasing
and serializing values of such types.

(jq has an XPath-like language, but for JSON.)

Nico
--
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Simon Slavin

On 8 Sep 2014, at 11:45pm, Nico Williams n...@cryptonector.com wrote:

 It'd also be good to have JSON and XML support, possibly as an
 loadable extension.  That way XPath and similar expressions matching
 document snippets in SQL string values could be used in SQL queries.

Not so sure about that.  There are JSON and XML extensions available for 
pretty-much every language out there.  Do you feel they need to be tightly 
integrated with SQLite somehow ?

 It'd be *very* convenient if SQLite3 had a value type that corresponds
 to loadable extensions' private types, and a protocol for releasing
 and serializing values of such types.

Ah, but there you struck gold.  If this is to be adopted, SQLite needs a 
DataType of FILE. Complete with functions to do things like get a file's name, 
path, length, contents, and probably half a dozen other things that don't come 
to mind right now.  In fact this might be useful for SQLite even if it isn't 
going to be used as an OpenDoc file container.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Nico Williams
On Mon, Sep 8, 2014 at 6:16 PM, Simon Slavin slav...@bigfraud.org wrote:
 On 8 Sep 2014, at 11:45pm, Nico Williams n...@cryptonector.com wrote:
 It'd also be good to have JSON and XML support, possibly as an
 loadable extension.  That way XPath and similar expressions matching
 document snippets in SQL string values could be used in SQL queries.

 Not so sure about that.  There are JSON and XML extensions available for 
 pretty-much every language out there.  Do you feel they need to be tightly 
 integrated with SQLite somehow ?

No, I don't.  I rather dislike the way Postgres did the hstore and the
subsequent JSON support.

I should clarify: what I don't like is ad-hoc syntax.  I would like a
way to embed arbitrary external languages like jq or XPath in SQL
expressions.

 It'd be *very* convenient if SQLite3 had a value type that corresponds
 to loadable extensions' private types, and a protocol for releasing
 and serializing values of such types.

 Ah, but there you struck gold.  If this is to be adopted, SQLite needs a 
 DataType of FILE. Complete with functions to do things like get a file's 
 name, path, length, contents, and probably half a dozen other things that 
 don't come to mind right now.  In fact this might be useful for SQLite even 
 if it isn't going to be used as an OpenDoc file container.

Yes.  Pretty please, with sugar on top?

Nico
--
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread John McKown
On Mon, Sep 8, 2014 at 6:32 PM, Nico Williams n...@cryptonector.com wrote:
 On Mon, Sep 8, 2014 at 6:16 PM, Simon Slavin slav...@bigfraud.org wrote:
 On 8 Sep 2014, at 11:45pm, Nico Williams n...@cryptonector.com wrote:
 It'd also be good to have JSON and XML support, possibly as an
 loadable extension.  That way XPath and similar expressions matching
 document snippets in SQL string values could be used in SQL queries.

 Not so sure about that.  There are JSON and XML extensions available for 
 pretty-much every language out there.  Do you feel they need to be tightly 
 integrated with SQLite somehow ?

 No, I don't.  I rather dislike the way Postgres did the hstore and the
 subsequent JSON support.

 I should clarify: what I don't like is ad-hoc syntax.  I would like a
 way to embed arbitrary external languages like jq or XPath in SQL
 expressions.

 It'd be *very* convenient if SQLite3 had a value type that corresponds
 to loadable extensions' private types, and a protocol for releasing
 and serializing values of such types.

 Ah, but there you struck gold.  If this is to be adopted, SQLite needs a 
 DataType of FILE. Complete with functions to do things like get a file's 
 name, path, length, contents, and probably half a dozen other things that 
 don't come to mind right now.  In fact this might be useful for SQLite even 
 if it isn't going to be used as an OpenDoc file container.

 Yes.  Pretty please, with sugar on top?

 Nico
 --

Hum, why not a URI data type instead? ref:
http://en.wikipedia.org/wiki/URI_scheme or
http://www.ietf.org/rfc/rfc3986.txt .This is a proper superset of a
URL. And it could encompass many other access methods. Some that are
implemented in browsers are things like http://some.webpage.html,
file:///path/to/local/file, mailto:user.n...@organization.net,
ftp://user:passw...@host.com/subdir/file and lots of other
possibilities. The RFC does not attempt to detail all possible scheme
(the first thing in the name, before the first :). SQLite could
implement the fetching of contents by doing something like loading a
dynamic library at run-time which might look like: libscheme.so or
.dll Where scheme is the URI scheme. E.g. libftp.so or libhttp.so .
If just used in a SELECT, SQLite would just return a string value
equal to the value such as you might see in a browser. And if the
contents were needed,  a function such as fetch() might be use. E.g.
SELECT FETCH(urifield) FROM table; would get the URI for each non-NULL
value of urifield, inspect the first portion for the scheme, load
the proper library and then pass the URI as a string value to that
routine. Of course, this is getting fairly involved. And what is done
if such a library does not exist? Error out the entire SELECT? Return
a NULL? It gets very complicated. And I'm sure Dr. Hipp will see more
problems and implications that I could ever imagine.


-- 
There is nothing more pleasant than traveling and meeting new people!
Genghis Khan

Maranatha! 
John McKown
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Nico Williams
On Mon, Sep 8, 2014 at 8:05 PM, John McKown
john.archie.mck...@gmail.com wrote:
 Hum, why not a URI data type instead? ref:

Because we're talking about a purely internal type, with internal
linkage.  Externally it would appear as TEXT or BLOB.

You'd use the TEXT type to store JSON, XML, ..., BLOB to store binary
encodings.  Internally you need to parse and serialize these things at
the boundaries.  If the boundaries are the existing ones then you end
up parsing and serializing more than if the boundaries were just the
file format.

What I've got in mind is an extension to the loadable extension
framework that allows each extension to add one (or more)
pseudo-type(s) that have: a parser, a serializer, a copy/incref, and a
release/decref operations, and probably nothing else.  Those
operations would be the internal linkage.

API-wise there would be new statement parameter binding and cursor
column accessors for using pseudo-types instead of TEXT/BLOB, but if
these aren't used you'd get TEXT/BLOB.

Language-wise there'd be not much special: virtual tables and
user-defined functions are enough, really.

If you ran a SELECT in the sqlite3 shell you'd get TEXT or BLOB
results, but if you ran it using the C API you could access the
internal extension type (e.g., the C 'jv' type provided by libjq).

Nico
--
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Keith Medcalf

Not really very difficult, and it does not require another type.  You just need 
a scalar function to process the URI passed to the function and return the 
result -- just like the readfile() (in the fileio.c extension, or included in 
the shell) function does for a file-specifier which can be opened by the 
platform open api.

Of course, the size of the module required to do this might be rather large.  
Or it could be very simple.  Here is a simple example in python using apsw and 
fs (output truncated in various places ...) with no meaningful results (ie, 
null) if the URI doesn't parse:

--- apswopener.py ---
import apsw
from fs.opener import opener
import sys

def uricontents(URI):
if not URI:
return
try:
contents = opener.getcontents(URI)
except:
return None
try:
return unicode(contents)
except:
return bytearray(contents)

def defineuricontents(cn):
cn.createscalarfunction('uricontents', uricontents, 1)

apsw.connection_hooks.append(defineuricontents)

db = None
if len(sys.argv)  1:
db = apsw.Connection(sys.argv[1])
apsw.Shell(db=db).cmdloop()
--- EOF ---

2014-09-08 19:59:08 [D:\Data\Apps\fs]
apswopener.py
SQLite version 3.8.7 (APSW 3.8.5-r1)
Enter .help for instructions
Enter SQL statements terminated with a ;
sqlite select uricontents('d:\source\sqlite\x');
SQLITE_32BIT_ROWID
SQLITE_4_BYTE_ALIGNED_MALLOC
SQLITE_64BIT_STATS
SQLITE_ALLOW_COVERING_INDEX_SCAN
[... pasting truncated ...]

sqlite select uricontents('http://mail.dessus.com/');

!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN 
http://www.w3.org/TR/html4/loose.dtd;
html lang=en dir=LTR
head
meta http-equiv=Content-Type content=text/html; charset=utf-8 /

title CommuniGate Pro dessus.com Entrance/title
link rel=stylesheet href=/SkinFiles/dessus.com//style.css 
type=text/css /
  meta http-equiv=x-dns-prefetch-control content=off /
[... pasting truncated ...]

sqlite select uricontents('http://www.sqlite.org');
!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN 
http://www.w3.org/TR/html4/strict.dtd;
htmlhead
meta http-equiv=content-type content=text/html; charset=UTF-8
titleSQLite Home Page/title
style type=text/css
body {
margin: auto;
font-family: Verdana, sans-serif;
padding: 8px 1%;
}

a { color: #044a64 }
a:visited { color: #734559 }
[... pasting truncated ...]

sqlite select length(uricontents('http://www.sqlite.org/favicon.ico'));
318
sqlite select uricontents('http://www.sqlite.org/favicon.ico');
Binary data
sqlite select hex(uricontents('http://www.sqlite.org/favicon.ico'));
01000100101011000400280116002800100021000400A8A8A800
98A4780070505000133132022002
002322022020220220222000220220202202220100020022200220202000222200200200
200200000200220200222200220200220000200200223220002200231331

sqlite select typeof(uricontents('http://www.sqlite.org/favicon.ico'));
blob
sqlite select typeof(uricontents('http://www.sqlite.org/'));
text

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
boun...@sqlite.org] On Behalf Of John McKown
Sent: Monday, 8 September, 2014 19:06
To: General Discussion of SQLite Database
Subject: Re: [sqlite] What if OpenDocument were built atop SQLite?

On Mon, Sep 8, 2014 at 6:32 PM, Nico Williams n...@cryptonector.com
wrote:
 On Mon, Sep 8, 2014 at 6:16 PM, Simon Slavin slav...@bigfraud.org
wrote:
 On 8 Sep 2014, at 11:45pm, Nico Williams n...@cryptonector.com
wrote:
 It'd also be good to have JSON and XML support, possibly as an
 loadable extension.  That way XPath and similar expressions matching
 document snippets in SQL string values could be used in SQL queries.

 Not so sure about that.  There are JSON and XML extensions available
for pretty-much every language out there.  Do you feel they need to be
tightly integrated with SQLite somehow ?

 No, I don't.  I rather dislike the way Postgres did the hstore and the
 subsequent JSON support.

 I should clarify: what I don't like is ad-hoc syntax.  I would like a
 way to embed arbitrary external languages like jq or XPath in SQL
 expressions.

 It'd be *very* convenient if SQLite3 had a value type that
corresponds
 to loadable extensions' private types, and a protocol for releasing
 and serializing values of such types.

 Ah, but there you struck gold.  If this is to be adopted, SQLite needs
a DataType of FILE. Complete with functions to do things like get a
file's name, path, length, contents, and probably half a dozen other
things that don't come to mind right now.  In fact this might be useful
for 

Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Nico Williams
On Mon, Sep 8, 2014 at 9:44 PM, Keith Medcalf kmedc...@dessus.com wrote:

 Not really very difficult, and it does not require another type.  You just 
 need a scalar function to process the URI passed to the function and return 
 the result -- just like the readfile() (in the fileio.c extension, or 
 included in the shell) function does for a file-specifier which can be 
 opened by the platform open api.

Here's intended usage:

sqlite3 .load jq
sqlite3 -- the jq() function takes a JSON text and a jq program as
(TEXT type) arguments
sqlite3 SELECT jq(json_column, '.Title') FROM some_table WHERE
jq(json_column, '.Author.surname') LIKE 'Smith';
titles
sqlite3

Now suppose you have a more complex query, with sub-queries say, so
that a result from jq() can be fed to jq() again.  Without a
pseudo-type the jq() function must always return encoded JSON texts
(as TEXT) and must always consume encoded JSON texts (as TEXT).  With
a pseudo-type the jq() function can consume either TEXT or the
pseudo-type, and it outputs the pseudo-type, which is converted to
TEXT as needed by calling the pseudo-type's encoder method.

I'm not entirely sure what you and/or John M. have in mind as for
using a URI scheme.  I assume you mean something like encode internal
values as a URI, which is fine at first, but then you realize it
leads to unavoidable leaks.

Suppose we have a JSON C API that uses pointers (or structs with
pointers) to objects on the heap.  And then suppose that we encode
these as URIs as TEXT or BLOB (the latter makes encoding and
decoding easy).  But now we have a problem: if a SQL expression
concatenates/substrings these values we might not recognize the result
as a valid URI and we'll leak the heap object.

But with a pseudo-type there's no such risk.  If at any point a SQL
sub-expression needs to manipulate a value where one of these
pseudo-types appears then SQLite3 would call the pseudo-type's encoder
to get a JSON text (or XML, or whatever) and then apply
sub-string/concat/whatever to that.

I'd hate to have to say to users that they have to be careful with
their SQL, else they could leak parsed JSON/XML objects...  Among
other things that would be insecure.

A pseudo-type would be an optimization, really, and only an
optimization, but a very valuable one, optimizing two things in the
case of XPath and jq:

 - some XML / JSON parsing/encoding can be avoided

 - XPath / jq program compilations can be cached (like SQL statement
compilation)

For intense XML / JSON applications those two optimizations could mean a lot.

I work with one application that uses Postgres because of the hstore.
It used to support SQLite3 as well, but now it can't because SQLite3
has nothing like the hstore.  It'd be nice if SQLite3 had something
like the PG hstore, but nicer and with JSON as the text encoding.

If SQLite3 could have a nice and well-performing XML interface then
Richard Hipp's OpenDocument on SQLite3 concept would be easier to
bring to fruition.

Nico
--
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Stephan Beal
On Tue, Sep 9, 2014 at 12:45 AM, Nico Williams n...@cryptonector.com
wrote:

 I've played with building a JSON extension for SQLite3 using jq's
 excellent JSON C library.  The biggest problem with that work is

that the extension has to serialize values to JSON (and, of course,
 parse) in many cases where it could be avoided with some help from
 SQLite3.


FWIW:

http://fossil.wanderinghorse.net/wikis/cson/?page=cson_sqlite3


-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do. -- Bigby Wolf
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] What if OpenDocument were built atop SQLite?

2014-09-08 Thread Stephan Beal
On Tue, Sep 9, 2014 at 6:46 AM, Stephan Beal sgb...@googlemail.com wrote:

 On Tue, Sep 9, 2014 at 12:45 AM, Nico Williams n...@cryptonector.com
 wrote:

 I've played with building a JSON extension for SQLite3 using jq's
 excellent JSON C library.  The biggest problem with that work is

 that the extension has to serialize values to JSON (and, of course,
 parse) in many cases where it could be avoided with some help from
 SQLite3.


 FWIW:

 http://fossil.wanderinghorse.net/wikis/cson/?page=cson_sqlite3


BTW: that's the same code we use in Fossil for the JSON API:

https://docs.google.com/document/d/1fXViveNhDbiXgCuE7QDXQOKeFzf2qNUkBEgiUvoqFN4/view


-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do. -- Bigby Wolf
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users