Search query for SQlite database

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
matgarage
Posts: 73
Joined: Sat Apr 20, 2013 11:39 am

Search query for SQlite database

Post by matgarage » Fri Jan 01, 2016 5:52 pm

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 ?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Search query for SQlite database

Post by Klaus » Fri Jan 01, 2016 6:52 pm

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

matgarage
Posts: 73
Joined: Sat Apr 20, 2013 11:39 am

Re: Search query for SQlite database

Post by matgarage » Fri Jan 08, 2016 4:55 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Search query for SQlite database

Post by Klaus » Fri Jan 08, 2016 5:37 pm

À votre service, mon ami! :)

Post Reply