Re: [sqlite] SQL Syntax fault on UPDATE statement

2016-08-17 Thread flo
Effectively,

Sorry about my mistake.

2016-08-17 10:33 GMT+02:00 Richard Hipp :

> On 8/17/16, flo  wrote:
> >
> > $ sqlite3 test.db "UPDATE test SET id=0 AND name='new_name' AND age=30
> > WHERE id=1;"
>
> The above is parsed like this:
>
>   UPDATE test SET id = (0 AND name='new_name' AND age=30) WHERE id=1;
>
> And since the expression in parentheses always evaluates to 0, the
> above is equivalent to:
>
>   UPDATE test SET id=0 WHERE id=1;
>
> Which is exactly what SQLite is doing.
>
> --
> D. Richard Hipp
> d...@sqlite.org
>
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQL Syntax fault on UPDATE statement

2016-08-17 Thread R Smith



On 2016/08/17 11:04 AM, Simon Davies wrote:

On 17 August 2016 at 09:39, R Smith  wrote:


On 2016/08/17 9:05 AM, flo wrote:

Hi everyone,

.
.
.

Well, it is perfectly valid to give boolean operations as an expression.
If I said " id = 3 AND 6 then the resulting value would be 2  (If you are
unsure why that is you need to read up on Boolean logic, check google for
it)

Boolean AND:
sqlite> select 3 and 6;
1

Bitwise and:
sqlite> select 3 & 6;
2


Indeed - thanks Simon.

I wasn't actually thinking in SQL terms there, just trying to explain a 
principle - which I should have checked to be clear on to the OP.


To be sure - "bitwise" isn't something else, it is still Boolean, it's 
just a way of doing boolean logic per bit (what makes the world of 
computing possible) as opposed to regarding the input as a single entity 
that evaluates to TRUE or FALSE. The fact that 3 and 6 both evaluate to 
TRUE (Because >0) in SQLite means they are regarded as entities (as they 
should when you use the word "AND" in stead of "&") and so rightly 
evaluate to TRUE (1) as above.


As an aside - I come from programming languages where that difference 
did not exist and "(3 and 6) --> 2", and "((i>0) or 2) -> 3" where i>0, 
which made setting flags and such much much faster and is much better to 
my mind with the small caveat that you couldn't hide error-return values 
in Boolean guise or directly refer a return value that might have 
multiple possible values (but you only want to know if it is or isn't 
so) which is a better construct for SQL.



In those days bytes were expensive. Now you can dedicate Integers or 
even strings and a whole column to one flag state without feeling any 
guilt - viva progress!  :)



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


Re: [sqlite] SQL Syntax fault on UPDATE statement

2016-08-17 Thread Simon Davies
On 17 August 2016 at 09:39, R Smith  wrote:
>
>
> On 2016/08/17 9:05 AM, flo wrote:
>>
>> Hi everyone,
.
.
.
> Well, it is perfectly valid to give boolean operations as an expression.
> If I said " id = 3 AND 6 then the resulting value would be 2  (If you are
> unsure why that is you need to read up on Boolean logic, check google for
> it)

Boolean AND:
sqlite> select 3 and 6;
1

Bitwise and:
sqlite> select 3 & 6;
2

> I hope that makes it clear!
> Ryan

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


Re: [sqlite] SQL Syntax fault on UPDATE statement

2016-08-17 Thread R Smith



On 2016/08/17 9:05 AM, flo wrote:

Hi everyone,

I found a reproducible bug on the SQL UPDATE statement parsing. Here is the
details.

I 've try to update some data on a SQLite database with a outlandish syntax
with "AND" between the columns to be update.  The SQL didn't fail but the
data update was incomplete.


The SQLite version :

$ sqlite3 -version
3.13.0 2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2


The data base schema :

$ sqlite3 test.db ".schema"
CREATE TABLE test(id interger, name varchar, age integer)


INTEGER is spelt wrong here (for id) - won't be a problem in this case, 
but might cause other non-expected things.





The initial stat of the table :

$ sqlite3 test.db "SELECT * FROM test;"
1|toto|10
2|tita|10
2|tita|10
1|toto|10
2|tita|10


The oulandish SQL UPDATE :

$ sqlite3 test.db "UPDATE test SET id=0 AND name='new_name' AND age=30
WHERE id=1;"


The stat of the table after the outlandish update :

$ sqlite3 test.db "SELECT * FROM test;"
0|toto|10
2|tita|10
2|tita|10
0|toto|10
2|tita|10

==> The "id" column was updated but not the two other columns "name" and
"age".


There is nothing outlandish about this, it's a normal statement and 
reads like normal SQL to the parser - I think all that happened is maybe 
your expected meaning is not aligned with what the Parser sees. Firstly, 
AND is a boolean operator in SQL, not a concatenation or grouping 
mechanism, for that we need comma - To try and explain, let me first 
show the correct way to update:


UPDATE test SET id = 0, name = 'new_name', age = 30 WHERE id = 1;

That must work correctly.
So why did it not fail then?

Well, it is perfectly valid to give boolean operations as an expression.
If I said " id = 3 AND 6 then the resulting value would be 2  (If you 
are unsure why that is you need to read up on Boolean logic, check 
google for it)
Also for evaluating booleans I could go if this_is_true AND this_is_true 
AND _this_is_true  then I will get a return value that is true (1) if 
all three are true, and false (0) otherwise.


What happened in your case is it checked whether id is 0 AND name is 
'new_name' AND age is 30... which of course it wasn't, so it returned 0 
(false) and so updated your id with a 0 value where id was 1.


Perfectly behaving as expected.

I hope that makes it clear!
Ryan

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


Re: [sqlite] SQL Syntax fault on UPDATE statement

2016-08-17 Thread Hick Gunter
Your UPDATE statement does not mean what you think it means.

UPDATE test SET id=0 AND name='new_name' AND age=30 WHERE id=1;

Is parsed as:

UPDATE test SET id = (0 AND name='new_name' AND age=30) WHERE id=1;

The expression (0 AND ...) will always evaluate to 0.


-Ursprüngliche Nachricht-
Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im 
Auftrag von flo
Gesendet: Mittwoch, 17. August 2016 09:05
An: sqlite-users@mailinglists.sqlite.org
Betreff: [sqlite] SQL Syntax fault on UPDATE statement

Hi everyone,

I found a reproducible bug on the SQL UPDATE statement parsing. Here is the 
details.

I 've try to update some data on a SQLite database with a outlandish syntax 
with "AND" between the columns to be update.  The SQL didn't fail but the data 
update was incomplete.


The SQLite version :

$ sqlite3 -version
3.13.0 2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2


The data base schema :

$ sqlite3 test.db ".schema"
CREATE TABLE test(id interger, name varchar, age integer)


The initial stat of the table :

$ sqlite3 test.db "SELECT * FROM test;"
1|toto|10
2|tita|10
2|tita|10
1|toto|10
2|tita|10


The oulandish SQL UPDATE :

$ sqlite3 test.db "UPDATE test SET id=0 AND name='new_name' AND age=30 WHERE 
id=1;"


The stat of the table after the outlandish update :

$ sqlite3 test.db "SELECT * FROM test;"
0|toto|10
2|tita|10
2|tita|10
0|toto|10
2|tita|10

==> The "id" column was updated but not the two other columns "name" and "age".


A common SQL Update syntaxe work perfectly :

$ sqlite3 test.db "UPDATE test SET id=6, name='new_name', age=30 WHERE id=2;"

$ sqlite3 test.db "SELECT * FROM test;"
0|toto|10
6|new_name|30
6|new_name|30
0|toto|10
6|new_name|30


Good Luck

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


___
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: h...@scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.


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


Re: [sqlite] SQL Syntax fault on UPDATE statement

2016-08-17 Thread Richard Hipp
On 8/17/16, flo  wrote:
>
> $ sqlite3 test.db "UPDATE test SET id=0 AND name='new_name' AND age=30
> WHERE id=1;"

The above is parsed like this:

  UPDATE test SET id = (0 AND name='new_name' AND age=30) WHERE id=1;

And since the expression in parentheses always evaluates to 0, the
above is equivalent to:

  UPDATE test SET id=0 WHERE id=1;

Which is exactly what SQLite is doing.

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


[sqlite] SQL Syntax fault on UPDATE statement

2016-08-17 Thread flo
Hi everyone,

I found a reproducible bug on the SQL UPDATE statement parsing. Here is the
details.

I 've try to update some data on a SQLite database with a outlandish syntax
with "AND" between the columns to be update.  The SQL didn't fail but the
data update was incomplete.


The SQLite version :

$ sqlite3 -version
3.13.0 2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2


The data base schema :

$ sqlite3 test.db ".schema"
CREATE TABLE test(id interger, name varchar, age integer)


The initial stat of the table :

$ sqlite3 test.db "SELECT * FROM test;"
1|toto|10
2|tita|10
2|tita|10
1|toto|10
2|tita|10


The oulandish SQL UPDATE :

$ sqlite3 test.db "UPDATE test SET id=0 AND name='new_name' AND age=30
WHERE id=1;"


The stat of the table after the outlandish update :

$ sqlite3 test.db "SELECT * FROM test;"
0|toto|10
2|tita|10
2|tita|10
0|toto|10
2|tita|10

==> The "id" column was updated but not the two other columns "name" and
"age".


A common SQL Update syntaxe work perfectly :

$ sqlite3 test.db "UPDATE test SET id=6, name='new_name', age=30 WHERE
id=2;"

$ sqlite3 test.db "SELECT * FROM test;"
0|toto|10
6|new_name|30
6|new_name|30
0|toto|10
6|new_name|30


Good Luck

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


[sqlite] SQL Syntax To Copy A Table

2015-03-30 Thread Dominique Devienne
On Thu, Mar 26, 2015 at 4:29 PM, Nigel Verity 
wrote:

> My requirement is to take periodic snapshots of a names and addresses
> table, to be stored in the same database as the master.
>

Perhaps also look into https://www.sqlite.org/backup.html, which doesn't
qualify for "the same database", but seems closer to the spirit of your
requirement. --DD


[sqlite] SQL Syntax To Copy A Table

2015-03-29 Thread Maurizio Trevisani
I suggest to use the CloneTable function
Have a look at
https://www.gaia-gis.it/fossil/libspatialite/wiki?name=CloneTable

It copies the table and all of its triggers, indexes, etc.

Maurizio

2015-03-26 16:35 GMT+01:00, John McKown :
> On Thu, Mar 26, 2015 at 10:29 AM, Nigel Verity 
> wrote:
>> Hi
>>
>> I know this must seem a fairly dumb question, but I can't find an easy way
>> to create a copy of table using just SQL.
>>
>> My requirement is to take periodic snapshots of a names and addresses
>> table, to be stored in the same database as the master.
>>
>> The master table has one index - an auto-incrementing integer ID (non
>> NULL, primary key). There is no need for the corresponding field in the
>> snapshot to be indexed, but the integer ID does need to be copied across.
>>
>> I'm happy to copy the table structure in one operation and the data in
>> another, but if it can be done in a single operation so much the better.
>
> You could use _two_ statements like:
>
> DROP TABLE IF EXISTS copy_of_bubba;
> CREATE TABLE copy_of_bubba AS SELECT * FROM bubba;
>
>>
>> Thanks
>>
>> Nige
>>
>>
>>
>> ___
>> sqlite-users mailing list
>> sqlite-users at mailinglists.sqlite.org
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>
>
> --
> If you sent twitter messages while exploring, are you on a textpedition?
>
> He's about as useful as a wax frying pan.
>
> 10 to the 12th power microphones = 1 Megaphone
>
> Maranatha! <><
> John McKown
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


[sqlite] SQL Syntax To Copy A Table

2015-03-26 Thread Martin Engelschalk
Hi Nige,

create table  as select * from 

See also http://www.sqlite.org/lang_createtable.html

Martin

Am 26.03.2015 um 16:29 schrieb Nigel Verity:
> Hi
>
> I know this must seem a fairly dumb question, but I can't find an easy way to 
> create a copy of table using just SQL.
>
> My requirement is to take periodic snapshots of a names and addresses table, 
> to be stored in the same database as the master.
>
> The master table has one index - an auto-incrementing integer ID (non NULL, 
> primary key). There is no need for the corresponding field in the snapshot to 
> be indexed, but the integer ID does need to be copied across.
>
> I'm happy to copy the table structure in one operation and the data in 
> another, but if it can be done in a single operation so much the better.
>
> Thanks
>
> Nige
>
>
>   
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

