MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / db_sqlite_update

Function db_sqlite_update

modules/db_sqlite/dbase.c:532–575  ·  view source on GitHub ↗

* Update some rows in the specified table * \param _h structure representing database connection * \param _k key names * \param _o operators * \param _v values of the keys that must match * \param _uk updated columns * \param _uv updated values of the columns * \param _n number of key=value pairs * \param _un number of columns to update * \return zero on success, negative value on failure

Source from the content-addressed store, hash-verified

530 * \return zero on success, negative value on failure
531 */
532int db_sqlite_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
533 const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n,
534 const int _un)
535{
536 int ret;
537 sqlite3_stmt* stmt;
538#ifdef SQLITE_BIND
539 db_ps_t ps;
540
541 CON_SET_CURR_PS(_h, &ps);
542#else
543 CON_RESET_CURR_PS(_h);
544#endif
545 ret = db_do_update(_h, _k, _o, _v, _uk, _uv, _n, _un,
546 db_sqlite_val2str, db_sqlite_submit_dummy_query);
547 if (ret != 0) {
548 return ret;
549 }
550
551 ret=sqlite3_prepare_v2(CON_CONNECTION(_h),
552 query_holder.s, query_holder.len, &stmt, NULL);
553 if (ret!=SQLITE_OK)
554 LM_ERR("failed to prepare: (%s)\n",
555 sqlite3_errmsg(CON_CONNECTION(_h)));
556
557#ifdef SQLITE_BIND
558 if (db_sqlite_bind_values(stmt, _uv, _un) != SQLITE_OK
559 && db_sqlite_bind_values(stmt, _v, _n)) {
560 LM_ERR("failed to bind values\n");
561 return -1;
562 }
563#endif
564
565 ret = sqlite3_step(stmt);
566
567 if (ret != SQLITE_DONE) {
568 LM_ERR("insert query failed %s\n", sqlite3_errmsg(CON_CONNECTION(_h)));
569 return -1;
570 }
571
572 sqlite3_finalize(stmt);
573
574 return 0;
575}
576
577/**
578 * Just like insert, but replace the row if it exists.

Callers

nothing calls this directly

Calls 2

db_do_updateFunction · 0.85
db_sqlite_bind_valuesFunction · 0.85

Tested by

no test coverage detected