Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    4

    Unanswered: 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!

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: Dynamic SQL: BEGIN DECLARE...

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

    HTH

    sathyaram

    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.

  3. #3
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •