<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p><br>
</p>
<p><br>
</p>
<p>Hi.</p>
<p><br>
</p>
<p>My SQL query is: <br>
</p>
<p><br>
</p>
<p><i>UPDATE GeneralConfigurations set Value = 'casa' where Attribute = 'Exists_Intercom_Call'</i></p>
<p><br>
</p>
<p>This query is correct and can execute very well when applied via a Firefox plugin for SQLite. So, I believe that such query is really correct.</p>
<p><br>
</p>
<p>However, when this query is passed to avp_db_query, the OpenSIPS logs:</p>
<p><br>
</p>
<p>-----------------------------------------------------------------------------------------------------------------------</p>
<p><br>
</p>
<p>Nov 5 18:25:53 [5655] DBG:avpops:ops_dbquery_avps: query [UPDATE GeneralConfigurations set Value = 'casa' where Attribute = 'Exists_Intercom_Call']<br>
Nov 5 18:25:53 [5655] ERROR:db_sqlite:db_sqlite_raw_query: query failed: near "UPDATE": syntax error<br>
</p>
<p>Nov 5 18:25:53 [5655] ERROR:avpops:db_query_avp: raw_query failed: db0(usr_preferences) UPDATE GeneralConfigurations set Value =...</p>
<p><br>
</p>
<p>--------------------------------------------------------------------------------------------------------------------------------</p>
<p><br>
</p>
<p>Can someone visualize what is the problem? Help, please.</p>
<p><br>
</p>
<p>Observations:</p>
<p><br>
</p>
<p>1. I'm using OpenSIPS 2.2 and SQLite 3.</p>
<p><br>
</p>
<p>2. I have changed the OpenSIPS dbase.c file on my own. (Following some hints gotten in this discussion list). So, I have changed the function db_sqlite_raw_query and now its code has these instructions:</p>
<p><br>
</p>
<p><br>
</p>
<p>..............................................................................................................................................................</p>
<p><br>
</p>
<p><br>
</p>
<p>int db_sqlite_raw_query(const db_con_t* _h, const str* _s, db_res_t** _r)<br>
{<br>
static char sql_str[SQL_BUF_LEN];<br>
int ret=-1;<br>
char* errmsg;<br>
// str select_str={"select", 6};<br>
<br>
CON_RESET_CURR_PS(_h);<br>
if (_s->len + 1 > SQL_BUF_LEN) {<br>
LM_ERR("query too big! try reducing the size of your query!"<br>
"Current max size [%d]!\n", SQL_BUF_LEN);<br>
return -1;<br>
}<br>
memcpy(sql_str, _s->s, _s->len);<br>
sql_str[_s->len] = '\0';<br>
<br>
char *saveptr;<br>
char *cpFrstWrd;<br>
char *cpScndWrd;<br>
<br>
cpFrstWrd = strtok_r(sql_str, " ", &saveptr);<br>
cpScndWrd = strtok_r(NULL, " ", &saveptr);<br>
<br>
</p>
<p> if (!((strncasecmp(cpFrstWrd, "SELECT", 6)==0) || (strncasecmp(cpScndWrd, "SELECT", 6)==0))){
<b>// now it will refuse queries with SELECT just when SELECT is in the beginning of the query.</b><br>
</p>
//if (!str_strstr(_s, &select_str)) {<br>
/* not a select statement; can execute the query and exit*/<br>
if (sqlite3_exec(CON_CONNECTION(_h),<br>
sql_str, NULL, NULL, &errmsg)) {<br>
LM_ERR("query failed: %s\n", errmsg);<br>
return -2;<br>
}<br>
<br>
return 0;<br>
}<br>
<p></p>
<p>// more logic follows here....</p>
<p><br>
</p>
<p>................................................................................................................................................<br>
</p>
<br>
<p></p>
<p><br>
</p>
<p>Any hint will be very helpful!!</p>
<p><br>
</p>
<p>Best regards.<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div id="Signature">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div class="BodyFragment"><font size="2">
<div class="PlainText">RODRIGO PIMENTA CARVALHO<br>
Inatel Competence Center<br>
Software<br>
Ph: +55 35 3471 9200 RAMAL 979<br>
</div>
</font></div>
</div>
</div>
</div>
</body>
</html>