BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Validate a Query before executing ...

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Nick
Guest





PostPosted: Thu Aug 26, 2004 2:43 pm    Post subject: Validate a Query before executing ... Reply with quote




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





PostPosted: Thu Aug 26, 2004 4:49 pm    Post subject: Re: Validate a Query before executing ... Reply with quote



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





PostPosted: Thu Aug 26, 2004 11:12 pm    Post subject: Re: Validate a Query before executing ... Reply with quote



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





PostPosted: Fri Aug 27, 2004 2:06 am    Post subject: Re: Validate a Query before executing ... Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.