Re: [sqlite] any way to find out how many current connections to db?

2007-08-12 Thread John Stanton

Try using lsof.

Chase wrote:


is there any way (in c/c++) to find out how many current connections 
there are to a database that i am connected to?


i'd like to do some housekeeping on the database every so often, but 
only if there's no one else connected to it at the time.


any ideas?

thanks.

- chase




- 


To unsubscribe, send email to [EMAIL PROTECTED]
- 






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



Re: [sqlite] Help with performance...

2007-08-12 Thread Joe Wilson
Forget about the alternate insert statements I suggested.

Assuming "id" is declared INTEGER PRIMARY KEY in all tables,
you can't get better performance than this in a single
insert statement:

 insert into x select x1.* from a.x x1, y where x1.id = y.id;



   

Be a better Heartthrob. Get better relationship answers from someone who knows. 
Yahoo! Answers - Check it out. 
http://answers.yahoo.com/dir/?link=list=396545433

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



Re: [sqlite] Trying to link static library from my embedded application

2007-08-12 Thread Daniel Berenguer
Thanks Joe!! It works now!!

Daniel.

On Sun, 2007-08-12 at 09:56 -0700, Joe Wilson wrote:
> You probably have another shared sqlite library in your path somewhere.
> 
> Explicitly link with /absolute/directory/to/your/libsqlite.a rather than
> -lsqlite.
> 
> --- Daniel Berenguer <[EMAIL PROTECTED]> wrote:
> > I've downloaded the sqlite-2.8.17 source code in order to create my own
> > static library for my embedded platform (OpenSlug)
> > 
> > source code package:
> > sqlite-source-2_8_17.zip
> > 
> > Ok, I get to cross-compile the static library (libsqlite.a) using this
> > simple makefile:
> > 
> > 
> > include ../Makefile_opnode.in
> > 
> > all: libsqlite.a copy_files
> > 
> > libsqlite.a:: attach.o auth.o btree.o btree_rb.o build.o copy.o date.o
> > delete.o encode.o expr.o func.o hash.o insert.o \
> >  main.o opcodes.o os.o pager.o parse.o pragma.o printf.o
> > random.o select.o table.o tokenize.o trigger.o update.o \
> >  util.o vacuum.o vdbe.o vdbeaux.o where.o
> > $(AR) crv $@ $^
> > copy_files:
> > cp libsqlite.a $(OPENSLUG_LIB_PATH)/
> > cp sqlite.h $(OPENSLUG_INCL_PATH)/opnode/
> > 
> > .PHONY: clean
> > 
> > clean:
> > rm -f *.o *~
> > 
> > 
> > The library seems to be correctly built and my app gets linked to the
> > static library without problems.
> > 
> > The problem comes when I run the application. Then I get this error:
> > 
> > "error while loading shared libraries: libsqlite.so.0: cannot open
> > shared object file: No such file or directory"
> > 
> > But I don't want to dinamically load the library... Any idea out there?
> 
> 
> 
>   
> 
> Shape Yahoo! in your own image.  Join our Network Research Panel today!   
> http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 
> 
> 
> 
> -
> To unsubscribe, send email to [EMAIL PROTECTED]
> -
> 


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



Re: [sqlite] Help with performance...

2007-08-12 Thread Joe Wilson
--- Joe Wilson <[EMAIL PROTECTED]> wrote:
> This should be faster:
> 
>  insert into x 
>   select * from a.x x1
>   where exists (select 1 from Y where x1.id = y.id);
> 
> See if adding an order by statement will make it faster by speeding
> up the inserts:
> 
>  insert into x 
>   select * from a.x x1
>   where exists (select 1 from Y where x1.id = y.id)
>   order by x1.id;

The last statement could be a bit faster if pragma temp_store = memory
- assuming the intermediate select result set can fit into memory.



  

Shape Yahoo! in your own image.  Join our Network Research Panel today!   
http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 



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



Re: [sqlite] Help with performance...

2007-08-12 Thread Joe Wilson
This should be faster:

 insert into x 
  select * from a.x x1
  where exists (select 1 from Y where x1.id = y.id);

See if adding an order by statement will make it faster by speeding
up the inserts:

 insert into x 
  select * from a.x x1
  where exists (select 1 from Y where x1.id = y.id)
  order by x1.id;

I don't think 1000 records selected and inserted per second is that bad,
but your idea below separating the select from the inserts may very well 
speed it up. For extra speed sort the records in memory by "id" prior 
to inserting them.

malloc()ing is not likely as important to disk seeking in this case.

Time the query on its own without the insert.
Also time everything from a :memory: database just for kicks to see
how much overhead the hard disk introduces.

--- Ken <[EMAIL PROTECTED]> wrote:
>   The id field is also the Primary Key and no other indices exist. I've run 
> the explan query
> plan and they seem optimal,  reading table X, and using an index access into 
> Z. 
>
>   I just had a thought. It seems to me that doing the insert into X select 
> from a.x might be the
> problem. Given that the Master DB is on the same disk as the attached DB.. So 
> effectively
> causing all sorts of seek operations.
>
>   Question does sqlite when doing an insert into X select * from Attached.X, 
> y where x.id =y.id
> operate internally as follows???
> for rows:
>read 1 row from A.X
>Insert row into X
> end row
>
>   If so then I suspect performance could be greatly improved as follows:
>  
>create a large memory buffer say 10,000 rows..
>Select and populate buffer.
>Begin;
>for each row in buffer:
> insert into x
>commit;
>
>   Could the overhead of  memory allocation acount for the variances? Is there 
> any way to pin the
> sqlite allocated pages into the Master DB's cache? Sort of a sub cached 
> allocation so that
> attached DB's do not require malloc/free for memory pages? 
>
>   Ken



  

Park yourself in front of a world of choices in alternative vehicles. Visit the 
Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 

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



Re: [sqlite] Trying to link static library from my embedded application

2007-08-12 Thread Joe Wilson
You probably have another shared sqlite library in your path somewhere.

Explicitly link with /absolute/directory/to/your/libsqlite.a rather than
-lsqlite.

--- Daniel Berenguer <[EMAIL PROTECTED]> wrote:
> I've downloaded the sqlite-2.8.17 source code in order to create my own
> static library for my embedded platform (OpenSlug)
> 
> source code package:
> sqlite-source-2_8_17.zip
> 
> Ok, I get to cross-compile the static library (libsqlite.a) using this
> simple makefile:
> 
> 
> include ../Makefile_opnode.in
> 
> all: libsqlite.a copy_files
> 
> libsqlite.a:: attach.o auth.o btree.o btree_rb.o build.o copy.o date.o
> delete.o encode.o expr.o func.o hash.o insert.o \
>  main.o opcodes.o os.o pager.o parse.o pragma.o printf.o
> random.o select.o table.o tokenize.o trigger.o update.o \
>  util.o vacuum.o vdbe.o vdbeaux.o where.o
>   $(AR) crv $@ $^
> copy_files:
>   cp libsqlite.a $(OPENSLUG_LIB_PATH)/
>   cp sqlite.h $(OPENSLUG_INCL_PATH)/opnode/
> 
> .PHONY: clean
> 
> clean:
>   rm -f *.o *~
> 
> 
> The library seems to be correctly built and my app gets linked to the
> static library without problems.
> 
> The problem comes when I run the application. Then I get this error:
> 
> "error while loading shared libraries: libsqlite.so.0: cannot open
> shared object file: No such file or directory"
> 
> But I don't want to dinamically load the library... Any idea out there?



  

Shape Yahoo! in your own image.  Join our Network Research Panel today!   
http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 



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



Re: [sqlite] Help with performance...

