 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Nick Guest
|
Posted: Thu Aug 26, 2004 2:43 pm Post subject: Validate a Query before executing ... |
|
|
Good Day All,
I would like to know how I would go about testing an SQL statement for validity, syntactically that is, prior to actually executing it against a database.
For example:
Select FirstNameL,astName from People order by EmployeeCode
In this example, the comma is in the wrong place. Therefore, if I try to execute it, it SHOULD fail. I would like to catch this. I am thinking I should Try/Catch this. It that all there is to it?
Thanks,
Nick
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Thu Aug 26, 2004 4:49 pm Post subject: Re: Validate a Query before executing ... |
|
|
Not knowing what database or data access components you are using
makes it hard to provide a meaningful answer. You can try preparing
the query within a try/except block. That may cause the query to be
parsed and optimized without having to execute it.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Thu Aug 26, 2004 11:12 pm Post subject: Re: Validate a Query before executing ... |
|
|
Nick wrote:
| Quote: |
I would like to know how I would go about testing an SQL statement
for validity, syntactically that is, prior to actually executing it
against a database.
For example:
Select FirstNameL,astName from People order by EmployeeCode
In this example, the comma is in the wrong place. Therefore, if I
try to execute it, it SHOULD fail. I would like to catch this. I am
thinking I should Try/Catch this. It that all there is to it?
|
Unless you have an SQL parser included in your own application (which is
possible to do but likely not worth it), simply catching the exception is
the usual way.
Depending on how you structure your app, using a try/finally is normally
recommended:
start transaction
try
execute query
commit
finally
rollback
end
If there is an exception, the transaction will still be handled, and the
exception will be raised to the calling code.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"Nature abhors the vacuum tube." - J.R. Pierce, Bell Labs engineer who
coined the term 'transistor'
|
|
| Back to top |
|
 |
Eric Hill Guest
|
Posted: Fri Aug 27, 2004 2:06 am Post subject: Re: Validate a Query before executing ... |
|
|
Not sure what database you use but the Oracle Call Interface *requires* you
to parse the SQL before submitting it. It goes like this:
- connect to the database
- parse a sql statement
- bind any variables you may have to the statement
- execute the statement
- fetch rows back to the client
- free the statement
- disconnect from the database
HTH,
Eric
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|