[OpenSIPS-Users] Why does avp_db_query rise an error when my SQL is correct?

Rodrigo Pimenta Carvalho pimenta at inatel.br
Thu Nov 5 21:45:12 CET 2015



Hi.


My SQL query is:


UPDATE GeneralConfigurations set Value = 'casa' where Attribute = 'Exists_Intercom_Call'


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.


However, when this query is passed to avp_db_query, the OpenSIPS logs:


-----------------------------------------------------------------------------------------------------------------------


Nov  5 18:25:53 [5655] DBG:avpops:ops_dbquery_avps: query [UPDATE GeneralConfigurations set Value = 'casa' where Attribute = 'Exists_Intercom_Call']
Nov  5 18:25:53 [5655] ERROR:db_sqlite:db_sqlite_raw_query: query failed: near "UPDATE": syntax error

Nov  5 18:25:53 [5655] ERROR:avpops:db_query_avp: raw_query failed: db0(usr_preferences) UPDATE GeneralConfigurations set Value =...


--------------------------------------------------------------------------------------------------------------------------------


Can someone visualize what is the problem?  Help, please.


Observations:


1. I'm using OpenSIPS 2.2 and SQLite 3.


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:



..............................................................................................................................................................



int db_sqlite_raw_query(const db_con_t* _h, const str* _s, db_res_t** _r)
{
        static char sql_str[SQL_BUF_LEN];
        int ret=-1;
        char* errmsg;
//      str select_str={"select", 6};

       CON_RESET_CURR_PS(_h);
       if (_s->len + 1 > SQL_BUF_LEN) {
         LM_ERR("query too big! try reducing the size of your query!"
        "Current max size [%d]!\n", SQL_BUF_LEN);
        return -1;
        }
        memcpy(sql_str, _s->s, _s->len);
        sql_str[_s->len] = '\0';

       char *saveptr;
       char *cpFrstWrd;
       char *cpScndWrd;

       cpFrstWrd = strtok_r(sql_str, " ", &saveptr);
       cpScndWrd = strtok_r(NULL, " ", &saveptr);


       if (!((strncasecmp(cpFrstWrd, "SELECT", 6)==0)   || (strncasecmp(cpScndWrd, "SELECT", 6)==0))){   // now it will refuse queries with SELECT just when SELECT is in the beginning of the query.

       //if (!str_strstr(_s, &select_str)) {
                /* not a select statement; can execute the query and exit*/
                if (sqlite3_exec(CON_CONNECTION(_h),
                        sql_str, NULL, NULL, &errmsg)) {
                        LM_ERR("query failed: %s\n", errmsg);
                        return -2;
                }

                return 0;
        }

// more logic follows here....


................................................................................................................................................



Any hint will be very helpful!!


Best regards.



RODRIGO PIMENTA CARVALHO
Inatel Competence Center
Software
Ph: +55 35 3471 9200 RAMAL 979
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20151105/9f247177/attachment.htm>


More information about the Users mailing list