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

World: r3wp

[SQLite] C library embeddable DB .

amacleod
22-Dec-2008
[827x2]
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]
. .
Robert
4-Jan-2009
[869x2]
FYI: I'm currently adding some stuff to Ashley's SQLite driver to:

1st: Handle in memory databases (":memory:")
2nd: To handle connection to more than one database file at once.

So, if someone did this already pleasae let me know :-)
A bit OT: Has anybody an idea how a "schema driven" database export 
does/could work?


I have an applicaiton that uses some tables, and records are linked 
by primary index IDs. Now I want to export a record and all its dependend 
records either into a new database or over the network to some other 
process.


Because ID ranges are different in the export target database or 
on the remote server, I need to rewrite the old IDs with the new 
ones.


At the moment I have a hand written, very app specific (and error 
prone) function for this. But I would like to do this in a much more 
generic fashion. Maybe just specifcing the relationship with some 
simple dialect and than have a generic function collecting everything.
Pekr
4-Jan-2009
[871]
rewriting IDs? A risky business :-) I have never done anything like 
that.
Robert
4-Jan-2009
[872]
How else will you do it if you transfer one set of related records 
from database A to a database B?
Pekr
4-Jan-2009
[873]
of course you are right. You just have to be carefull or you could 
end-up with some "dead" child records.
sqlab
4-Jan-2009
[874x2]
Why not transfer the old ID to a new  indexed field oldID?
I just tried using an extra object with only the reference pointers. 
But I never checked, if it is working with more than one opened database 
because of the limitations regarding simulataneous access by more 
than one process.
Robert
4-Jan-2009
[876]
sqlab, don't understand what you mean. How will an oldID help me 
to get all records back together? This would require that the application 
knows about oldID.