Syntax to use variable in a query using PB API & SQLite

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Pierre Mercier
User
User
Posts: 10
Joined: Wed Apr 23, 2008 4:02 am
Location: CANADA

Syntax to use variable in a query using PB API & SQLite

Post by Pierre Mercier »

I am just starting programming in Pure Basic and i can't find the right syntax for queries using variable and passing it from PB api to SQLite database

All Samples below is use on a program done with VB6 and MSAccess and all :shock: work properly

Here is a sample of different small queries using different variable

Using a String var
"SELECT Client.* FROM client WHERE ((Client.ville) = ' " & MyCity & " '))

Using a numeric var
"SELECT Client.* FROM client WHERE ((Client.Zipcode) = " & MyZipCode & "));"

Using a string var and a numeric var and formattinf the query on 2 lines for easy reading
"SELECT Client.* FROM Client WHERE (((Client .ville) = ' " & MyCity & " ') " _
& "AND ((client.CP) =(" & MyCP & "))

Using a string var with like operator
"SELECT Client.* FROM Client WHERE (((Client.CP) like '*" & MyCP & *');"

Using a Datetime Var
"SELECT Client.* FROM Client WHERE (((Client.Dlv) = #" & MyDate & "# ))
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Quite a few of us use a 'wrapper'.

See if this helps http://www.purebasic.fr/english/viewtopic.php?t=27036

search may also help. report back if it doesn't.

cheers
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

well i think i know what you need is:

Code: Select all

"Select * FROM Client WHERE ville='"+Mycity+"'"
Pierre Mercier
User
User
Posts: 10
Joined: Wed Apr 23, 2008 4:02 am
Location: CANADA

Queries's syntax

Post by Pierre Mercier »

That exactly what i need and it work perfectly on string. I will try the
other with + replacing &.

Many thank's :P
Post Reply