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

Function db_sqlite_replace

modules/db_sqlite/dbase.c:585–625  ·  view source on GitHub ↗

* Just like insert, but replace the row if it exists. * \param _h database handle * \param _k key names * \param _v values of the keys that must match * \param _n number of key=value pairs * \return zero on success, negative value on failure */

Source from the content-addressed store, hash-verified

583 * \return zero on success, negative value on failure
584 */
585int db_sqlite_replace(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n)
586{
587 int ret;
588 sqlite3_stmt* stmt;
589#ifdef SQLITE_BIND
590 db_ps_t ps;
591
592 CON_SET_CURR_PS(_h, &ps);
593#else
594 CON_RESET_CURR_PS(_h);
595#endif
596 ret = db_do_replace(_h, _k, _v, _n, db_sqlite_val2str,
597 db_sqlite_submit_dummy_query);
598 if (ret != 0) {
599 return ret;
600 }
601
602 ret=sqlite3_prepare_v2(CON_CONNECTION(_h),
603 query_holder.s, query_holder.len, &stmt, NULL);
604 if (ret!=SQLITE_OK)
605 LM_ERR("failed to prepare: (%s)\n",
606 sqlite3_errmsg(CON_CONNECTION(_h)));
607
608#ifdef SQLITE_BIND
609 if (db_sqlite_bind_values(stmt, _v, _n) != SQLITE_OK) {
610 LM_ERR("failed to bind values\n");
611 return -1;
612 }
613#endif
614
615 ret = sqlite3_step(stmt);
616
617 if (ret != SQLITE_DONE) {
618 LM_ERR("insert query failed %s\n", sqlite3_errmsg(CON_CONNECTION(_h)));
619 return -1;
620 }
621
622 sqlite3_finalize(stmt);
623
624 return 0;
625}
626
627/**
628 * Returns the last inserted ID.

Callers

nothing calls this directly

Calls 2

db_do_replaceFunction · 0.85
db_sqlite_bind_valuesFunction · 0.85

Tested by

no test coverage detected