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 > Database Server Software > DB2 > Dynamic SQL: BEGIN DECLARE...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-12-03, 04:05
HabaHaba HabaHaba is offline
Registered User
 
Join Date: Oct 2003
Posts: 4
Dynamic SQL: BEGIN DECLARE...

Hi all!
I have a small program which executes incoming queries and sends result back to client.
It's written on C with embeded SQL (SQLCI).
So, the problem is, that the incoming queries has a different size and i don't know how to dynamicly change it in:
Code:
    EXEC SQL BEGIN DECLARE SECTION;
        char hostvarquery[1024];
    EXEC SQL END DECLARE SECTION;
The question is -- How to put the variable in the string between BEGIN and END DECLARE SECTION?
Great thanks for answers!
Reply With Quote
  #2 (permalink)  
Old 11-12-03, 04:41
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: Dynamic SQL: BEGIN DECLARE...

You will have to read about SQLDA and use it in your program

HTH

sathyaram

Quote:
Originally posted by HabaHaba
Hi all!
I have a small program which executes incoming queries and sends result back to client.
It's written on C with embeded SQL (SQLCI).
So, the problem is, that the incoming queries has a different size and i don't know how to dynamicly change it in:
Code:
    EXEC SQL BEGIN DECLARE SECTION;
        char hostvarquery[1024];
    EXEC SQL END DECLARE SECTION;
The question is -- How to put the variable in the string between BEGIN and END DECLARE SECTION?
Great thanks for answers!
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 11-12-03, 06:57
HabaHaba HabaHaba is offline
Registered User
 
Join Date: Oct 2003
Posts: 4
Hello once again...
I'm using SQLDA, but, as i understand, it's useful after the query executed, but my problem, is that incoming query can be more than memory allocated for it. I know the size of query, but i can't dynamicly allocate memory for it when i'm declaring a host variable because when i'm trying to put the variable with known size in declaration, SQL precompiler fails with the message: "Variable hostvarquery not defined or not usable"
Here is a small part of my programm (to illustrate what i'm talking about):
Code:
    //bytes -- incoming variable
    EXEC SQL BEGIN DECLARE SECTION;
        char hostvarquery[bytes];
    EXEC SQL END DECLARE SECTION;   
    //myquery is a pointer to incoming query
    strcpy(hostvarquery,myquery);       
   //Here is a problem string
    EXEC SQL PREPARE MyStatement from :hostvarquery;
   //*mydaptr is a pointer to SQLDA struct
    EXEC SQL DESCRIBE MyStatement INTO :*mydaptr;
If declare hostvarquery like this:
Code:
    EXEC SQL BEGIN DECLARE SECTION;
        char hostvarquery[1024];
    EXEC SQL END DECLARE SECTION;
all will be fine, but hostvarquery will not be dynamic, and if a client sends query bigger than 1024 - it will not work
My question is how to make the size of hostvarquery dynamic?
Thanx one more time!
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On