05-28-2015 08:41 AM
Hello,
I am connecting to a MS access 2007 Database using the Database connectivity toolkit (DCT).
I need to build a query from some input string controls (Operator, Lot). Using standard SQL I could use :
SELECT * FROM TEST_SETUP WHERE OPERATOR='string from Operator control' and LOT='string from Lot control';
However this leads to the possibility of an SQL injection attack, so I'd like to use a parameterized query. I see examples showng the format for an INSERT command, but nothing showing how to call out parameters for a Select statement......
Any ideas?
Thanks!
05-29-2015 11:20 AM
Hello Howard,
Thanks for using NI support forums. I’ll suggest building Query string prior to send it. If you want to avoid some characters in order to prevent SQLi then you can implement some comparison logic within the vi to “validate” or “check” the entire string. Functions like concatenate string or string length can be useful on this case.
Have a great day!
.
05-29-2015 07:59 PM
Hi Marco,
Thanks for the reply, but not sure how it answers my question. Yes, I could build a string and send a standard query but what if the user's name is little bobby tables?
05-31-2015 10:23 AM
05-31-2015 11:02 AM
My point being that there are times when typed input is a requirement. User name / password - If you have 5000 users, are you going to scroll through a list? Yes, there are options such as autocomplete, etc. but often you wouldn't want to expose a list of all users.....
There are reasons the parameterized query was developed, one of them to overcome the potential issues of SQL injection. Specifically my question concerns the correct format of the Labview parameterized query VI. I don't want to use unfiltered text input. That was the reason for the post.....
05-31-2015 04:35 PM
@HowardB wrote:
I see examples showng the format for an INSERT command, but nothing showing how to call out parameters for a Select statement......
Any ideas?
Do it the same as with INSERT commands; use "?" in the SQL for your paramteters. Does that not work?
05-31-2015 07:55 PM
So, something like "SELECT * FROM TEST_DATA WHERE OPERATOR=(operator) and LOT=(lot) values (?,?)"
Does that look correct? I'll try it tomorrow when I get back to work.....
06-01-2015 03:10 AM
More something like this: "SELECT * FROM TEST_DATA WHERE OPERATOR=? and LOT=?"
06-01-2015 03:35 AM - edited 06-01-2015 03:36 AM
Ah, you need a good reference on SQL, rather than LabVIEW help. Look up the SQL syntax for SELECT, and then you use "?" in place of the parameters (as dkfire shows).
06-01-2015 05:10 AM
So for the select statement, the Labview vi does not use named parameters? So then I must set the parameters in the same order as the ?'s appear?
Thanks for the help!