Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Run SQL Statement from a string
Message
From
11/08/2006 15:28:02
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
 
 
To
11/08/2006 10:13:51
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01144703
Message ID:
01144915
Views:
25
Jeff, just one thing to consider when building SQL strings: "SQL Injection" is where a hacker supplies a parameter that alters the result.

Example:

Say you want to allow sales agents to look-up their own customers but not all your other customers. The agent enters the customer ID and the details are displayed. Here is the SQL used for the lookup:
lcagent=<agent's unique id>
lcID=<customer's unique id entered by agent>
lcselect=[select * from customer where cAgent="]+lcAgent+[" and ccustomerID="]+lcID+["]
&lcselect
Obviously this SQL prevents agent1 from accessing customers "owned" by agent2.

But say a hacker enters the customer ID as JJ" or ccustomerID != "?

You end up with this SQL:
select * from customer where cAgent="agent1" and ccustomerID="JJ" or ccustomerID != "?"
This SQL will reveal the entire customer list.

It's a trivial example, but something that could appear anywhere SQL is built from user input.

IMHO the best response is to use parameterised queries:
lcagent=<agent's unique id>
ccustomerID=<customer's unique id entered by agent>
lcselect=[select * from customer where cAgent=?lcAgent and ccustomerID=?lcID]
&lcselect
The ? parameters automatically insert the variable content at that point. It cannot have SQL injected. It is also easier to maintain IMHO and works against SQL server and other backends as well.
"... They ne'er cared for us
yet: suffer us to famish, and their store-houses
crammed with grain; make edicts for usury, to
support usurers; repeal daily any wholesome act
established against the rich, and provide more
piercing statutes daily, to chain up and restrain
the poor. If the wars eat us not up, they will; and
there's all the love they bear us.
"
-- Shakespeare: Coriolanus, Act 1, scene 1
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform