[Devel] unixodbc reconnect & stored procedures

Alex Gradinar Alex.Gradinar at cartel.md
Wed Mar 15 18:31:32 CET 2006


Hello Daniel,

Did you receive my patch?
I generated a patch and send you as attachment.
I didn't post it on the tracker on sourceforge.
Could you post it?

I've done another patch which  implements using call of stored procedure instead 
of use insert/delete/update.
I've attached it.

There is a #define SQL_PROC which switch on using stored procedure in function
db_insert, db_delete, db_update and db_replace.

The SQL syntax
{call <oper>_<table>(p_field1=value1,..,p_fieldN=valueN)}
where <oper> may be: insert, delete, update and replace
<table> is a name of table
field1 - filedN  are names of fields

For example:
{call insert_location 
(p_username='123',p_contact='sip:123 at 1.2.3.4:5060',p_expires='2006-03-15 
18:39:47',
p_q=-1.00,p_callid='1234',p_cseq=2,p_flags=0,p_user_agent='X-PRO release 
1105x',p_received=NULL,p_socket='1.2.3.5_5060')}

{call update_location (p_expires='2006-03-15 
18:56:03',p_q=-1.00,p_callid='1235',p_cseq=3,p_flags=0,
p_user_agent='X-PRO release 1105x',p_received=NULL,p_socket='1.2.3.5_5060',
pp_user_name='123',pp_contact='sip:123 at 1.2.3.4:5060')}

{call delete_location (p_user_name='123',p_contact='sip:123 at 1.2.3.4:5060')}


This patch also fix one small bug in function db_update
In the origin code the query string is null terminated only if exist 'where' 
parameters.
Origin code is
========
 if (_n)
 {
  ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " where ");
  if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
  off += ret;

  ret = print_where(&CON_CONNECTION(_h), sql_buf + off, SQL_BUF_LEN - off, _k, 
_o, _v, _n);
  if (ret < 0) return -1;
  off += ret;

  *(sql_buf + off) = '\0';
 }
========
The correct code is
========
 if (_n)
 {
  ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " where ");
  if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
  off += ret;

  ret = print_where(&CON_CONNECTION(_h), sql_buf + off, SQL_BUF_LEN - off, _k, 
_o, _v, _n);
  if (ret < 0) return -1;
  off += ret;
 }

*(sql_buf + off) = '\0';
========


Best regards,
Alex Gradinar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unixodbc-sql-procs.patch
Type: application/octet-stream
Size: 7065 bytes
Desc: not available
Url : http://openser.org/pipermail/devel/attachments/20060315/a81e96ce/unixodbc-sql-procs.obj


More information about the Devel mailing list