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 

Determine presence of resultset from query syntax?

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





PostPosted: Wed May 19, 2004 8:02 am    Post subject: Determine presence of resultset from query syntax? Reply with quote



Hi,

Is there a way to find out if a TSQLQuery has a result set,
without having to write my own SQL parser?
It is OK if this is done after executing the query.

E.g.
SELECT * FROM TABLENAME has a resultset,
but
UPDATE TABLENAME
INSERT INTO TABLENAME
DELETE FROM TABLENAME
DROP TABLE TABLENAME
TRUNCATE TABLE TABLENAME
SELECT FieldList INTO TABLENAME
do not.

Thanks in advance
Jan



--------------------------------------------------------------------------
Jan Doggen, QSA Landsmeer, The Netherlands
Please remove the spam blocker from my email address when replying directly


Back to top
Vitali Kalinin
Guest





PostPosted: Wed May 19, 2004 8:31 am    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote



Just an idea. You can wrap yours SQL in stored proc, create it and inspect
sysdepends system table (assuming we are talking about MS SQL Server).

Regards,
Vitali
"Jan Doggen" <j.doggen (AT) BLOCKqsa (DOT) nl> сообщил/сообщила в новостях следующее:
news:40ab14a4$1 (AT) newsgroups (DOT) borland.com...
Quote:
Hi,

Is there a way to find out if a TSQLQuery has a result set,
without having to write my own SQL parser?
It is OK if this is done after executing the query.

E.g.
SELECT * FROM TABLENAME has a resultset,
but
UPDATE TABLENAME
INSERT INTO TABLENAME
DELETE FROM TABLENAME
DROP TABLE TABLENAME
TRUNCATE TABLE TABLENAME
SELECT FieldList INTO TABLENAME
do not.

Thanks in advance
Jan



--------------------------------------------------------------------------
Jan Doggen, QSA Landsmeer, The Netherlands
Please remove the spam blocker from my email address when replying
directly





Back to top
Bojidar Alexandrov
Guest





PostPosted: Wed May 19, 2004 9:22 am    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote



If will continue with crazy ideas

If you put "set fmtonly on" before your sql (and off at end)
it will not execute but only return format of the fields and an empty
recordset if any.

Either way it is not needed to write a parser only to search for statements
insert/update/select....

Bojidar Alexandrov


"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> wrote

Quote:
Just an idea. You can wrap yours SQL in stored proc, create it and inspect
sysdepends system table (assuming we are talking about MS SQL Server).

Regards,
Vitali
"Jan Doggen" <j.doggen (AT) BLOCKqsa (DOT) nl> сообщил/сообщила в новостях следующее:
news:40ab14a4$1 (AT) newsgroups (DOT) borland.com...
Hi,

Is there a way to find out if a TSQLQuery has a result set,
without having to write my own SQL parser?
It is OK if this is done after executing the query.

E.g.
SELECT * FROM TABLENAME has a resultset,
but
UPDATE TABLENAME
INSERT INTO TABLENAME
DELETE FROM TABLENAME
DROP TABLE TABLENAME
TRUNCATE TABLE TABLENAME
SELECT FieldList INTO TABLENAME
do not.

Thanks in advance
Jan




--------------------------------------------------------------------------
Jan Doggen, QSA Landsmeer, The Netherlands
Please remove the spam blocker from my email address when replying
directly







Back to top
Vitali Kalinin
Guest





PostPosted: Wed May 19, 2004 11:22 am    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote


Either way it is not needed to write a parser only to search for statements
Quote:
insert/update/select....
It is not so simple, since select statement can be part of Insert, Update or

even DDL statment



Back to top
Bojidar Alexandrov
Guest





PostPosted: Wed May 19, 2004 12:04 pm    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote

Quote:
Either way it is not needed to write a parser only to search for
statements
insert/update/select....
It is not so simple, since select statement can be part of Insert, Update
or
even DDL statment

yes, and there can be multiple separate statements in one batch.

I highly suspect that this is really not needed by the asker... will see
what he will say.

Bojidar Alexandrov



Back to top
Vitali Kalinin
Guest





PostPosted: Wed May 19, 2004 12:40 pm    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote

Read SQL snippets that he had provided in original post and you'll see.
"Bojidar Alexandrov" <bojo_do_not_spam (AT) kodar (DOT) net> сообщил/сообщила в
новостях следующее: news:40ab4d5a (AT) newsgroups (DOT) borland.com...
Quote:
Either way it is not needed to write a parser only to search for
statements
insert/update/select....
It is not so simple, since select statement can be part of Insert,
Update
or
even DDL statment

yes, and there can be multiple separate statements in one batch.

I highly suspect that this is really not needed by the asker... will see
what he will say.

Bojidar Alexandrov





Back to top
Bojidar Alexandrov
Guest





PostPosted: Wed May 19, 2004 1:03 pm    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote

Quote:
I highly suspect that this is really not needed by the asker... will see
what he will say.

I mean that understanding before execution if there will be a recordset
probbaly is not really needed by him.



Back to top
Vitali Kalinin
Guest





PostPosted: Wed May 19, 2004 2:03 pm    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote

Just found interesting link from thread "Print Messages"
http://community.borland.com/article/0,1410,20245,00.html. If switching to
ADO is ok to your, then it can efficiently address yours problem:
"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> сообщил/сообщила в новостях
следующее: news:40ab1b7e (AT) newsgroups (DOT) borland.com...
Quote:
Just an idea. You can wrap yours SQL in stored proc, create it and inspect
sysdepends system table (assuming we are talking about MS SQL Server).

Regards,
Vitali
"Jan Doggen" <j.doggen (AT) BLOCKqsa (DOT) nl> сообщил/сообщила в новостях следующее:
news:40ab14a4$1 (AT) newsgroups (DOT) borland.com...
Hi,

Is there a way to find out if a TSQLQuery has a result set,
without having to write my own SQL parser?
It is OK if this is done after executing the query.

E.g.
SELECT * FROM TABLENAME has a resultset,
but
UPDATE TABLENAME
INSERT INTO TABLENAME
DELETE FROM TABLENAME
DROP TABLE TABLENAME
TRUNCATE TABLE TABLENAME
SELECT FieldList INTO TABLENAME
do not.

Thanks in advance
Jan




--------------------------------------------------------------------------
Jan Doggen, QSA Landsmeer, The Netherlands
Please remove the spam blocker from my email address when replying
directly







Back to top
Del Murray
Guest





PostPosted: Wed May 19, 2004 7:16 pm    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote

Yes, I agree, what is he really trying to do? After all, the select
statement doesn't get in there by itsself. So the author should know whether
a result set is **expected** or not. If you dont say 'select something' you
wont get a result set. If you are executing a stored proc then you better
know what it does before you go blindly calling it . It might say 'delete
from bank_account_records where 1 = 2' ....
that has a result but not a result set ... the result is you get fired ...
:-)


Back to top
Jan Doggen
Guest





PostPosted: Wed May 19, 2004 9:15 pm    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote

What am I really trying to do? ;-)

This is a small tool for simple login and sql execution on an MSDE database
(no graphical interface).
I sent it to the customer for troubleshooting and support, when I want to
'look' in his database, or help him fix things (phone support).
I want the user to be able to enter SQL statements, these can be with or
without result set, and they are not known beforehand.
I would like not to have to explain to the user the difference between
between queries with and without result sets, just display the query results
if they exist.

Jan


"Del Murray" <Del.Murray (AT) N_S_CreditHawk (DOT) Net> schreef in bericht
news:40abb1aa$1 (AT) newsgroups (DOT) borland.com...
Quote:
Yes, I agree, what is he really trying to do? After all, the select
statement doesn't get in there by itsself. So the author should know
whether
a result set is **expected** or not. If you dont say 'select something'
you
wont get a result set. If you are executing a stored proc then you better
know what it does before you go blindly calling it . It might say 'delete
from bank_account_records where 1 = 2' ....
that has a result but not a result set ... the result is you get fired ...
:-)





Back to top
Bojidar Alexandrov
Guest





PostPosted: Thu May 20, 2004 8:13 am    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote

Quote:
just display the query results
if they exist.

Then just do that.



Back to top
Jan Doggen
Guest





PostPosted: Thu May 20, 2004 8:27 am    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote

???

--> Back to original question ;-)

"Bojidar Alexandrov" <bojo_do_not_spam (AT) kodar (DOT) net> schreef in bericht
news:40ac68be (AT) newsgroups (DOT) borland.com...
Quote:
just display the query results
if they exist.

Then just do that.





Back to top
Jan Doggen
Guest





PostPosted: Thu May 20, 2004 9:43 am    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote

I have now done it the dirty way:

procedure TFrmLoginTests.BtnExecuteSQLClick(Sender: TObject);
VAR
Msg: String;
RA : integer;
begin
WITH QryTest DO
BEGIN
SQL.Clear;
SQL.Text := MmoSQL.Text;
try
Open;
cdsTest.Open;
FrmQueryResults.ShowModal;
cdsTest.Close;
Close;
except
on E:Exception DO
BEGIN
Msg := E.Message;
IF Pos('CURSOR',UpperCase(Msg)) <> 0 THEN
BEGIN
try
ExecSQL;
RA := RowsAffected;
CASE RA OF
0 : Msg := 'Geen rijen';
1 : Msg := '1 rij';
ELSE Msg := IntToStr(RA) + 'rijen';
END;
ShowInfoBox('Query uitgevoerd',Msg + ' gewijzigd');
except
on E:Exception DO
ShowErrorBox('Kan query niet uitvoeren',Msg);
end; { inner try }
END
ELSE
ShowErrorBox('Kan query niet uitvoeren',Msg);
END; { ON E:exception }
end; { Outer try }
END; { WITH QryTest }
end; { BtnExecuteSQLClick }


Jan


Back to top
Bojidar Alexandrov
Guest





PostPosted: Thu May 20, 2004 9:49 am    Post subject: Re: Determine presence of resultset from query syntax? Reply with quote


"Jan Doggen" <JanDoggenTHISISASPAMBLOCKER (AT) planet (DOT) nl> wrote

Quote:
???

--> Back to original question Wink

you need to execute query and see if there is resultset.



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.