2007-08-12 Thread Ken
Joe, 
   
  Thanks for the reply.
   
  The id field is also the Primary Key and no other indices exist. I've run the 
explan query plan and they seem optimal,  reading table X, and using an index 
access into Z. 
   
  I just had a thought. It seems to me that doing the insert into X select from 
a.x might be the problem. Given that the Master DB is on the same disk as the 
attached DB.. So effectively causing all sorts of seek operations.
   
  Question does sqlite when doing an insert into X select * from Attached.X, y 
where x.id =y.id operate internally as follows???
for rows:
   read 1 row from A.X
   Insert row into X
end row
   
  If so then I suspect performance could be greatly improved as follows:
 
   create a large memory buffer say 10,000 rows..
   Select and populate buffer.
   Begin;
   for each row in buffer:
insert into x
   commit;
   
  Could the overhead of  memory allocation acount for the variances? Is there 
any way to pin the sqlite allocated pages into the Master DB's cache? Sort of a 
sub cached allocation so that attached DB's do not require malloc/free for 
memory pages? 
   
  Ken
  

Joe Wilson <[EMAIL PROTECTED]> wrote:
  Not much you can do.
You could examine the output of EXPLAIN QUERY PLAN for those statements.

Hard to know without knowing the schema, but try making the "id" an 
INTEGER PRIMARY KEY, assuming it's appropriate for your data.

Try to have as few indexes as possible on the table being inserted into.

--- Ken wrote:
> I'm looking for your help solving a performance issue:
> 
> Master db and an attached db. called A
> 
> Table x and table Y are identical in both the master and Attached database.
> table Z is built to determine the set of rows to copy and has an index on the 
> id field.
> 
> The goal is to move data from many attached db's to the master.
> 
> SQL statements:
> Begin;
> insert into x 
> select x1.* from a.x x1 , Y
> where x1.id = y.id ;
> commit;
> takes 4.08 seconds to move 3904 rows.
> 
> begin;
> insert into y 
> select y1.* from a.x y1 , Y
> where y1.id = y.id ;
> commit;
> Takes 2.19 seconds to move 2676 rows.
> 
> So X is moved at 922 r/s and y is moved at 1221 r/s.
> Table X has 16 columns and no blobs
> Table Y has 22 columns one of which is a blob.
> 
> All columns are integers except for the blob on table y.
> 
> So why is the X copy performance 25% slower than Y ?
> 
> Page size is 4k.
> Cache size is 4000.
> locking_mode = exclusive.
> Synchronous off
> 
> Is there any way to disable journaling? 
> I can always re-create the DB should anything fail. 
> 
> Any other ideas on how to make this run quicker?
> 
> Thanks,
> Ken





Building a website is a piece of cake. Yahoo! Small Business gives you all the 
tools to get online.
http://smallbusiness.yahoo.com/webhosting 

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




[sqlite] Trying to link static library from my embedded application

2007-08-12 Thread Daniel Berenguer
Hi all,

I've downloaded the sqlite-2.8.17 source code in order to create my own
static library for my embedded platform (OpenSlug)

source code package:
sqlite-source-2_8_17.zip

Ok, I get to cross-compile the static library (libsqlite.a) using this
simple makefile:


include ../Makefile_opnode.in

all: libsqlite.a copy_files

libsqlite.a:: attach.o auth.o btree.o btree_rb.o build.o copy.o date.o
delete.o encode.o expr.o func.o hash.o insert.o \
 main.o opcodes.o os.o pager.o parse.o pragma.o printf.o
random.o select.o table.o tokenize.o trigger.o update.o \
 util.o vacuum.o vdbe.o vdbeaux.o where.o
$(AR) crv $@ $^
copy_files:
cp libsqlite.a $(OPENSLUG_LIB_PATH)/
cp sqlite.h $(OPENSLUG_INCL_PATH)/opnode/

.PHONY: clean

clean:
rm -f *.o *~