-- 

*Codeswift GmbH *
Kr?utlerweg 20a
A-5020 Salzburg
Tel: +49 (0) 8662 / 494330
Mob: +49 (0) 171 / 4487687
Fax: +49 (0) 3212 / 1001404
engelschalk at codeswift.com
www.codeswift.com / www.swiftcash.at

Codeswift Professional IT Services GmbH
Firmenbuch-Nr. FN 202820s
UID-Nr. ATU 50576309



[sqlite] SQL Syntax To Copy A Table

2015-03-26 Thread Nigel Verity
Hi

I know this must seem a fairly dumb question, but I can't find an easy way to 
create a copy of table using just SQL.

My requirement is to take periodic snapshots of a names and addresses table, to 
be stored in the same database as the master.

The master table has one index - an auto-incrementing integer ID (non NULL, 
primary key). There is no need for the corresponding field in the snapshot to 
be indexed, but the integer ID does need to be copied across.

I'm happy to copy the table structure in one operation and the data in another, 
but if it can be done in a single operation so much the better.

Thanks

Nige





[sqlite] SQL Syntax To Copy A Table

2015-03-26 Thread John McKown
On Thu, Mar 26, 2015 at 10:29 AM, Nigel Verity  
wrote:
> Hi
>
> I know this must seem a fairly dumb question, but I can't find an easy way to 
> create a copy of table using just SQL.
>
> My requirement is to take periodic snapshots of a names and addresses table, 
> to be stored in the same database as the master.
>
> The master table has one index - an auto-incrementing integer ID (non NULL, 
> primary key). There is no need for the corresponding field in the snapshot to 
> be indexed, but the integer ID does need to be copied across.
>
> I'm happy to copy the table structure in one operation and the data in 
> another, but if it can be done in a single operation so much the better.

You could use _two_ statements like:

DROP TABLE IF EXISTS copy_of_bubba;
CREATE TABLE copy_of_bubba AS SELECT * FROM bubba;

>
> Thanks
>
> Nige
>
>
>
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



-- 
If you sent twitter messages while exploring, are you on a textpedition?

He's about as useful as a wax frying pan.

10 to the 12th power microphones = 1 Megaphone

Maranatha! <><
John McKown


Re: [sqlite] sql syntax grammar: single-source

2011-04-05 Thread Vitali Kiruta
> This currently works.  But because it is not part of the language spec, we
> do not guarantee that we will continue to support it.

Thanks a lot for quick answer.
Do you mean the sqlite language spec, or the sql standard?

I would be very much in favor of keeping this behavior. It makes
select statement more modular and simplifies sql code generation.

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


Re: [sqlite] sql syntax grammar: single-source

2011-04-05 Thread Richard Hipp
On Tue, Apr 5, 2011 at 8:30 AM, Vitali Kiruta  wrote:

> Hi everybody,
>
> I hope somebody could clarify this for me. According to the sql
> grammar definition, the single-source production
> does not allow the table-alias after the join-source
>
> See http://www.sqlite.org/syntaxdiagrams.html#single-source
>
> However, when I'm trying to run this query it works just fine:
>
> select t.* from (t1 join t2) as t;
>
> Is it an oversight in the definition or am I missing something?
>

This currently works.  But because it is not part of the language spec, we
do not guarantee that we will continue to support it.


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



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


[sqlite] sql syntax grammar: single-source

2011-04-05 Thread Vitali Kiruta
Hi everybody,

I hope somebody could clarify this for me. According to the sql
grammar definition, the single-source production
does not allow the table-alias after the join-source

See http://www.sqlite.org/syntaxdiagrams.html#single-source

However, when I'm trying to run this query it works just fine:

select t.* from (t1 join t2) as t;

Is it an oversight in the definition or am I missing something?

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


Re: [sqlite] SQL syntax diagrams

2010-01-15 Thread D. Richard Hipp

On Jan 15, 2010, at 9:10 AM, Andy Gibbs wrote:

