I Need some database coding help

Just starting out? Need help? Post your questions and find answers here.
hessu
User
User
Posts: 25
Joined: Fri Nov 20, 2015 6:30 am

I Need some database coding help

Post by hessu »

v$ = "%" + InputRequester("", "Enter Nutritiongroup:", "") + "%"

DatabaseQuery(1, "SELECT * FROM Food where Nutritiongroup Like '" +v$+ "' " ) , This one is good

DatabaseQuery(1, "SELECT * FROM Food where Nutritiongroup = '" +v$+ "' ") , This one is NOT good, I get none record.

Please help !
infratec
Always Here
Always Here
Posts: 7583
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: I Need some database coding help

Post by infratec »

Hi,

= means: exactly identical as

But you have % as head and tail.
It can not fit exactly.

Bernd
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: I Need some database coding help

Post by normeus »

don't include % inside v$

Code: Select all

v$ = InputRequester("", "Enter Nutritiongroup:", "") 

DatabaseQuery(1, "SELECT * FROM Food where Nutritiongroup Like '%" +v$+ "%' " ) ;  % here

DatabaseQuery(1, "SELECT * FROM Food where Nutritiongroup = '" +v$+ "' ") ; % NOT here


Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
hessu
User
User
Posts: 25
Joined: Fri Nov 20, 2015 6:30 am

Re: I Need some database coding help

Post by hessu »

Thank you for good advice. :lol: :lol: :lol:
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: I Need some database coding help

Post by Marc56us »

If you want to be more secure (avoid code injection)
and let user input string with: " and/or '
use labels (with SetDatabaseString etc)

Code: Select all

; Normal query
v$ = InputRequester("", "Enter Nutritiongroup:", "")

SetDatabaseString(1, 0, v$)

DatabaseQuery(1, "SELECT * FROM Food where Nutritiongroup = ? ") 


; Like query
v$ = "%" + InputRequester("", "Enter Nutritiongroup:", "") + "%"

SetDatabaseString(1, 0, v$)

DatabaseQuery(1, "SELECT * FROM Food where Nutritiongroup Like ? ") 
:arrow: So long Chr(34) and ' "+ +" ' to make SQL strings :P

Thank's Falsam (french forum) for this reminder of PB possibilities.
:wink:
Post Reply