The library seems to be correctly built and my app gets linked to the
static library without problems.

The problem comes when I run the application. Then I get this error:

"error while loading shared libraries: libsqlite.so.0: cannot open
shared object file: No such file or directory"

But I don't want to dinamically load the library... Any idea out there?

Thanks,

Daniel.


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



Re: [sqlite] Query has problems with string that looks like a number

2007-08-12 Thread Christopher Backhouse
OK, that fixes it on the commandline. Now to figure out how to link 
against the new version...


Joe Wilson wrote:

Time to upgrade.

--- Christopher Backhouse <[EMAIL PROTECTED]> wrote:

I repeated exactly what you have there and confirm it doesn't work for me.

[EMAIL PROTECTED]:/tmp$ sqlite3 testing
SQLite version 3.3.13
Enter ".help" for instructions
sqlite> CREATE TABLE foo(bar text, baz text);
sqlite> INSERT INTO "foo" VALUES('123','345');
sqlite> INSERT INTO "foo" VALUES('123','6789');
sqlite> INSERT INTO "foo" VALUES('23456','13');
sqlite> INSERT INTO "foo" VALUES('432','13');
sqlite> INSERT INTO "foo" VALUES('7654321','13');
sqlite> INSERT INTO "foo" VALUES('1234567','345');
sqlite> select * from foo;
123|345
123|6789
23456|13
432|13
7654321|13
1234567|345
sqlite> select distinct bar, baz as z from foo where bar in (select bar 
from foo where baz==z order by length(bar) desc limit 1);

sqlite> .q


Joe Wilson wrote:

--- Christopher Backhouse <[EMAIL PROTECTED]> wrote:

I have a table:
create table foo(bar text,baz text);

I want to produce a list of all bar's paired with the longest baz they 
are ever associated with. I came up with the following query:


select distinct bar,baz as z from foo where bar in (select bar from foo 
where baz==z order by length(bar) desc limit 1);


This query works (although it might not be the best way to do this), 
except in the case where bar is a string that can be interpreted as a 
number in which case that value of bar never appears in the output.
I assume that in one part of the query it is being treated as a number 
and at another as a string, such that they compare not-equal.


Shouldn't the "text" in the table definition cause promotion to string 
in every case?


My question is how do i cast bar back to a string, or otherwise cause 
sqlite to do the right thing in this case? Or alternatively is there a 
different query which would avoid this problem?

I don't see the problem.
Are you seeing something different?

SQLite version 3.4.0

CREATE TABLE foo(bar text, baz text);
INSERT INTO "foo" VALUES('123','345');
INSERT INTO "foo" VALUES('123','6789');
INSERT INTO "foo" VALUES('23456','13');
INSERT INTO "foo" VALUES('432','13');
INSERT INTO "foo" VALUES('7654321','13');
INSERT INTO "foo" VALUES('1234567','345');

select distinct bar, baz as z from foo where bar in (
 select bar from foo where baz==z 
  order by length(bar) desc limit 1);


bar z 
--  --
123 6789  
7654321 13
1234567 345   




   

Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. 
http://mobile.yahoo.com/go?refer=1GNXIC


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




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



Re: [sqlite] Query has problems with string that looks like a number

2007-08-12 Thread Joe Wilson
Workaround for 3.3.13:

 select distinct bar, baz as z from foo where bar in ((
   select bar from foo where baz==z order by length(bar) desc limit 1
 ));

It's just different enough to prevent sqlite 3.3.13 from choking on
the "order by" clause in the "in" subquery.