>
> Hi,
>
> I really like the way the SQL syntax diagrams are done (e.g. at 
> http://www.sqlite.org/syntaxdiagrams.html) 
> .  What software did you use for it?
>

http://wiki.tcl.tk/21708

Also:

http://www.sqlite.org/faq.html#q25 and 
http://www.sqlite.org/search?q=syntax+diagrams


D. Richard Hipp
d...@hwaci.com



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


Re: [sqlite] SQL syntax diagrams

2010-01-15 Thread Dan Kennedy

On Jan 15, 2010, at 9:10 PM, Andy Gibbs wrote:

>
> Hi,
>
> I really like the way the SQL syntax diagrams are done (e.g. at 
> http://www.sqlite.org/syntaxdiagrams.html) 
> .  What software did you use for it?

http://wiki.tcl.tk/21708

>
> Regards
> Andy
>   
> _
> We want to hear all your funny, exciting and crazy Hotmail stories.  
> Tell us now
> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> ___
> 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


[sqlite] SQL syntax diagrams

2010-01-15 Thread Andy Gibbs

Hi,

I really like the way the SQL syntax diagrams are done (e.g. at 
http://www.sqlite.org/syntaxdiagrams.html).  What software did you use for it?

Regards
Andy
  
_
We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now
http://clk.atdmt.com/UKM/go/195013117/direct/01/
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQL Syntax

2009-07-09 Thread Rick Ratchford


Cheers!
 
Rick Ratchford
ProfitMax Trading Inc. 
http://www.amazingaccuracy.com
 
 

#>-Original Message-
#>From: sqlite-users-boun...@sqlite.org 
#>[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Igor Tandetnik
#>Sent: Thursday, July 09, 2009 1:15 PM
#>To: sqlite-users@sqlite.org
#>Subject: Re: [sqlite] SQL Syntax
#>
#>Rick Ratchford 
#>wrote:
#>> select
#>>(select min(Year) ...) as firstFullYear,
#>>(select max(Year) ...) as lastFullYear;
#>>
#>> If I go with the condensed version you illustrate above, I 
#>assume that 
#>> I would then need to use the LIMIT clause, right? When I 
#>tried it, I 
#>> get a bunch of rows returned, all with the same information.
#>>
#>> 1988  2008
#>> 1988  2008
#>> 1988  2008
#>> 1988  2008
#>> 1988  2008
#>> 1988  2008
#>> ...
#>>
#>> Here is the SQL used:
#>>
#>> Select (Select min(Year) From TmpTable Where Month=1 and Day<8) as 
#>> FirstYear,
#>>   (Select max(Year) From TmpTable Where Month=12 and Day>24) as 
#>> LastYear FROM TmpTable"
#>
#>Do you see a FROM clause in my example?
#>
#>Igor Tandetnik 
#>


select
   (select min(Year) ...) as firstFullYear,
   (select max(Year) ...) as lastFullYear;

When I saw the '...', I assumed this was just a partial example and that I
was to fill in the rest. Because I'm still a real newbie at this, I didn't
realize that a 'select' does not always need to be followed by a table name.
I feel like a real dummy now. :-&

Thanks again.

Rick




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


Re: [sqlite] SQL Syntax

2009-07-09 Thread Igor Tandetnik
Rick Ratchford 
wrote:
> select
>(select min(Year) ...) as firstFullYear,
>(select max(Year) ...) as lastFullYear;
>
> If I go with the condensed version you illustrate above, I assume
> that I would then need to use the LIMIT clause, right? When I tried
> it, I get a bunch of rows returned, all with the same information.
>
> 1988  2008
> 1988  2008
> 1988  2008
> 1988  2008
> 1988  2008
> 1988  2008
> ...
>
> Here is the SQL used:
>
> Select (Select min(Year) From TmpTable Where Month=1 and Day<8) as
> FirstYear,
>   (Select max(Year) From TmpTable Where Month=12 and Day>24) as
> LastYear FROM TmpTable"

Do you see a FROM clause in my example?

Igor Tandetnik 



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


Re: [sqlite] SQL Syntax

2009-07-09 Thread Rick Ratchford

Rick Ratchford wrote:
> Okay, this worked, but I have NO IDEA why.
>
>SQLString = "SELECT min(Year) FROM TmpTable " & _
>"WHERE Month=1 UNION " & _
>"SELECT max(Year) FROM TmpTable " & _
>"WHERE Month = 12 LIMIT 2"

Read about aggregate functions (min() is one of those) in your favorite SQL
textbook, then drop the LIMIT clause. You may also want to use UNION ALL
instead of UNION: otherwise, if you just have one full year's worth of data,
you'll get a single row as UNION removes duplicates.

In fact, it may be more convenient (definitely easier to reuse as a fragment
in more complicated queries) to return this result as one row with two
columns:

select
(select min(Year) ...) as firstFullYear,
(select max(Year) ...) as lastFullYear;

Igor Tandetnik 



Igor,

If I go with the condensed version you illustrate above, I assume that I
would then need to use the LIMIT clause, right? When I tried it, I get a
bunch of rows returned, all with the same information.

1988  2008
1988  2008
1988  2008
1988  2008
1988  2008
1988  2008
...

Here is the SQL used:

Select (Select min(Year) From TmpTable Where Month=1 and Day<8) as
FirstYear,
   (Select max(Year) From TmpTable Where Month=12 and Day>24) as
LastYear FROM TmpTable"


LIMIT 1 ??

Thanks.
Rick



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


Re: [sqlite] SQL Syntax

2009-07-09 Thread Rick Ratchford
Rick Ratchford wrote:
> Okay, this worked, but I have NO IDEA why.
>
>SQLString = "SELECT min(Year) FROM TmpTable " & _
>"WHERE Month=1 UNION " & _
>"SELECT max(Year) FROM TmpTable " & _
>"WHERE Month = 12 LIMIT 2"

Read about aggregate functions (min() is one of those) in your favorite SQL
textbook, then drop the LIMIT clause. You may also want to use UNION ALL
instead of UNION: otherwise, if you just have one full year's worth of data,
you'll get a single row as UNION removes duplicates.

In fact, it may be more convenient (definitely easier to reuse as a fragment
in more complicated queries) to return this result as one row with two
columns:

select
(select min(Year) ...) as firstFullYear,
(select max(Year) ...) as lastFullYear;

>Igor Tandetnik 
-
SQLString =  "SELECT min(Year) FROM TmpTable " & _
 "WHERE Month=1 And Day<8 " & _
 "UNION ALL " & _
 "SELECT max(Year) FROM TmpTable " & _
 "WHERE Month = 12 And Day>24 "


This should limit it to looking for something in the first week and last
week.

David

-

 Noobie here 

I think the min and max functions by design return only one value.

However, I'm afraid this query might not work in the general case.

For example, if your data starts on january 20, 1988, then this query will
think 1988 is a full year. Ditto if the data ends early in december.

So it seems to me that it works for you by luck, because your data set
doesn't start in january, nor ends in december.

Unless of course if I am totally wrong, which happens often enough.

Jean-Denis Muys

-

In one message, I'd like to thank you all for your help (Igor, David,
Jean-Denis, ...).

Igor, that's a good precaution to use UNION ALL, although in case of my code
this would never happen since it has a minimum 5 years of data requirement
even to run the procedure. Thanks for that pointer as well as the idea to
condense by reply by having both years appear in one row. I've not reached
the point in my 'book' where you group 'select' inside 'select' using
parenthesis. Yours was actually the first time I've seen it. Thanks. :)

David, thanks for your input on the addition of Day <>. :)

Jean-Denis, newbie or not, thanks for your input. I did note this and had
originally placed a Day < 5 for the beginning year and Day > 28 for the last
year. But with all the tweeking I was doing to this, some things dropped,
some added... I'll use David's 'first week, last week' numbers for the
final.

Thanks guys.

Rick







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


Re: [sqlite] SQL Syntax

2009-07-09 Thread David Bicking
On Thu, 2009-07-09 at 10:47 +0200, Jean-Denis Muys wrote:
> On 7/9/09 6:21 , "Rick Ratchford"  wrote:
> 
> >  
> > Okay, this worked, but I have NO IDEA why.
> > 
> > SQLString = "SELECT min(Year) FROM TmpTable " & _
> > "WHERE Month=1 UNION " & _
> > "SELECT max(Year) FROM TmpTable " & _
> > "WHERE Month = 12 LIMIT 2"
> > 
> > 
> > While this returned the correct answers:
> > 
> > 1988
> > 2008
> > 
> > 

> 
> However, I'm afraid this query might not work in the general case.
> 
> For example, if your data starts on january 20, 1988, then this query will
> think 1988 is a full year. Ditto if the data ends early in december.
> 
> So it seems to me that it works for you by luck, because your data set
> doesn't start in january, nor ends in december.
> 

SQLString =  "SELECT min(Year) FROM TmpTable " & _
 "WHERE Month=1 And Day<8 " & _
 "UNION ALL " & _
 "SELECT max(Year) FROM TmpTable " & _
 "WHERE Month = 12 And Day>24 "


This should limit it to looking for something in the first week and last week.

David


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


Re: [sqlite] SQL Syntax

2009-07-09 Thread Igor Tandetnik
Rick Ratchford wrote:
> Okay, this worked, but I have NO IDEA why.
>
>SQLString = "SELECT min(Year) FROM TmpTable " & _
>"WHERE Month=1 UNION " & _
>"SELECT max(Year) FROM TmpTable " & _
>"WHERE Month = 12 LIMIT 2"

Read about aggregate functions (min() is one of those) in your favorite 
SQL textbook, then drop the LIMIT clause. You may also want to use UNION 
ALL instead of UNION: otherwise, if you just have one full year's worth 
of data, you'll get a single row as UNION removes duplicates.

In fact, it may be more convenient (definitely easier to reuse as a 
fragment in more complicated queries) to return this result as one row 
with two columns:

select
(select min(Year) ...) as firstFullYear,
(select max(Year) ...) as lastFullYear;

Igor Tandetnik 



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


Re: [sqlite] SQL Syntax

2009-07-09 Thread Jean-Denis Muys

On 7/9/09 6:21 , "Rick Ratchford"  wrote:

>  
> Okay, this worked, but I have NO IDEA why.
> 
> SQLString = "SELECT min(Year) FROM TmpTable " & _
> "WHERE Month=1 UNION " & _
> "SELECT max(Year) FROM TmpTable " & _
> "WHERE Month = 12 LIMIT 2"
> 
> 
> While this returned the correct answers:
> 
> 1988
> 2008
> 
> What I don't understand is why it didn't simply return:
> 
> 1988
> 1988
> 
> Since there is at least 15 or more days in Month=1 (Jan).
> 
> Anyone?
> 

 Noobie here 

I think the min and max functions by design return only one value.

However, I'm afraid this query might not work in the general case.

For example, if your data starts on january 20, 1988, then this query will
think 1988 is a full year. Ditto if the data ends early in december.

So it seems to me that it works for you by luck, because your data set
doesn't start in january, nor ends in december.

Unless of course if I am totally wrong, which happens often enough.

Jean-Denis Muys

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


Re: [sqlite] SQL Syntax

2009-07-08 Thread John Machin
On 9/07/2009 2:21 PM, Rick Ratchford wrote:
>  
> Okay, this worked, but I have NO IDEA why.
> 
> SQLString = "SELECT min(Year) FROM TmpTable " & _
> "WHERE Month=1 UNION " & _
> "SELECT max(Year) FROM TmpTable " & _
> "WHERE Month = 12 LIMIT 2"
> 
> 
> While this returned the correct answers:
> 
> 1988
> 2008
> 
> What I don't understand is why it didn't simply return:
> 
> 1988
> 1988
> 
> Since there is at least 15 or more days in Month=1 (Jan).
> 
> Anyone?
> 
> Thanks.
> Rick
> 
> 
> 
> Original Message-
> From: sqlite-users-boun...@sqlite.org
> [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Rick Ratchford
> Sent: Wednesday, July 08, 2009 11:17 PM
> To: 'General Discussion of SQLite Database'
> Subject: [sqlite] SQL Syntax
> 
> I've been trying all kinds of different ways to accomplish the following,
> and my head is spinning.
>  
> Problem: How do you return from the DB just the YEAR of the first and last
> YEAR that had dates from 1st week  of January to last week of December?
>  
> Clarification: Suppose you had a database that contained stock price data.
> You are only interested in the first and last year that was a complete year.
>  
> A "complete year" is a year where you have price data from the very first
> weekday (not weekend or holiday) of the year to the very last weekday of
> that year. Usually, a complete year is from Jan 2, 3 or 4 to Dec 29, 30, 31.
>  
>  
> Result Desired: To simply return the YEAR of the first complete year, and
> the YEAR of the last complete year of the dataset. This should return only
> two years in a single column. If 1988 is the first complete year and 2008 is
> the last complete year, then it should only return:
>  
> 1988
> 2008
>  
> Available columns are:
>  
> DATE (complete date)
> YEAR
> MONTH
> DAY
> ...
>  
>  
> I'm trying to do something like this, but it won't work because it says you
> can only have one LIMIT clause.
>  
> SQLString = "SELECT min(Year) FROM TmpTable " & _
> "WHERE Month=1 LIMIT 1 UNION " & _
> "SELECT max(Year) FROM TmpTable " & _
> "WHERE Month = 12 LIMIT 1"
> 
> Help would be appreciated.
>  
Each SELECT will return only 1 result. Split that up into 2 queries 
(omit the LIMIT clause; it's redundant) and see for yourself.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQL Syntax

2009-07-08 Thread Rick Ratchford
 
Okay, this worked, but I have NO IDEA why.

SQLString = "SELECT min(Year) FROM TmpTable " & _
"WHERE Month=1 UNION " & _
"SELECT max(Year) FROM TmpTable " & _
"WHERE Month = 12 LIMIT 2"


While this returned the correct answers:

1988
2008

What I don't understand is why it didn't simply return:

1988
1988

Since there is at least 15 or more days in Month=1 (Jan).

Anyone?

Thanks.
Rick



Original Message-
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Rick Ratchford
Sent: Wednesday, July 08, 2009 11:17 PM
To: 'General Discussion of SQLite Database'
Subject: [sqlite] SQL Syntax

I've been trying all kinds of different ways to accomplish the following,
and my head is spinning.
 
Problem: How do you return from the DB just the YEAR of the first and last
YEAR that had dates from 1st week  of January to last week of December?
 
Clarification: Suppose you had a database that contained stock price data.
You are only interested in the first and last year that was a complete year.
 
A "complete year" is a year where you have price data from the very first
weekday (not weekend or holiday) of the year to the very last weekday of
that year. Usually, a complete year is from Jan 2, 3 or 4 to Dec 29, 30, 31.
 
 
Result Desired: To simply return the YEAR of the first complete year, and
the YEAR of the last complete year of the dataset. This should return only
two years in a single column. If 1988 is the first complete year and 2008 is
the last complete year, then it should only return:
 
1988
2008
 
Available columns are:
 
DATE (complete date)
YEAR
MONTH
DAY
...
 
 
I'm trying to do something like this, but it won't work because it says you
can only have one LIMIT clause.
 
SQLString = "SELECT min(Year) FROM TmpTable " & _
"WHERE Month=1 LIMIT 1 UNION " & _
"SELECT max(Year) FROM TmpTable " & _
"WHERE Month = 12 LIMIT 1"

Help would be appreciated.
 
Thanks.
 
Rick
 
___
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


[sqlite] SQL Syntax

2009-07-08 Thread Rick Ratchford
I've been trying all kinds of different ways to accomplish the following,
and my head is spinning.
 
Problem: How do you return from the DB just the YEAR of the first and last
YEAR that had dates from 1st week  of January to last week of December?
 
Clarification: Suppose you had a database that contained stock price data.
You are only interested in the first and last year that was a complete year.
 
A "complete year" is a year where you have price data from the very first
weekday (not weekend or holiday) of the year to the very last weekday of
that year. Usually, a complete year is from Jan 2, 3 or 4 to Dec 29, 30, 31.
 
 
Result Desired: To simply return the YEAR of the first complete year, and
the YEAR of the last complete year of the dataset. This should return only
two years in a single column. If 1988 is the first complete year and 2008 is
the last complete year, then it should only return:
 
1988
2008
 
Available columns are:
 
DATE (complete date)
YEAR
MONTH
DAY
...
 
 
I'm trying to do something like this, but it won't work because it says you
can only have one LIMIT clause.
 
SQLString = "SELECT min(Year) FROM TmpTable " & _
"WHERE Month=1 LIMIT 1 UNION " & _
"SELECT max(Year) FROM TmpTable " & _
"WHERE Month = 12 LIMIT 1"

Help would be appreciated.
 
Thanks.
 
Rick
 
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] SQL syntax issue?

2007-02-08 Thread Sherlock, Ric
I've come across the following SQL syntax issue in Sqlite that is maybe
a bug (or maybe just a product of my poor SQL knowledge!)
I have a database that from the command line will execute the following
statement fine:

SELECT clients.cl_lname, clients.cl_title, price_profiles.pp_year
FROM clients LEFT JOIN price_profiles ON clients.cl_id =
price_profiles.pp_client

But gives and error with the following statement (it will run fine on
the same tables in Access)

  SELECT clients.cl_lname, clients.cl_title, price_profiles.pp_year,
prices.pr_mfd, prices.pr_price
  FROM (clients LEFT JOIN price_profiles ON clients.cl_id =
price_profiles.pp_client) LEFT JOIN prices ON price_profiles.pp_id =
prices.pr_pp

  SQL error: no such column: clients.cl_lname

If I remove the table part of all the column names (luckily the column
names are unique) then the statement will execute with no problems.

  SELECT cl_lname, cl_title, pp_year, pr_mfd, pr_price
  FROM (clients LEFT JOIN price_profiles ON cl_id = pp_client) LEFT JOIN
prices ON pp_id = pr_pp

Is this behaviour expected in Sqlite? Is there an alternative format I
should use in the above case?

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] SQL syntax possibilities

2005-11-16 Thread roger


>  Original Message 
> Subject: Re: [sqlite] SQL syntax possibilities
> From: Darren Duncan <[EMAIL PROTECTED]>
> Date: Wed, November 16, 2005 10:41 pm
> To: sqlite-users@sqlite.org
> 
> At 1:34 AM -0700 11/16/05, [EMAIL PROTECTED] wrote:
> >uSQLite does not (generally) enter into the details of the query it is
> >passed. There is however an exception for security. uSQLite requires a
> >login and (depending on the user and network) assigns the user a level:
> >
> >0: No access
> >1: Select only
> >2: Update/Insert only
> >3: Select/Update/Insert only
> >4: Power user
> 
> Maybe your list wasn't complete, but I notice that 'Delete' is 
> conspicuously absent, yet it is necessary to do many common tasks.
> 

Yes, you could reason that delete should be at level 3. I started of
with Read only or read/write and added 2 because it is appropriate for
remote automated data insertion, which is a prime application of the
protocol. I did 3 and 4 to seperate nervous users form confident
users:-) Perhaps it is just the way I define databases, but I find
delete little use in normal operations, I keep everything :-)

