r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[SQLite] C library embeddable DB .

Graham
22-Dec-2008
[819]
you have to create your dialected string first
sqlab
22-Dec-2008
[820]
A concatenation like 
like '%' || ? || '%'
shoud work
PeterWood
22-Dec-2008
[821]
I got this unexpected behaviour:
>> do %~/Code/Library/Rebol/sqlite.r

Script: "SQLite driver" (26-Nov-2008)

>> connect %~/Code/SQLite3/mydata.db

** User Error: SQLite out of memory

** Near: make error! reform ["SQLite" error]

>> change-dir %~/Code/SQLite3

== %/Users/peter/Code/SQLite3
/
>> connect %mydata.db

== 3400768
amacleod
22-Dec-2008
[822x7]
sqlab,

reslts: sql reduce [{select * from fdbooks where ftext like '%'||?||'%'} 
srch]
== []
where srch: "ladders"
no error but not finding what should be there.:

reslts: sql reduce [{select * from fdbooks where ftext like '%ladders%'}]

== [[2 "FFP-LADDERS" "1-PORTABLE LADDERS" "2." " SIZES AND TYPES 
OF PORTABLE LADDERS IN USE^/" "" 4-Dec-2008/15:29:1
9] [4 "FFP-LADD...
I got it!
it works when srch: 'ladders
as word?
Not string?
What if I want multi-word string?
as in;

reslts: sql reduce [{select * from fdbooks where ftext like '%aluminum 
ladders%'}]

== [[9 "FFP-LADDERS" "1-PORTABLE LADDERS" "3." " CONSTRUCTION OF 
PORTABLE ALUMINUM LADDERS^/" "" 4-Dec-2008/15:29:19
] [10 "FFP-LADD...
and while we are here...
what about multiple words in string...
ladders
 and  "aluminum" as apposed to "aluminum ladders"
And how could I figure this out myself. Is this syntax a part of 
the sqlite.r interface or sqlite itself?
Graham
22-Dec-2008
[829]
You need a primer in sql ...
amacleod
22-Dec-2008
[830x2]
I can find the sql commands but I do not know how to rebolize them. 

Where can I find that I need to do this: '%'||?||'%' ?
I do not see anything like that in any docs I can find.
Graham
22-Dec-2008
[832x4]
You construct your sql statement and test it.
Then you substitute your variables ... that's it.
the sql statements are standard sql.  You don't need to use the ? 
stuff .... ie. you can compose your statement before hand.
I don't know sqllite's syntax .. but this looks wrong to me


reslts: sql reduce [{select * from fdbooks where ftext like '%aluminum 
ladders%'}]

it should simply be


reslts: sql {select * from fdbooks where ftext like '%aluminum ladders%'}
BrianH
22-Dec-2008
[836x2]
Those || are string concatenation, afaict. Use JOIN in REBOL for 
that.
Or REJOIN.
Graham
22-Dec-2008
[838x4]
I've never tested whether the sql dialect can replace ? inside single 
quotes.
Anyway, you don't need to use the sql dialect ... just create your 
sql statement and then execute it.
And once you learn sql, then you can look at the dialect .... which 
is a simple substitution thing.
Instead of LIKE, you can also use CONTAINS
BrianH
22-Dec-2008
[842]
SQLite has a CONTAINS extension?
Graham
22-Dec-2008
[843]
oh ... sqlite ? ... ooops
sqlab
22-Dec-2008
[844x2]
a ||  b 
is the sqlite syntax for concatenation of two strings.
http://www.sqlite.org/lang_expr.html
Dont't use the reduce
amacleod
22-Dec-2008
[846]
sqlab,

>> reslts: sql reduce [{select * from fdbooks where ftext like '%aluminum%' 
|| '%ladder%'}]

== [[9 "FFP-LADDERS" "1-PORTABLE LADDERS" "3." " CONSTRUCTION OF 
PORTABLE ALUMINUM LADDERS^/" "" 4-Dec-2008/15:29:19
] [10 "FFP-LADD...
works. Thanks again...but
BrianH
22-Dec-2008
[847]
Equivalent to the above: {select * from fdbooks where ftext like 
'%aluminum%ladder%'}
amacleod
22-Dec-2008
[848]
How do I do that with variables?
BrianH
22-Dec-2008
[849]
Are you checking for whether
- Both of the words are in the string in that order

- Both of the words are in the string directly adjacent to each other 
in that order
- Both of the words are in the string in any order
- Either of the words are in the string in any order
?
amacleod
22-Dec-2008
[850]
It gives different results...


>> reslts: sql [{select * from fdbooks where ftext like '%aluminum%' 
|| '%ladder%'}]

== [[9 "FFP-LADDERS" "1-PORTABLE LADDERS" "3." " CONSTRUCTION OF 
PORTABLE ALUMINUM LADDERS^/" "" 4-Dec-2008/15:29:19
] [10 "FFP-LADD...


>> reslts: sql [{select * from fdbooks where ftext like '%ladder%aluminum%' 
}]
== [[11 "FFP-LADDERS" "1-PORTABLE LADDERS" "3.1.1" {

Solid Beam Aluminum Construction- This type of ladder has a solid 
side rail co...
BrianH
22-Dec-2008
[851x2]
Answer my question first then I can answer yours :)
Pick one of the 4.
amacleod
22-Dec-2008
[853x2]
I need to search for multi-word string "aluminum ladder" (in that 
order...

but also would like to beable to search for the occurnace of multiple 
words in any order: "aluminum" and "Ladder" and "water" etc
2 and 3 I suppose
BrianH
22-Dec-2008
[855]
If you want to search for a multiword string, use LIKE '%aluminum 
ladder%', then use OR to add other clauses.
The choices above, with examples:
1: like '%aluminum%ladder%'
2: like '%aluminum ladder%'
3: like '%aluminum%' and like '%ladder%'
4: like '%aluminum%' or like '%ladder%'
The || operator means string concatenation, not or.
amacleod
22-Dec-2008
[856x3]
Thanks BrianH,
But how do I use it dynamically?
insert and update use "?" so you can use variables. 


reslts: sql reduce [{select * from fdbooks where ftext like '%'||?||'%'} 
srch]
== []
works when srch is a word!
but not when it contains a string!
>> srch: "aluminum"
== "aluminum"

>> reslts: sql reduce [{select * from fdbooks where ftext like '%'||?||'%'} 
srch]
== []

>> srch: 'aluminum
== aluminum

>> reslts: sql reduce [{select * from fdbooks where ftext like '%'||?||'%'} 
srch]

== [[9 "FFP-LADDERS" "1-PORTABLE LADDERS" "3." " CONSTRUCTION OF 
PORTABLE ALUMINUM LADDERS^/" "" 4-Dec-2008/15:29:19
] [10 "FFP-LADD...
BrianH
22-Dec-2008
[859x2]
It sounds like you are on the right track, but running into bugs 
in the REBOL SQLite access infrastrcture.
Have you considered whether it is a casing issue?
amacleod
22-Dec-2008
[861]
I gues I can build the {select * from fdbooks where ftext like '%ladder%'} 
string dynamically with rejoin and insert it: 

srch: {select * from fdbooks where ftext like '%ladder%'}
reslts: sql reduce [srch]

== [[2 "FFP-LADDERS" "1-PORTABLE LADDERS" "2." " SIZES AND TYPES 
OF PORTABLE LADDERS IN USE^/" "" 4-Dec-2008/15:29:1
9] [4 "FFP-LADD...
BrianH
22-Dec-2008
[862]
If yo can be certain that any ' in your strings is being escaped 
properly, that may be the way to go.
amacleod
22-Dec-2008
[863x2]
to make it more sophisticated I can parse the search input for "aluminum 
ladders"  and seperate words as having "and" between each...like 
most search engines. THan build it and insert it.
BrianH,

Its working...I just do not know how to make it dynamic.
BrianH
22-Dec-2008
[865]
That is a good approach anyways, as it will help prevent SQL injection 
attacks.
amacleod
22-Dec-2008
[866]
Thanks for all the help.
BrianH
22-Dec-2008
[867]
I am not as familiar with the bugs in your SQLite access infrastructure 
as I am with SQLite itself, so I helped where I could :(
ManuM
23-Dec-2008
[868]
. .