Page 1 of 1

Search query for SQlite database

Posted: Fri Jan 01, 2016 5:52 pm
by matgarage
Hi,

I'm trying to filter a database content to display item that match with a particular text string.
My database contain 1 table (StationsList) and 4 fields (F1, F2,F3,F4)

I'm trying to set a search field with a script that display in a datagrid the result of the search/filtering

Search field code :

Code: Select all

on keyDown theKey 
   
   put theKey after fld "ftext"
   put fld "ftext" into rval 
   put "StationsList" into tTableName    
-- Start of the QUERY building
   put "SELECT * FROM " & tTableName & " LIKE "& "'%" &rval& "%'"  into tSQL
   put textdecode (revDataFromQuery(tab, cr, dbID, tSQL),"UTF8") into triData
   
   set the DGtext of group "StationsListe2" to triData
end keyDown
That return :
revdberr,Database Error: SQL error or missing database
Query: SELECT * FROM StationsList LIKE '%mom

(where '%mom' is the 'rval' variable conbinated with '%' but without the last '% ?)

I'm a beginner in SQlite, I've tried a lot of variations of syntax and some googled formulas, without result.

Did you get a hint to manage with with ?

Re: Search query for SQlite database

Posted: Fri Jan 01, 2016 6:52 pm
by Klaus
HI Mat,

you forgot to add WHAT database field is like %xxx%!
The SQL query should look like this:
...
SELECT * FROM StationsList WHERE F1 LIKE '%mom%'
## Or WHEREever you want to search
...

Here a link to MY SQL reference, I am not an db expert so I have to look up most things :D
http://www.w3schools.com/sql/default.asp


Best

Klaus

Re: Search query for SQlite database

Posted: Fri Jan 08, 2016 4:55 pm
by matgarage
Hi Klaus,
I thinked to have already thank you for this hint that let me go forward in my project but I don't... ahem.

So "Thank you again Klaus" ;-)

Matthieu

Re: Search query for SQlite database

Posted: Fri Jan 08, 2016 5:37 pm
by Klaus
À votre service, mon ami! :)