Having said that, I also kept things simple to mimimise the
complications of parsing the SQL, but now I realise I can leave that to
SQL by means of the authorise callback, I may let a few extra levels
creep in or more likely do a bit field. Keeping remote access within
necessary limits is just good sense.

I agree with you about the damage causable by UPDATE however. I have
long felt that SQL should make WHERE clauses obigatory. The UPDATE is
particularly terrible as it is very easy to hit return prematurly after
completing the values. IMHO, if you want to operate on all records then
it should be necessary to put a WHERE ALL clause or something.

Would a PRAGMA FORCE_WHERE option in SQLite be considered feature creep?
Perhaps some notion allready exists, I am no expert on SQL syntax and
standards.









Re: [sqlite] SQL syntax possibilities

2005-11-16 Thread Darren Duncan

At 1:34 AM -0700 11/16/05, [EMAIL PROTECTED] wrote:

uSQLite does not (generally) enter into the details of the query it is
passed. There is however an exception for security. uSQLite requires a
login and (depending on the user and network) assigns the user a level:

0: No access
1: Select only
2: Update/Insert only
3: Select/Update/Insert only
4: Power user


Maybe your list wasn't complete, but I notice that 'Delete' is 
conspicuously absent, yet it is necessary to do many common tasks.


And before you say that it was left out from all but Power User 
because of its possible destructiveness, I would say that Update is 
just as destructive; an Update can blow away anything a Delete can, 
if you say "update ... set foo = 0" for all fields and rows.


