How do I pass a collection type to a prepared statement in Informix-4gl

Ask a Question related to Informix, Design and Development.

  1. #1

    Default Re: How do I pass a collection type to a prepared statement in Informix-4gl


    One way is to construct the string for prepare dynamically - ( the c_sel
    text ), but I think it will defeat the purpose of using prepared statements.

    Second, include a temp table in the query and use a subquery on temp
    table after inserting the vals of blue etc in temp table.

    Third- if you know the max number of values in IN clause -

    use let c_txt = " sel ................................ where
    ............... in (?,?,?,?,?,?,?)"

    and execute using "blue","red","dummy","dummy",dummy" etc ( you can use
    an arry initialized to all dummy values and just populate the values you
    have -
    arr[1]=blue , arr[2]=red and then execute using this array

    Hope this helps

    Rgds
    Preetinder

    Jean Sagi wrote:
    >I have some minor problem with a 4gl - Sql statement.
    >Maybe someone has addreesed it before:
    >
    >Let say you have the following query:
    >
    >select count(*)
    >from some_table
    >where field_code = 10
    >and field_color in ( "blue", "red", "color" )
    >into temp tx
    >with no log;
    >
    >where table some_table exists and has a fields field_code and field_color
    >
    >let say that this query must be inside a 4gl program and you want to prepare it and execute it:
    >
    >let c_sel =
    >" select count(*) ",
    >" from some_table",
    >" where field_code = 10 ",
    >" and field_color in ( 'blue', 'red', 'color' ) ",
    >" into temp tx ",
    >" with no log "
    >
    >prepare st_sel from c_sel
    >execute c_sel
    >
    >NO problem...
    >
    >Now you want the filter "field_code = 10" be dinamyc :
    >
    >let c_sel =
    >" select count(*) ",
    >" from some_table",
    >" where field_code = ? ",
    >" and field_color in ( 'blue', 'red', 'color' ) ",
    >" into temp tx ",
    >" with no log "
    >
    >prepare st_sel from c_sel
    >execute c_sel using 10
    >
    >No problem
    >
    >!!Now you want the filter "field_color in ( 'blue', 'red', 'color' )" be dynamic
    >
    >HOW DO YOU THAT?
    >
    >I tried different approaches but none of the worked...
    >
    >Ex:
    >
    >let c_sel =
    >" select count(*) ",
    >" from some_table",
    >" where field_code = ? ",
    >" and field_color in ? ",
    >" into temp tx ",
    >" with no log "
    >
    >prepare st_sel from c_sel
    >execute c_sel using 10, "('blue', 'red', 'color')"
    >
    >abort with the following error:
    >
    >Program stopped at "prog_name.4gl", line number xxx.
    >4GL run-time error number -9650.
    >Right hand side of IN expression must be a COLLECTION type.
    >
    >BTW:
    >
    >#finderr -9650
    >Message number -9650 not found.
    >
    >What I can see is that the right expression must be of collection type... so
    >
    >
    >How do I pass a collection type to a prepared statement in Informix-4gl?
    >
    >
    >
    >Chucho!
    >
    >PD:
    >
    >Operating System version : HP-UX serve-name B.11.00 U 9000/856
    >INFORMIX-4GL Version : 7.30.HC7
    >
    >Jean Sagi
    >jeansagi@myrealbox.com
    >jeansagi@netscape.net
    >
    >
    >sending to informix-list
    >
    >
    sending to informix-list
    preetinder dhaliwal Guest

  2. Similar Questions and Discussions

    1. PREPARED STATEMENT
      Hi there, I want to know that is a posibillity to test if a statement is prepared in PL/PgSQL. I have create a function: .......... PREPARE...
    2. How do I pass a collection type to a prepared statement in Informix-4gl 7.30?
      Haven't used 4GL much but maybe you can use a subquery. Store the values in a temp table, then ... and field_color in (select fcolor from...
    3. HELP: Associated statement is not prepared - SQL Agent
      Hi ... I got a job using Web Publishing to generate report based on the data returned from store procedure. Lately, I got some funny problem...
    4. --- Associated statement is not prepared - SQL Agent
      Hi ... I got a job using Web Publishing to generate report based on the data returned from store procedure. Lately, I got some funny problem...
    5. !!!! Associated statement is not prepared - SQL Agent !!!!
      Hi ... I got a job using Web Publishing to generate report based on the data returned from store procedure. Lately, I got some funny problem...
  3. #2

    Default Re: How do I pass a collection type to a prepared statement in Informix-4gl


    Jean Sagi wrote:
    > I have some minor problem with a 4gl - Sql statement.
    > Maybe someone has addreesed it before:
    >
    > Let say you have the following query:
    >
    > select count(*)
    > from some_table
    > where field_code = 10
    > and field_color in ( "blue", "red", "color" )
    > into temp tx
    > with no log;
    >
    > where table some_table exists and has a fields field_code and field_color
    >
    > let say that this query must be inside a 4gl program and you want to prepare it and execute it:
    >
    > let c_sel =
    > " select count(*) ",
    > " from some_table",
    > " where field_code = 10 ",
    > " and field_color in ( 'blue', 'red', 'color' ) ",
    > " into temp tx ",
    > " with no log "
    >
    > prepare st_sel from c_sel
    > execute c_sel
    >
    > NO problem...
    >
    > Now you want the filter "field_code = 10" be dinamyc :
    >
    > let c_sel =
    > " select count(*) ",
    > " from some_table",
    > " where field_code = ? ",
    > " and field_color in ( 'blue', 'red', 'color' ) ",
    > " into temp tx ",
    > " with no log "
    >
    > prepare st_sel from c_sel
    > execute c_sel using 10
    >
    > No problem
    >
    > !!Now you want the filter "field_color in ( 'blue', 'red', 'color' )" be dynamic
    >
    > HOW DO YOU THAT?
    >
    > I tried different approaches but none of the worked...
    >
    > Ex:
    >
    > let c_sel =
    > " select count(*) ",
    > " from some_table",
    > " where field_code = ? ",
    > " and field_color in ? ",
    > " into temp tx ",
    > " with no log "
    >
    > prepare st_sel from c_sel
    > execute c_sel using 10, "('blue', 'red', 'color')"
    >
    > abort with the following error:
    >
    > Program stopped at "prog_name.4gl", line number xxx.
    > 4GL run-time error number -9650.
    > Right hand side of IN expression must be a COLLECTION type.
    >
    > BTW:
    >
    > #finderr -9650
    > Message number -9650 not found.
    >
    > What I can see is that the right expression must be of collection type... so
    >
    >
    > How do I pass a collection type to a prepared statement in Informix-4gl?
    I don't know, I'd have to read the manual first..., but it's too much effort.

    If you know how many values there are going to be then you could do
    something like:

    LET c_sel = "SELECT COUNT(*)",
    " FROM some_table",
    " WHERE field_code = ?",
    " AND field_color IN (?, ?, ?)",
    " INTO TEMP tx WITH NO LOG"

    Then you could do:

    PREPARE st_sel FROM c_sel
    EXECUTE c_sel USING 10, "blue", "red", "color"

    If you DON'T know how many values there are going to be then you could
    populate another TEMP table first with the values for your list. Then you
    could do something like:

    LET c_sel = "SELECT COUNT(*)",
    " FROM some_table",
    " WHERE field_code = ?",
    " AND field_color IN",
    " (SELECT valid_color FROM my_temp_colors)",
    " INTO TEMP tx WITH NO LOG"

    Cheers,
    --
    Mark.

    +----------------------------------------------------------+-----------+
    | Mark D. Stock mailto:mdstock@MydasSolutions.com |//////// /|
    | Mydas Solutions Ltd [url]http://MydasSolutions.com[/url] |///// / //|
    | +-----------------------------------+//// / ///|
    | |We value your comments, which have |/// / ////|
    | |been recorded and automatically |// / /////|
    | |emailed back to us for our records.|/ ////////|
    +----------------------+-----------------------------------+-----------+

    sending to informix-list
    Mark D. Stock Guest

  4. #3

    Default Re: How do I pass a collection type to a prepared statement in Informix-4gl


    Thanks to Everett Mills and catfish, who answered,

    I think I could use both suggestions, parse the list of colors and
    include them in a temporary table.

    TIA


    Chucho!

    Jean Sagi wrote:
    > I have some minor problem with a 4gl - Sql statement.
    > Maybe someone has addreesed it before:
    >
    > Let say you have the following query:
    >
    > select count(*)
    > from some_table
    > where field_code = 10
    > and field_color in ( "blue", "red", "color" )
    > into temp tx
    > with no log;
    >
    > where table some_table exists and has a fields field_code and field_color
    >
    > let say that this query must be inside a 4gl program and you want to prepare it and execute it:
    >
    > let c_sel =
    > " select count(*) ",
    > " from some_table",
    > " where field_code = 10 ",
    > " and field_color in ( 'blue', 'red', 'color' ) ",
    > " into temp tx ",
    > " with no log "
    >
    > prepare st_sel from c_sel
    > execute c_sel
    >
    > NO problem...
    >
    > Now you want the filter "field_code = 10" be dinamyc :
    >
    > let c_sel =
    > " select count(*) ",
    > " from some_table",
    > " where field_code = ? ",
    > " and field_color in ( 'blue', 'red', 'color' ) ",
    > " into temp tx ",
    > " with no log "
    >
    > prepare st_sel from c_sel
    > execute c_sel using 10
    >
    > No problem
    >
    > !!Now you want the filter "field_color in ( 'blue', 'red', 'color' )" be dynamic
    >
    > HOW DO YOU THAT?
    >
    > I tried different approaches but none of the worked...
    >
    > Ex:
    >
    > let c_sel =
    > " select count(*) ",
    > " from some_table",
    > " where field_code = ? ",
    > " and field_color in ? ",
    > " into temp tx ",
    > " with no log "
    >
    > prepare st_sel from c_sel
    > execute c_sel using 10, "('blue', 'red', 'color')"
    >
    > abort with the following error:
    >
    > Program stopped at "prog_name.4gl", line number xxx.
    > 4GL run-time error number -9650.
    > Right hand side of IN expression must be a COLLECTION type.
    >
    > BTW:
    >
    > #finderr -9650
    > Message number -9650 not found.
    >
    > What I can see is that the right expression must be of collection type... so
    >
    >
    > How do I pass a collection type to a prepared statement in Informix-4gl?
    >
    >
    >
    > Chucho!
    >
    > PD:
    >
    > Operating System version : HP-UX serve-name B.11.00 U 9000/856
    > INFORMIX-4GL Version : 7.30.HC7
    >
    > Jean Sagi
    > [email]jeansagi@myrealbox.com[/email]
    > [email]jeansagi@netscape.net[/email]
    >
    >
    >
    --


    Atte,


    Jesús Antonio Santos Giraldo
    [email]jeansagi@myrealbox.com[/email]
    [email]jeansagi@netscape.net[/email]

    sending to informix-list
    Jean Sagi Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139