Re: [Sqlrelay-discussion] the inputBindString posts the last value into the destination table repea
Brought to you by:
mused
|
From: Alfred J F. <alf...@gm...> - 2007-10-02 15:54:41
|
Hello,
This is happening because the inputBindString function associates a
pointer to a string with a variable, but does not use that pointer until the
executeQuery function is called. In your code, you associate all of your
query variables to a single pointer (body). When the executeQuery function
is called, the pointer body points to the last string you assigned it
("zxvf"). Try using different pointers for each query variable.
Good luck
On 10/2/07, Sha Li Jun <lig...@sh...> wrote:
>
> hi all:
>
> I wroten a simple C program to test the inputBindString function of
> the sqlrelay , the destination table was created in a mysql database .
> its table structure is term_no varchar(3), order_no varchar(4),
> book_name varchar(120), publisher varchar(10), and the C program
> contains follow source code to insert values into the table,
>
> #include <sqlrelay/sqlrclientwrapper.h>
> #include <string.h>
>
> int main(){
>
> char *body;
>
> sqlrcon mysql_con = sqlrcon_alloc("192.168.1.101",5900,"",
> "mydbuser","userpwd",0,1);
> sqlrcur mysql_cur = sqlrcur_alloc(mysql_con);
>
> sqlrcur_prepareQuery( mysql_cur, "insert into kb values (
> :term_no, :order_no, :book_name, :publisher )" );
>
> strcpy( body, "079" );
> sqlrcur_inputBindString( mysql_cur, "term_no", body );
> strcpy( body, "0002" );
> sqlrcur_inputBindString( mysql_cur, "order_no", body );
> strcpy( body, "abcd" );
> sqlrcur_inputBindString( mysql_cur, "book_name", body );
> strcpy( body, "zxvf" );
> sqlrcur_inputBindString( mysql_cur, "publisher", body );
> sqlrcur_executeQuery( mysql_cur );
>
> sqlrcon_commit( mysql_con );
> sqlrcur_free( mysql_cur );
> sqlrcon_free( mysql_con );
> }
>
>
> but the result of inserting is incorrect , the "zxvf" was filled in all
> of columns, in other words, the last value of the inputBindString was
> inserted by the executeQuery repeatly.
>
> term_no order_no book_name publisher
> ====================================
> zxv zxvf zxvf zxvf
>
> I could not find any mistakes in my source code, the result is so strange
> that I have no idea, anybody could help me ? thank you.
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Sqlrelay-discussion mailing list
> Sql...@li...
> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion
>
--
Alfred J Fazio,
alf...@gm...
|