I suggest that levels like this make more sense from a security standpoint:

0: No access
1: Select only (read-only)
2: Insert only (non-destructive drop-box)
3: Select/Insert only (fully non-destructive read and write)
4: Select/Insert/Update/Delete only (full read-write data, no ddl)
5: Power User

-- Darren Duncan


RE: [sqlite] SQL syntax possibilities

2005-11-16 Thread roger


>  Original Message 
> Subject: Re: [sqlite] SQL syntax possibilities
> From: Eric Bohlman <[EMAIL PROTECTED]>
> Date: Wed, November 16, 2005 10:54 am
> To: sqlite-users@sqlite.org
> 
> [EMAIL PROTECTED] wrote:
> > uSQLite does not (generally) enter into the details of the query it is
> > passed. There is however an exception for security. uSQLite requires a
> > login and (depending on the user and network) assigns the user a level:
> > 
> > 0: No access
> > 1: Select only
> > 2: Update/Insert only
> > 3: Select/Update/Insert only
> > 4: Power user
> > 
> > These rules are enforced by looking at the first word in a query, the
> > code is at the bottom of this post. My problem is that I allow multiple
> > queries to be concatented, and this is a useful feature for bulk inserts
> > and blocks of queries that must be executed atomicaly (Major hangup is
> > level 2 for remote updates inserts). However, with the present routine
> > I could do eg:
> 
> I think you should look into using SQLite's authorizer callback 
> mechanism; that way you don't have to parse syntax.

Yup. Will do.
Thanks.

(Repeat after me RTFM, RTFM,RTFM...)




Re: [sqlite] SQL syntax possibilities

2005-11-16 Thread Eric Bohlman

[EMAIL PROTECTED] wrote:

uSQLite does not (generally) enter into the details of the query it is
passed. There is however an exception for security. uSQLite requires a
login and (depending on the user and network) assigns the user a level:

0: No access
1: Select only
2: Update/Insert only
3: Select/Update/Insert only
4: Power user

These rules are enforced by looking at the first word in a query, the
code is at the bottom of this post. My problem is that I allow multiple
queries to be concatented, and this is a useful feature for bulk inserts
and blocks of queries that must be executed atomicaly (Major hangup is
level 2 for remote updates inserts). However, with the present routine
I could do eg:


I think you should look into using SQLite's authorizer callback 
mechanism; that way you don't have to parse syntax.


[sqlite] SQL syntax possibilities

2005-11-16 Thread roger
uSQLite does not (generally) enter into the details of the query it is
passed. There is however an exception for security. uSQLite requires a
login and (depending on the user and network) assigns the user a level:

0: No access
1: Select only
2: Update/Insert only
3: Select/Update/Insert only
4: Power user

These rules are enforced by looking at the first word in a query, the
code is at the bottom of this post. My problem is that I allow multiple
queries to be concatented, and this is a useful feature for bulk inserts
and blocks of queries that must be executed atomicaly (Major hangup is
level 2 for remote updates inserts). However, with the present routine
I could do eg:

Select 1;Drop table foo

With user level 1. AFAIK it would be sufficient that I modify the
ChekLevel routine such that it will check the first word and each word
that follows a semicolon (but I must also skip quoted semicolons). Is
this correct? Or can anybody think of any scenarios where this would
not work?




int ChekLevel(char *query,int uselevel){
char *cur,*dur;

cur=query;
// strip lead
while((*cur<' ')&&(*cur))cur++;


// strncasecmp is the same as strncmp except that
// it ignores case. It is a GNU extension to the
// Clib which many other libs have.
if(!strncasecmp(cur,"SELECT",6))
return (uselevel<1)||(uselevel==2)?0:1;

if(!strncasecmp(cur,"UPDATE",6))
return uselevel<2? 0:1;

if(!strncasecmp(cur,"INSERT",6))
return uselevel<2? 0:1;

return uselevel<4? 0:1;
}



RE: [sqlite] SQL syntax - please help

2005-07-03 Thread Dennis Volodomanov
Ok, thank you Darren. It's good to know that, so I don't waste time
trying to implement something that doesn't exist :-) 

Are there plans to implement this sometime in the future?

   Dennis

-Original Message-
From: Darren Duncan [mailto:[EMAIL PROTECTED] 
Sent: Friday, 1 July 2005 7:31 PM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] SQL syntax - please help

I don't think that SQLite supports what you want yet.

As soon as the SQL:2003 "WITH RECURSIVE ... SELECT ..." syntax is
supported, you should be able to do what you want elegantly.

Meanwhile, you will have to do multiple selects to work with N
recursions.

-- Darren Duncan



Re: [sqlite] SQL syntax - please help

2005-07-01 Thread Darren Duncan

I don't think that SQLite supports what you want yet.

As soon as the SQL:2003 "WITH RECURSIVE ... SELECT ..." syntax is 
supported, you should be able to do what you want elegantly.


Meanwhile, you will have to do multiple selects to work with N recursions.

-- Darren Duncan

At 5:10 PM +1000 7/1/05, Dennis Volodomanov wrote:

Hello all,

I'm trying to form a specific query, but not sure if that's possible at
all and if it is, how it should look like. I'd really appreciate your
help :-)

I have 2 tables (simplest case, but once I know this, I can work out the
rest):

CREATE TABLE TableA(
   UID INTEGER PRIMARY KEY,
   Text,
   PARENTTABLEID,
   RECORDID)

CREATE TABLE TableMain(
   UID INTEGER PRIMARY KEY,
   Text)

Where TableA's RECORDID is in fact the UID of TableMain and
PARENTTABLEID can be filled with TableA's UID to show hierarchical
relationship, so they can go like this:

