[freetds] a question about RPC

李春雷 lichunlei at kingsoft.com
Wed Feb 15 23:05:22 EST 2006


hi :

    Could  you  give me some practical example of programme  which use RPC with several parameters in C languge .   i want to see  how the function of  ct_command ,ct_param   work   , and  how to deal with the results .     thanks .

                                                                                                                                             Leo



----- Original Message ----- 
From: <freetds-request at lists.ibiblio.org>
To: <freetds at lists.ibiblio.org>
Sent: Tuesday, February 14, 2006 1:00 AM
Subject: [½ðɽ¶¾°Ôʶ±ð´ËÓʼþΪÀ¬»øÓʼþ]FreeTDS Digest, Vol 37, Issue 15


> Send FreeTDS mailing list submissions to
> freetds at lists.ibiblio.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.ibiblio.org/mailman/listinfo/freetds
> or, via email, send a message with subject or body 'help' to
> freetds-request at lists.ibiblio.org
> 
> You can reach the person managing the list at
> freetds-owner at lists.ibiblio.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of FreeTDS digest..."
> 
> 
> Today's Topics:
> 
>   1. a   question  about   transaction (=?gb2312?B?wO60usDX?=)
>   2. Re: a   question  about   transaction (ZIGLIO, Frediano, VF-IT)
>   3. Re: a   question  about   transaction (Thompson, Bill D (London))
>   4. Re: MS SQL Server 2005 and FreeTDS (Jeff Dahl)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Mon, 13 Feb 2006 20:23:39 +0800
> From: =?gb2312?B?wO60usDX?= <lichunlei at kingsoft.com>
> Subject: [freetds] a   question  about   transaction
> To: <freetds-request at lists.ibiblio.org>
> Cc: <freetds at lists.ibiblio.org>
> Message-ID: <001c01c63098$51e62f80$b90ba8c0 at kingsoft.cn>
> Content-Type: text/plain; charset="gb2312"
> 
> hi:
> 
>   i am writing a programme which execute a transaction by freetds ,  however  , there is a strange instance that no  code is returned ,but the sqlserver data had been influenced  .   i need the returnd code to execute the next step.  but nothing.
> 
> 
> i use the function run_command which is  programmed by myself to execute sql sentence which have no returned result. 
> 
> 
> function:
> 
> 
> /* Run commands from which we expect no results returned */ 
> // Update,insert,delete
> static inline CS_RETCODE run_command(CS_COMMAND * cmd, const char *sql )
> {
> CS_RETCODE ret, results_ret;
> CS_INT result_type;
> 
> if (cmd == NULL) return CS_FAIL;
> if (ct_command(cmd, CS_LANG_CMD, sql, CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) return CS_FAIL;
> if (ct_send(cmd) != CS_SUCCEED) return CS_FAIL;
> 
> while ( (results_ret = ct_results( cmd , &result_type ) ) == CS_SUCCEED )
> {
>  switch ((int) result_type) 
>  {
>  case CS_CMD_SUCCEED:
>   break;
>  case CS_CMD_DONE:
>   break;
>  case CS_CMD_FAIL:
>   return E_NORMAL;
>  default:
>   return CS_FAIL;
>  }
> } 
> switch ( (int) results_ret ) 
> {
> case CS_END_RESULTS:
>  break;
> case CS_FAIL:
> default:
>  return CS_FAIL;
> }
> 
> return CS_SUCCEED;
> }
> 
> 
> the transaction is :
> snprintf( szInsert,
>  SQL_BUFFER_LENGTH,
>  "BEGIN TRANSACTION addnewcarduser "
>  "Insert into authinfo2( uid,password) values( \'%s\',\'%s\')"
>  "Insert into secuinfo( uid,password2) values( \'%s\',\'%s\')"
>  "insert into statinfo(uid,reg_date,reg_ip) values( \'%s\',\'%s\' ,%d)"
>  "insert into last_login(uid,last_login_time,last_login_ip) values( \'%s\',\'%s\',%d)"
>  "insert into userinfo(uid) values( \'%s\')"
>  "insert into money(uid) values( \'%s\')"
>  "insert into point(uid) values( \'%s\')"
>  "update secuinfo set user_type=user_type+power(2,2) ,service=service+power(2,3) where uid = \'%s\'" 
>        "insert into op_log(uid,op_type,op_time,op_detail,op_ip) values( \'%s\',11,\'%s\','????????????????',%d)"
>  "COMMIT TRANSACTION addnewcarduser",
>       val->username ,
>  val->password ,
>        val->username ,
>  val->password ,
>  val->username ,
>  ChangeTmFormat(val->currentdate,szTime) ,
>  val->userip ,
>  val->username ,
>  ChangeTmFormat(val->currentdate,szTime) ,
>  val->userip ,
>        val->username ,
>        val->username ,
>  val->username ,
>        val->username ,
>  val->username ,
>  ChangeTmFormat(val->currentdate,szTime) ,
>  val->userip );
> 
> 
> please tell me  how to get the return code .
> 
> ------------------------------
> 
> Message: 2
> Date: Mon, 13 Feb 2006 14:01:39 +0100
> From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio at vodafone.com>
> Subject: Re: [freetds] a   question  about   transaction
> To: "FreeTDS Development Group" <freetds at lists.ibiblio.org>
> Message-ID:
> <F7F148C986A2A84F930FEB8C3B169EA002FBC588 at OPDMEXO01.omnitel.it>
> Content-Type: text/plain; charset="utf-8"
> 
>> 
>> hi:
>> 
>>    i am writing a programme which execute a transaction by 
>> freetds ,  however  , there is a strange instance that no  
>> code is returned ,but the sqlserver data had been influenced  
>> .   i need the returnd code to execute the next step.  but nothing.
>> 
>> 
>> i use the function run_command which is  programmed by myself 
>> to execute sql sentence which have no returned result. 
>> 
>> 
>> function:
>> 
>> 
>> /* Run commands from which we expect no results returned */ 
>> // Update,insert,delete
>> static inline CS_RETCODE run_command(CS_COMMAND * cmd, const 
>> char *sql )
>> {
>>  CS_RETCODE ret, results_ret;
>>  CS_INT result_type;
>>  
>>  if (cmd == NULL) return CS_FAIL;
>>  if (ct_command(cmd, CS_LANG_CMD, sql, CS_NULLTERM, 
>> CS_UNUSED) != CS_SUCCEED) return CS_FAIL;
>>  if (ct_send(cmd) != CS_SUCCEED) return CS_FAIL;
>> 
>>  while ( (results_ret = ct_results( cmd , &result_type ) ) == 
>> CS_SUCCEED )
>>  {
>>   switch ((int) result_type) 
>>   {
>>   case CS_CMD_SUCCEED:
>>    break;
>>   case CS_CMD_DONE:
>>    break;
>>   case CS_CMD_FAIL:
>>    return E_NORMAL;
>>   default:
>>    return CS_FAIL;
>>   }
>>  } 
>>  switch ( (int) results_ret ) 
>>  {
>>  case CS_END_RESULTS:
>>   break;
>>  case CS_FAIL:
>>  default:
>>   return CS_FAIL;
>>  }
>> 
>>  return CS_SUCCEED;
>> }
>> 
> 
> I'm not a CTLib expert so I can't help here
> 
>> 
>> the transaction is :
>> snprintf( szInsert,
>>   SQL_BUFFER_LENGTH,
>>   "BEGIN TRANSACTION addnewcarduser "
>>   "Insert into authinfo2( uid,password) values( \'%s\',\'%s\')"
>>   "Insert into secuinfo( uid,password2) values( \'%s\',\'%s\')"
>>   "insert into statinfo(uid,reg_date,reg_ip) values( 
>> \'%s\',\'%s\' ,%d)"
>>   "insert into last_login(uid,last_login_time,last_login_ip) 
>> values( \'%s\',\'%s\',%d)"
>>   "insert into userinfo(uid) values( \'%s\')"
>>   "insert into money(uid) values( \'%s\')"
>>   "insert into point(uid) values( \'%s\')"
>>   "update secuinfo set user_type=user_type+power(2,2) 
>> ,service=service+power(2,3) where uid = \'%s\'" 
>>         "insert into 
>> op_log(uid,op_type,op_time,op_detail,op_ip) values( 
>> \'%s\',11,\'%s\','????????',%d)"
>>   "COMMIT TRANSACTION addnewcarduser",
>>        val->username ,
>>   val->password ,
>>         val->username ,
>>   val->password ,
>>   val->username ,
>>   ChangeTmFormat(val->currentdate,szTime) ,
>>   val->userip ,
>>   val->username ,
>>   ChangeTmFormat(val->currentdate,szTime) ,
>>   val->userip ,
>>         val->username ,
>>         val->username ,
>>   val->username ,
>>         val->username ,
>>   val->username ,
>>   ChangeTmFormat(val->currentdate,szTime) ,
>>   val->userip );
>> 
> 
> Here I see some problems:
> - sql injection (%s is not suffucient, string should be quoted)
> - error handling, usually I write code like
>  BEGIN TRANSACTION
>  insert 1 ...
>  IF @@ERROR <> 0
>    insert 2 ...
>  .. and so on ..
>  IF @@ERROR <> 0 COMMIT ELSE ROLLBACK
> 
> now, which error aren't you able to catch?
> 
> freddy77
> 
> ------------------------------
> 
> Message: 3
> Date: Mon, 13 Feb 2006 13:16:01 -0000
> From: "Thompson, Bill D (London)" <bill_d_thompson at ml.com>
> Subject: Re: [freetds] a   question  about   transaction
> To: "FreeTDS Development Group" <freetds at lists.ibiblio.org>
> Message-ID:
> <EA147559111B6D489258F903ADB90878063193DE at mllna201mb.uk.ml.com>
> Content-Type: text/plain; charset="gb2312"
> 
> Hi,
> 
> You say you have a "strange instance" where "no code is returned"...
> 
> from where is "no code returned" ? from ct_results ? or from your run_command() function ?
> 
> what return code are you trying to capture ?
> is it the successful completion of all the commands you have submitted ?
> 
> I would capture and print out all the returns from ct_results, which should help to make it clearer.
> 
> I would say, as long as you never get CS_CMD_FAIL returned from ct_results() your commands have worked.
> 
> By the way, I think you should implement the addnewcarduser functionality as  
> a stored procedure, into which you pass username, password and userip 
> (maybe current date too, although the stored proc could work that out for you.)
> 
> 
> Bill
> 
> 
> 
> 
> 
> -----Original Message-----
> From: freetds-bounces at lists.ibiblio.org [mailto:freetds-bounces at lists.ibiblio.org] On Behalf Of lichunlei at kingsoft.com
> Sent: 13 February 2006 12:24
> To: freetds-request at lists.ibiblio.org
> Cc: freetds at lists.ibiblio.org
> Subject: [freetds] a question about transaction
> 
> 
> hi:
> 
>   i am writing a programme which execute a transaction by freetds ,  however  , there is a strange instance that no  code is returned ,but the sqlserver data had been influenced  .   i need the returnd code to execute the next step.  but nothing.
> 
> 
> i use the function run_command which is  programmed by myself to execute sql sentence which have no returned result. 
> 
> 
> function:
> 
> 
> /* Run commands from which we expect no results returned */ 
> // Update,insert,delete
> static inline CS_RETCODE run_command(CS_COMMAND * cmd, const char *sql )
> {
> CS_RETCODE ret, results_ret;
> CS_INT result_type;
> 
> if (cmd == NULL) return CS_FAIL;
> if (ct_command(cmd, CS_LANG_CMD, sql, CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) return CS_FAIL;
> if (ct_send(cmd) != CS_SUCCEED) return CS_FAIL;
> 
> while ( (results_ret = ct_results( cmd , &result_type ) ) == CS_SUCCEED )
> {
>  switch ((int) result_type) 
>  {
>  case CS_CMD_SUCCEED:
>   break;
>  case CS_CMD_DONE:
>   break;
>  case CS_CMD_FAIL:
>   return E_NORMAL;
>  default:
>   return CS_FAIL;
>  }
> } 
> switch ( (int) results_ret ) 
> {
> case CS_END_RESULTS:
>  break;
> case CS_FAIL:
> default:
>  return CS_FAIL;
> }
> 
> return CS_SUCCEED;
> }
> 
> 
> the transaction is :
> snprintf( szInsert,
>  SQL_BUFFER_LENGTH,
>  "BEGIN TRANSACTION addnewcarduser "
>  "Insert into authinfo2( uid,password) values( \'%s\',\'%s\')"
>  "Insert into secuinfo( uid,password2) values( \'%s\',\'%s\')"
>  "insert into statinfo(uid,reg_date,reg_ip) values( \'%s\',\'%s\' ,%d)"
>  "insert into last_login(uid,last_login_time,last_login_ip) values( \'%s\',\'%s\',%d)"
>  "insert into userinfo(uid) values( \'%s\')"
>  "insert into money(uid) values( \'%s\')"
>  "insert into point(uid) values( \'%s\')"
>  "update secuinfo set user_type=user_type+power(2,2) ,service=service+power(2,3) where uid = \'%s\'" 
>        "insert into op_log(uid,op_type,op_time,op_detail,op_ip) values( \'%s\',11,\'%s\','????????????????',%d)"
>  "COMMIT TRANSACTION addnewcarduser",
>       val->username ,
>  val->password ,
>        val->username ,
>  val->password ,
>  val->username ,
>  ChangeTmFormat(val->currentdate,szTime) ,
>  val->userip ,
>  val->username ,
>  ChangeTmFormat(val->currentdate,szTime) ,
>  val->userip ,
>        val->username ,
>        val->username ,
>  val->username ,
>        val->username ,
>  val->username ,
>  ChangeTmFormat(val->currentdate,szTime) ,
>  val->userip );
> 
> 
> please tell me  how to get the return code .
> --------------------------------------------------------
> 
> If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail.     http://www.ml.com/email_terms/
> --------------------------------------------------------
> 
> 
> ------------------------------
> 
> Message: 4
> Date: Mon, 13 Feb 2006 09:13:10 -0700
> From: Jeff Dahl <jddahl at micron.com>
> Subject: Re: [freetds] MS SQL Server 2005 and FreeTDS
> To: FreeTDS Development Group <freetds at lists.ibiblio.org>
> Message-ID: <43F0B016.9030302 at micron.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> 
> 
> Frediano Ziglio wrote:
> 
>>Il giorno ven, 10/02/2006 alle 18.01 -0700, Jeff Dahl ha scritto:
>>  
>>
>>>Why does this query
>>>
>>>    CREATE TABLE #data( myID varchar( 25 ))
>>>    INSERT into #data select myID from myTable where myID = 'data1'
>>>    INSERT into #data select myID from myTable where myID = 'data2'
>>>    CREATE index myindex on #data (myID)
>>>    SELECT myID
>>>    FROM #data, myTable
>>>    WHERE ( #data.myID = myTable.myID )
>>>    DROP TABLE #data
>>>
>>>generate this error:
>>>
>>>    SQL_STATE: 24000
>>>    NATIVE_ERROR: 0
>>>    MSG: [FreeTDS][SQL Server]Invalid cursor state
>>>    MSG_LEN: 41
>>>
>>>I've tried this with both 0.63 and the latest CVS version.  Only the CVS
>>>version gives the error.  Version 0.63 doesn't return anything.
>>>
>>>Thanks,
>>>Jeff Dahl
>>>
>>>    
>>>
>>
>>Is difficult do reply to your question without knowing the tool you are
>>using... I suppose is a ODBC tool like isql. Or is it a program you
>>wrote? 
>>
> I wrote the program using the ODBC API.  However, if I run the same 
> query with with tsql (v0.63 and CVS), the data is returned correctly.  
> Looks like the problem is in the ODBC layer.
> 
>>Does myTable contain 'data1' and 'data2' ?
>>  
>>
> Yes.
> 
>>0.63 version reply is wrong, while CVS is a bit... futuristic... We
>>already started a new branch so CVS is not the next coming release but
>>the release AFTER the coming release... However fixing problem before
>>any release is feasible...
>>
>>freddy77
>>
>>
>>_______________________________________________
>>FreeTDS mailing list
>>FreeTDS at lists.ibiblio.org
>>http://lists.ibiblio.org/mailman/listinfo/freetds
>>
>>  
>>
> 
> 
> ------------------------------
> 
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
> 
> 
> End of FreeTDS Digest, Vol 37, Issue 15
> ***************************************
>


More information about the FreeTDS mailing list