Re: [sqlite] BLOB support and SQLite 3.0

2003-12-15 Thread Mrs. Brisby
On Mon, 2003-12-15 at 09:37, D. Richard Hipp wrote:
>(2) The ".dump" command will only show the binary data through
>the first \000 character.  If the binary data contains no
>\000 characters, the ".dump" command might segfault.

Add an SQL function like TOCHAR or something like that. Then make dump's
output look like this:

INSERT INTO foo ('Hello'||TOCHAR(32)||'World!');




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[sqlite] BLOB support and SQLite 3.0

2003-12-15 Thread D. Richard Hipp
Mrs. Brisby wrote:
[...] I really would like to see user-defined "structures"- but I
suspect this will have to wait for SQLite 3.0 or whenever we get
non-null-terminating values...
You can do that now.  The (experimental) sqlite_bind() API available
in 2.8.7 allows you to insert arbitrary binary data into an SQLite
database.  There are, however, limitations:
  (1) When you do a query, you will get back a pointer to the
  beginning of the binary data, but not its length.  You'll
  probably need to store the length in a separate column.
  (2) The ".dump" command will only show the binary data through
  the first \000 character.  If the binary data contains no
  \000 characters, the ".dump" command might segfault.
  (3) If you try to put binary data into a column that is indexed,
  you will likely corrupt the database and may segfault.
Fixing (1) is not too hard, but there are non-technical reasons
that will delay this fix for at least 6 months. I have no clue
how to fix (2).  A fix for (3) will require a file format change.
Since you mentioned SQLite 3.0...  Design studies for SQLite 3.0
have been underway for several months.  We (I have collaborators)
are looking at a very different file format for 3.0 that is both
faster and uses less disk space.  The current thought is that the
API would change in several important ways too, ways that make it
easier to insert or extract binary data.  The new API routines would
use a prefix of "sqlite3_" instead of "sqlite_".  A small library
or wrapper routines (or perhaps macros) would be provided for
backwards compatibility to the SQLite 2.0 API.  Database files
would have to be converted separately in order to work with 3.0.
Bugs will continue to be fixed in the 2.x.x series after 3.0 appears,
in order to support legacy applications built around 2.x.x,
but new features will go into 3.0 exclusively, according to the
plan.  SQLite 3.0 is unlikely to appear before the middle of 2004
at the earliest.  There is no guarantee that SQLite 3.0 will ever
come into existance - we may decide to continue forward with 2.0
instead.
--
D. Richard Hipp -- [EMAIL PROTECTED] -- 704.948.4565
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: [sqlite] Let us make SQLite more powerful

2003-12-15 Thread Mrs. Brisby
All I was demonstrating was how to use a single field. It's obviously
better to use a second table and build a relationship using JOIN.

I don't see where "multi-occurrence" fields can do something that
JOIN-ed relationships can't.

SELECT LastName FROM Contacts JOIN Phones USING (phoneID) HAVING
PhoneNumber='2064814442';

or perhaps:

SELECT LastName FROM Contacts WHERE phoneID IN (SELECT phoneID FROM
Phones WHERE PhoneNumber='2064814442';

Thus it would seem that this can simply be implemented in terms of
syntax (automatic table creation, rewriting queries for implicit joins,
etc).

You'll note I never said that this feature is "uncommon" - merely
unnecessary, kludgy, and queries written in this manner are difficult to
read, and as at least you've noticed, difficult to port. It would be
nice for the engine to do it automatically for you.

But it would make the engine more complex- for a direction that isn't
standard, that doesn't add the ability to answer questions that
previously could not, nor the ability to answer questions faster than
before. That is, as near as I can tell, it only provides the ability to
answer questions with less typing.

Even if BASIS is slower for these implicit joins, that doesn't mean
other systems are (PostgreSQL isn't, for example). What it does mean is
that BASIS has a crappy query optimizer.

That said, I really would like to see user-defined "structures"- but I
suspect this will have to wait for SQLite 3.0 or whenever we get
non-null-terminating values...


On Mon, 2003-12-15 at 07:25, Steve O'Hara wrote:
> Here's my tuppence worth;
> 
> I've been working with BASIS for donkeys years and it is one of the few
> RDBMS that fully supports multi-occurence fields.
> To search for a value in such a field you simply say
> SELECT LastName FROM Contacts
> WHERE Phones = "2064814442"
> This means search in any occurance within Phones
> 
> If you want a specific entry then you say
> SELECT LastName FROM Contacts
> WHERE Phones(3) = "2064814442"
> 
> Interestingly, if you have a number of fields that have matched values e.g.
> Phone, Extension etc you can do this
> SELECT LastName FROM Contacts
> WHERE Phones="2064814442" WITH Extension="234"
> This means find records where the same occurance of Phones and Extension
> meets the criteria.
> 
> Although BASIS is fully relational, this feature is very commonly used
> instead of creating linked lookup tables and doing a join, because of the
> poorer performance of joins. The techniques shown here by Mrs Brisby are
> fine but because they use LIKE, they don't use an index and so will be very
> slow for large databases.
> 
> However, there are some disadvantages to this stuff;
> 
>   Multi-occurance fields are not common to RDBMS
> 
>   Sorting can be interesting (you might have to do an "exploding" sort) e.g.
> SELECT LastName FROM Contacts
> WHERE Phones = "2064814442" ORDER BY EVERY Phones
>or
> SELECT LastName FROM Contacts
> WHERE Phones = "2064814442" ORDER BY Phones(1)
> 
>   More complexity in SQLite
> 
> Steve
> 
> 
> 
> 
> -Original Message-
> From: Mrs. Brisby [mailto:[EMAIL PROTECTED]
> Sent: 12 December 2003 13:56
> To: Yogesh Vachhani
> Cc: [EMAIL PROTECTED]
> Subject: Re: [sqlite] Let us make SQLite more powerful
> 
> 
> On Fri, 2003-12-12 at 08:09, Yogesh Vachhani wrote:
> > For example, if the Phones column is a collection, one can find all
> > rows that contain the phone number 206-481-4442 by specifying the
> > following SELECT statement:
> >
> > SELECT LastName
> > FROM Contacts
> > WHERE Phones(ANY) = "2064814442"
> 
> Why not encode Phones as ":phonenumber:"
> that way you can already do:
> SELECT LastName FROM Contacts WHERE Phones LIKE '%:phonenumber:%'
> 
> (btw, your quoting is wrong)
> 
> > If one always store fax numbers in the third element of the Phones
> > collection, one could find all rows that contain a particular fax
> > number
> > like this:
> >
> > SELECT LastName
> > FROM Contacts
> > WHERE Phones(3) = "2064814442"
> 
> SELECT LastName FROM Contacts WHERE Phones LIKE ':%::%::phonenumber:%';
> 
> 
> > For example, lets return to the contact database, which contains a
> > Phones column whose
> > data type is PhoneStructure, so the Phones column contains the
> > columns PhoneType and PhoneNum. The following query could returns
> > just the phone number 206-402-9400 and not the phone type for that
> > number:
> >
> > SELECT Phones(*)!PhoneNum
> > FROM Contacts
> > WHERE LastName = "Calder"
> 
> This didn't require any special syntax.
> 
> > The following query would return the phone numbers for every contact
> > who has a fax number:
> >
> > SELECT Phones(*)!PhoneNum
> > FROM Contacts
> >