TableMain
   |--- TableA
 |--- TableA

Ok, I need to search through the Text field, so for simple tables I had
this (filing with appropriate data of course using sqlite3_mprintf()
function):

SELECT * FROM TableMain WHERE Text LIKE '%%%q%%'

and I had UNION if I needed to search on more than one field. So far so
good, but now I have this hierarchy of TableA's, that also need to be
searched through, and I'd like to have one SQL statement that does it,
if possible.

I'd like to know if I can do something like this (incorrect, but to show
the idea):

SELECT * FROM TableMain WHERE Text  LIKE 'x' UNION SELECT * FROM TableA
WHERE TableA.RECORDID=TableMain.UID AND Text LIKE 'x'

??? (and how could I go through recursive TableA's?)

Thank you for reading this :-)

I'd appreciate any comments, and I'd like to know if this is possible at
all.

Regards,

   Dennis




[sqlite] SQL syntax - please help

2005-07-01 Thread Dennis Volodomanov
Hello all,
 
I'm trying to form a specific query, but not sure if that's possible at
all and if it is, how it should look like. I'd really appreciate your
help :-)
 
I have 2 tables (simplest case, but once I know this, I can work out the
rest):
 
CREATE TABLE TableA(
   UID INTEGER PRIMARY KEY,
   Text,
   PARENTTABLEID,
   RECORDID)
 
CREATE TABLE TableMain(
   UID INTEGER PRIMARY KEY,
   Text)
 
Where TableA's RECORDID is in fact the UID of TableMain and
PARENTTABLEID can be filled with TableA's UID to show hierarchical
relationship, so they can go like this:
 
TableMain
   |--- TableA
 |--- TableA
 
Ok, I need to search through the Text field, so for simple tables I had
this (filing with appropriate data of course using sqlite3_mprintf()
function):
 
SELECT * FROM TableMain WHERE Text LIKE '%%%q%%'
 
and I had UNION if I needed to search on more than one field. So far so
good, but now I have this hierarchy of TableA's, that also need to be
searched through, and I'd like to have one SQL statement that does it,
if possible.
 
I'd like to know if I can do something like this (incorrect, but to show
the idea):
 
SELECT * FROM TableMain WHERE Text  LIKE 'x' UNION SELECT * FROM TableA
WHERE TableA.RECORDID=TableMain.UID AND Text LIKE 'x'
 
??? (and how could I go through recursive TableA's?)
 
Thank you for reading this :-)
 
I'd appreciate any comments, and I'd like to know if this is possible at
all.
 
Regards,
 
   Dennis


Re: [sqlite] SQL Syntax from 2.8 to 3.0 not backward compatible?

2004-06-25 Thread Guillaume Fougnies
Ok.
Perhaps it should be written in the documentation of
"SQLite Version 3" or in the chapter "Transaction Control At The SQL
Level" of the "Locking And Concurrency In SQLite Version 3".

Thanks.
bye.

Fri, Jun 25, 2004 at 04:22:10AM -0700: Daniel K wrote:
> A BEGIN cannot have an ON CONFLICT clause in sqlite
> version 3.
>
> Dan.
>
>
> --- Guillaume Fougnies <[EMAIL PROTECTED]> wrote:
> > Here is it:
> >
> > SQLite version 3.0.1
> > Enter ".help" for instructions
> > sqlite> BEGIN TRANSACTION ON CONFLICT ROLLBACK;
> > SQL error: near "ON": syntax error
> >
> > bye.

--
Guillaume FOUGNIES

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



Re: [sqlite] SQL Syntax from 2.8 to 3.0 not backward compatible?

2004-06-25 Thread Daniel K
A BEGIN cannot have an ON CONFLICT clause in sqlite
version 3.

Dan.


--- Guillaume Fougnies <[EMAIL PROTECTED]> wrote:
> Here is it:
> 
> SQLite version 3.0.1
> Enter ".help" for instructions
> sqlite> BEGIN TRANSACTION ON CONFLICT ROLLBACK;
> SQL error: near "ON": syntax error
> 
> bye.
> --
> Guillaume FOUGNIES
> 
>
-
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 





__
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 

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



[sqlite] SQL Syntax from 2.8 to 3.0 not backward compatible?

2004-06-25 Thread Guillaume Fougnies
Here is it:

SQLite version 3.0.1
Enter ".help" for instructions
sqlite> BEGIN TRANSACTION ON CONFLICT ROLLBACK;
SQL error: near "ON": syntax error

bye.
--
Guillaume FOUGNIES

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



[sqlite] SQL syntax

2004-06-21 Thread aducom
Is there a document describing changes in sql statements, especially on 
pragma's? Which pragma's are understood?

Albert

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



RE: [sqlite] SQL Syntax checker?

2004-05-05 Thread Keith Herold
Doesn't sqlite have a function for doing this?  It only checks SQLite-92
stuff, I think.

You could always roll one from the spec using (f)lex and yacc. Or bison, or
.

A quick google showed different parsers in Java, for Delphi and FoxPro, etc.

--Keith

++ 
 [EMAIL PROTECTED] 
 Lead Speech Recognition Engineer 
 Toll-Free: (877) 977 - 0707 
 Phone: (858) 707 - 0707 x238 

 www.LumenVox.com 
 Fax:   (858) 707 - 7072 

 LumenVox, LLC 
 3615 Kearny Villa Rd #202 
 San Diego, CA 92123 
++ 
 

> -Original Message-
> From: Dan Keeley [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, May 05, 2004 2:36 AM
> To: [EMAIL PROTECTED]
> Subject: [sqlite] SQL Syntax checker?
> 
> 
> Hi,
> 
> Not directly sqlite related, but does anyone know of a SQL 
> syntax checker 
> which will check syntax without actually connecting to a db 
> and running the 
> query?
> 
> Thanks!
> Dan
> 
> _
> Express yourself with cool new emoticons 
> http://www.msn.co.uk/specials/myemo
> 
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


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



[sqlite] SQL Syntax checker?

2004-05-05 Thread Dan Keeley
Hi,

Not directly sqlite related, but does anyone know of a SQL syntax checker 
which will check syntax without actually connecting to a db and running the 
query?

Thanks!
Dan
_
Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]