--- Christopher Backhouse <[EMAIL PROTECTED]> wrote:
> I repeated exactly what you have there and confirm it doesn't work for me.
> 
> [EMAIL PROTECTED]:/tmp$ sqlite3 testing
> SQLite version 3.3.13
> Enter ".help" for instructions
> sqlite> CREATE TABLE foo(bar text, baz text);
> sqlite> INSERT INTO "foo" VALUES('123','345');
> sqlite> INSERT INTO "foo" VALUES('123','6789');
> sqlite> INSERT INTO "foo" VALUES('23456','13');
> sqlite> INSERT INTO "foo" VALUES('432','13');
> sqlite> INSERT INTO "foo" VALUES('7654321','13');
> sqlite> INSERT INTO "foo" VALUES('1234567','345');
> sqlite> select * from foo;
> 123|345
> 123|6789
> 23456|13
> 432|13
> 7654321|13
> 1234567|345
> sqlite> select distinct bar, baz as z from foo where bar in (select bar 
> from foo where baz==z order by length(bar) desc limit 1);
> sqlite> .q



  

Shape Yahoo! in your own image.  Join our Network Research Panel today!   
http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 



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



Re: [sqlite] Query has problems with string that looks like a number

2007-08-12 Thread Joe Wilson
Time to upgrade.

--- Christopher Backhouse <[EMAIL PROTECTED]> wrote:
> I repeated exactly what you have there and confirm it doesn't work for me.
> 
> [EMAIL PROTECTED]:/tmp$ sqlite3 testing
> SQLite version 3.3.13
> Enter ".help" for instructions
> sqlite> CREATE TABLE foo(bar text, baz text);
> sqlite> INSERT INTO "foo" VALUES('123','345');
> sqlite> INSERT INTO "foo" VALUES('123','6789');
> sqlite> INSERT INTO "foo" VALUES('23456','13');
> sqlite> INSERT INTO "foo" VALUES('432','13');
> sqlite> INSERT INTO "foo" VALUES('7654321','13');
> sqlite> INSERT INTO "foo" VALUES('1234567','345');
> sqlite> select * from foo;
> 123|345
> 123|6789
> 23456|13
> 432|13
> 7654321|13
> 1234567|345
> sqlite> select distinct bar, baz as z from foo where bar in (select bar 
> from foo where baz==z order by length(bar) desc limit 1);
> sqlite> .q
> 
> 
> Joe Wilson wrote:
> > --- Christopher Backhouse <[EMAIL PROTECTED]> wrote:
> >> I have a table:
> >> create table foo(bar text,baz text);
> >>
> >> I want to produce a list of all bar's paired with the longest baz they 
> >> are ever associated with. I came up with the following query:
> >>
> >> select distinct bar,baz as z from foo where bar in (select bar from foo 
> >> where baz==z order by length(bar) desc limit 1);
> >>
> >> This query works (although it might not be the best way to do this), 
> >> except in the case where bar is a string that can be interpreted as a 
> >> number in which case that value of bar never appears in the output.
> >> I assume that in one part of the query it is being treated as a number 
> >> and at another as a string, such that they compare not-equal.
> >>
> >> Shouldn't the "text" in the table definition cause promotion to string 
> >> in every case?
> >>
> >> My question is how do i cast bar back to a string, or otherwise cause 
> >> sqlite to do the right thing in this case? Or alternatively is there a 
> >> different query which would avoid this problem?
> > 
> > I don't see the problem.
> > Are you seeing something different?
> > 
> > SQLite version 3.4.0
> > 
> > CREATE TABLE foo(bar text, baz text);
> > INSERT INTO "foo" VALUES('123','345');
> > INSERT INTO "foo" VALUES('123','6789');
> > INSERT INTO "foo" VALUES('23456','13');
> > INSERT INTO "foo" VALUES('432','13');
> > INSERT INTO "foo" VALUES('7654321','13');
> > INSERT INTO "foo" VALUES('1234567','345');
> > 
> > select distinct bar, baz as z from foo where bar in (
> >  select bar from foo where baz==z 
> >   order by length(bar) desc limit 1);
> > 
> > bar z 
> > --  --
> > 123 6789  
> > 7654321 13
> > 1234567 345   



   

Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, 
photos & more. 
http://mobile.yahoo.com/go?refer=1GNXIC

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



