Re: Dynamic Sql Q (esqlc)
Posted in 1996
Jeff Pickett wrote:
>
> I am looking some help writing dynamic sql in esqlc. I have been
> trying to use the manuals for direction, but I still can't get it
> to work. Allow me to explain the scenario.
>
> I want to dynamically form an insert statement, prepare it once,
> and then execute it multiple times with different data. So it
> seems to me that this is a job for dynamic sql. After getting
> thouroughly confused by the manuals, this is what I come up with.
>
> NOTE: This is just a little proof of concept program, and everything
> is hardwired. I just want to get this part working first.
>
> snip [ c-program ]
>
> I get a segmentation fault when I execute the statement. Any help
> or example code would be greatly appreciated.
>
> Thanks,
>
> Jeff Pickett
> --
Hi Jeff,
I'm not the best programmer (espacially C is not my preferred language). However,
I wrote some ESQL/C-programs using Dynamic SQL. In your case, I'd suggest the
following code:
$ char sql_stmt[MAXSQLSTMT];
$ int hv_rx_numbr;
$ xxx hv_dt_flld;
int i;
strcpy(sql_stmt, "INSERT INTO rmttncadv (rmttncadvsrl, rx_nmbr, dt_flld)");
strcat(sql_stmt, " VALUES ( 0, ?, ? );" );
$ PREPARE stmt_id FROM $sql_stmt;
$ EXECUTE stmt_id USING :hv_rx_numbr, :hv_dt_flld;
$ FREE stmt_id;
Hope this helps,
Peter