If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Confused...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-20-04, 02:31
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
Confused...

Feel like I should know this....

Does anyone know of a way to test a query for syntax without actually running the query?

I have an asp page that creates a series of nearly 50 INSERT statements from about 20 parameters entered by the user.

I don't want to even begin the process of doing the inserts unless all the queries have correct syntax and will work without error. (Reversing the process, if an error occurs on Insert statement #43 would be a real pain.)

My plan is to create ALL the Insert statements in an array... and then run them through some sort of syntax test PRIOR to actually submitting them to the database.

Some of the Inserts will get pretty complex... and depending on the user's parameters... some of which are based on retrieved data... there is a possibility of many odd syntax problems.

Any ideas?

Tim
__________________
Tim
Reply With Quote
  #2 (permalink)  
Old 01-20-04, 04:39
Apel Apel is offline
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 228
Many databases have a DESCRIBE, EXPLAIN or similar statement that will show you the execution plan of a query. If your query has a syntax error the statement will throw an error too.
Another possibility would be to encapsulate all statements within a big transaction and roll it back if one statement fails, this saves you the work of undoing the queries yourself.
The "clean" way would be to check all parameters for validity _before_ executing any query. This is also strongly advisable from a security standpoint to prevent SQL injection attacks.
Reply With Quote
  #3 (permalink)  
Old 01-20-04, 07:28
yoja7 yoja7 is offline
Registered User
 
Join Date: Jan 2004
Location: India
Posts: 31
Re: Confused...

Quote:
Originally posted by MrWizard
I don't want to even begin the process of doing the inserts unless all the queries have correct syntax and will work without error. (Reversing the process, if an error occurs on Insert statement #43 would be a real pain.)


Tim

sorry for editing ur post ;-)

hey, u can try using objConn.BeginTrans at start of processing of INSERT statements and on error use Rollback. I donno how helpful this is

btw .try this page for some help
http://www.w3schools.com/ado/met_conn_begintrans.asp
__________________
Do not walk behind me, for I may not lead.
Do not walk ahead of me, for I may not follow.
Do not walk beside me, either.
Just leave me alone.

Yogesh Jangam
http://yogeshjangam.*************
Reply With Quote
  #4 (permalink)  
Old 02-03-04, 04:24
Bullschmidt Bullschmidt is offline
Guru
 
Join Date: Jun 2003
Location: USA
Posts: 1,032
Instead of acting on the SQL statements you could have your Web page simply print the statements. Then you could separately test them one by one by copying and pasting them into something like the query builder area of Access changing any % to be * instead.
__________________
J. Paul Schmidt, Freelance Web and Database Developer
www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips
Reply With Quote
  #5 (permalink)  
Old 02-03-04, 11:17
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
Quote:
Originally posted by Bullschmidt
Instead of acting on the SQL statements you could have your Web page simply print the statements. Then you could separately test them one by one by copying and pasting them into something like the query builder area of Access changing any % to be * instead.

Thanks.... but I'm not sure I understand you're suggestion.

The point is that I'm already certain of the basic structure of the SQL... that's no problem. My issue is with the data that a user might enter.

I don't want to wait until I actually submit the query to know if it will work ok. I'm looking for a way to test the query... just as if it were submitted... but not actually have it processed.

The issue is that these multiple queries rely on diverse and unpredictable data entry.... with untrusted users. In addition, if submitted, the queries willl take a LONG time to run, and will modifiy existing data..... which means reversing them will be a big of a nightmare.

What I'm now doing is simply checking for illegal characters before submitting the query.

Tim
__________________
Tim
Reply With Quote
  #6 (permalink)  
Old 02-03-04, 11:29
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
This is the better way to check for illegal characters before submitting the query.
Reply With Quote
  #7 (permalink)  
Old 02-03-04, 11:46
Apel Apel is offline
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 228
Yes, if the users are untrusted you MUST validate the entered data correctly before running the query. A malicious user might construct parameters that will actually pass your "execution test" but do harmful things to your data.
Imagine this simple query:
Code:
MyCon.Execute "DELETE FROM MyTable WHERE MyName='" & MyUntrustedParameter & "'"
An attacker could pass something like:
Code:
doesnotexist' OR 'bla'='bla
as MyUntrustedParameter. The query would execute and delete all records in MyTable.
Reply With Quote
  #8 (permalink)  
Old 02-03-04, 19:16
Bullschmidt Bullschmidt is offline
Guru
 
Join Date: Jun 2003
Location: USA
Posts: 1,032
Quote:
In addition, if submitted, the queries willl take a LONG time to run, and will modifiy existing data..... which means reversing them will be a big of a nightmare.
I'd suggest testing with sample data instead of the real thing (i.e. perhaps use a copy of the database or something if possible).
__________________
J. Paul Schmidt, Freelance Web and Database Developer
www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On