Re: [sqlite] Query has problems with string that looks like a number

2007-08-12 Thread Christopher Backhouse

I repeated exactly what you have there and confirm it doesn't work for me.

[EMAIL PROTECTED]:/tmp$ sqlite3 testing
SQLite version 3.3.13
Enter ".help" for instructions
sqlite> CREATE TABLE foo(bar text, baz text);
sqlite> INSERT INTO "foo" VALUES('123','345');
sqlite> INSERT INTO "foo" VALUES('123','6789');
sqlite> INSERT INTO "foo" VALUES('23456','13');
sqlite> INSERT INTO "foo" VALUES('432','13');
sqlite> INSERT INTO "foo" VALUES('7654321','13');
sqlite> INSERT INTO "foo" VALUES('1234567','345');
sqlite> select * from foo;
123|345
123|6789
23456|13
432|13
7654321|13
1234567|345
sqlite> select distinct bar, baz as z from foo where bar in (select bar 
from foo where baz==z order by length(bar) desc limit 1);

sqlite> .q


Joe Wilson wrote:

--- Christopher Backhouse <[EMAIL PROTECTED]> wrote:

I have a table:
create table foo(bar text,baz text);

I want to produce a list of all bar's paired with the longest baz they 
are ever associated with. I came up with the following query:


select distinct bar,baz as z from foo where bar in (select bar from foo 
where baz==z order by length(bar) desc limit 1);


This query works (although it might not be the best way to do this), 
except in the case where bar is a string that can be interpreted as a 
number in which case that value of bar never appears in the output.
I assume that in one part of the query it is being treated as a number 
and at another as a string, such that they compare not-equal.


Shouldn't the "text" in the table definition cause promotion to string 
in every case?


My question is how do i cast bar back to a string, or otherwise cause 
sqlite to do the right thing in this case? Or alternatively is there a 
different query which would avoid this problem?


I don't see the problem.
Are you seeing something different?

SQLite version 3.4.0

CREATE TABLE foo(bar text, baz text);
INSERT INTO "foo" VALUES('123','345');
INSERT INTO "foo" VALUES('123','6789');
INSERT INTO "foo" VALUES('23456','13');
INSERT INTO "foo" VALUES('432','13');
INSERT INTO "foo" VALUES('7654321','13');
INSERT INTO "foo" VALUES('1234567','345');

select distinct bar, baz as z from foo where bar in (
 select bar from foo where baz==z 
  order by length(bar) desc limit 1);


bar z 
--  --
123 6789  
7654321 13
1234567 345   




   
Ready for the edge of your seat? 
Check out tonight's top picks on Yahoo! TV. 
http://tv.yahoo.com/


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




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



Re: [sqlite] Query has problems with string that looks like a number

2007-08-12 Thread Joe Wilson
--- Christopher Backhouse <[EMAIL PROTECTED]> wrote:
> I have a table:
> create table foo(bar text,baz text);
> 
> I want to produce a list of all bar's paired with the longest baz they 
> are ever associated with. I came up with the following query:
> 
> select distinct bar,baz as z from foo where bar in (select bar from foo 
> where baz==z order by length(bar) desc limit 1);
> 
> This query works (although it might not be the best way to do this), 
> except in the case where bar is a string that can be interpreted as a 
> number in which case that value of bar never appears in the output.
> I assume that in one part of the query it is being treated as a number 
> and at another as a string, such that they compare not-equal.
> 
> Shouldn't the "text" in the table definition cause promotion to string 
> in every case?
> 
> My question is how do i cast bar back to a string, or otherwise cause 
> sqlite to do the right thing in this case? Or alternatively is there a 
> different query which would avoid this problem?

I don't see the problem.
Are you seeing something different?

SQLite version 3.4.0

CREATE TABLE foo(bar text, baz text);
INSERT INTO "foo" VALUES('123','345');
INSERT INTO "foo" VALUES('123','6789');
INSERT INTO "foo" VALUES('23456','13');
INSERT INTO "foo" VALUES('432','13');
INSERT INTO "foo" VALUES('7654321','13');
INSERT INTO "foo" VALUES('1234567','345');

select distinct bar, baz as z from foo where bar in (
 select bar from foo where baz==z 
  order by length(bar) desc limit 1);

bar z 
--  --
123 6789  
7654321 13
1234567 345   



   
Ready
 for the edge of your seat? 
Check out tonight's top picks on Yahoo! TV. 
http://tv.yahoo.com/

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



[sqlite] Query has problems with string that looks like a number

2007-08-12 Thread Christopher Backhouse

I have a table:
create table foo(bar text,baz text);

I want to produce a list of all bar's paired with the longest baz they 
are ever associated with. I came up with the following query:


select distinct bar,baz as z from foo where bar in (select bar from foo 
where baz==z order by length(bar) desc limit 1);


This query works (although it might not be the best way to do this), 
except in the case where bar is a string that can be interpreted as a 
number in which case that value of bar never appears in the output.
I assume that in one part of the query it is being treated as a number 
and at another as a string, such that they compare not-equal.


Shouldn't the "text" in the table definition cause promotion to string 
in every case?


My question is how do i cast bar back to a string, or otherwise cause 
sqlite to do the right thing in this case? Or alternatively is there a 
different query which would avoid this problem?


Thanks - Chris


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



[sqlite] Re: ATTACH/DETACH DATABASE

2007-08-12 Thread Igor Tandetnik

Igor Mironchick <[EMAIL PROTECTED]>
wrote:

If I attach database "db_attached" into "db" and then close "db".
After opening "db" does I need to attach "db_attached" again or this
attachment was stored???


Attachment is a property of database connection, it is not reflected in 
the physical database file. You need to issue ATTACH statements in every 
connection you open, before you can refer to other databases on that 
connection.


Igor Tandetnik 



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



[sqlite] ATTACH/DETACH DATABASE

2007-08-12 Thread Igor Mironchick

Hi, guys.

If I attach database "db_attached" into "db" and then close "db". After 
opening "db" does I need to attach "db_attached" again or this 
attachment was stored???


--
Regards,
Igor Mironchick,
Intervale ©
#ICQ 492-597-570


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



Re: [sqlite] sqlite3 datatype

2007-08-12 Thread yahoo
On 11 Aug, Gerry Snyder wrote:
> fred238 wrote:
>> Gerry Snyder a écrit :
>>> fred238 wrote:
 Is necessary to set column datatype in sqlite3 ?
 Is better to use class storage in sqlite3 (TEXT, NUMERIC, INTEGER, 
 REAL, NONE)  ?

>>> Check out http://www.sqlite.org/datatype3.html and ask again here if 
>>> yu have further questions.
>>>
>> already read it and i don't understand all
> 
> Ok, I will try to help a little.
> 
> You do not need to set data types. If you don't, the default affinity 
> will be NUMERIC. That is, anything that looks like a number will be 
> stored as an integer or a real, as appropriate. This can waste some time 
> if you want to use the value as a string, but in general should not be a 
> real problem.
> 
> Specifying datatypes may make things easier for some strongly typed 
> languages (I don't really know--I use Tcl myself).

I disagree (although I also use Tcl). If you store eg. the string '08'
in a column with type NUMERIC, you'll get '8' back, in later
SELECTs. And that is probably not what you want. Set the column type
to 'TEXT' in such cases.

As in tcl, with 'eq' and '=='. Use 

  if {$a eq $b} {...}

to test for string identity, and

  if {$a == $b} {...}

to test for equal numeric values.

I see dynamic typing as a feature (well, I'm using tcl). But this does
not mean, it is without pitfalls.

rolf



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