Example #1
0
/*
 * Insert a row into specified table
 * _con: structure representing database connection
 * _k: key names
 * _v: values of the keys
 * _n: number of key=value pairs
 */
int db_postgres_insert(const db_con_t* _h, const db_key_t* _k, 
		const db_val_t* _v, const int _n)
{
	db_res_t* _r = NULL;

	CON_RESET_CURR_PS(_h); /* no prepared statements support */
	int tmp = db_do_insert(_h, _k, _v, _n, db_postgres_val2str,
		db_postgres_submit_query);

	if (submit_func_called)
	{
		/* finish the async query, 
		 * otherwise the next query will not complete */

		/* only call this if the DB API has effectively called
		 * our submit_query function
		 *
		 * in case of insert queueing,
		 * it may postpone calling the insert func until
		 * enough rows have piled up */
		if (db_postgres_store_result(_h, &_r) != 0)
			LM_WARN("unexpected result returned\n");

		submit_func_called = 0;
	}
	
	if (_r)
		db_free_result(_r);

	if (CON_HAS_INSLIST(_h))
		CON_RESET_INSLIST(_h);

	return tmp;
}
Example #2
0
/*
 * Insert a row into specified table
 * _con: structure representing database connection
 * _k: key names
 * _v: values of the keys
 * _n: number of key=value pairs
 */
int db_postgres_insert(const db_con_t* _h, const db_key_t* _k,
		const db_val_t* _v, const int _n)
{
	db_res_t* _r = NULL;

	CON_RESET_CURR_PS(_h); /* no prepared statements support */

	/* This needs to be reset before each call to db_do_insert.
	   This is only used by inserts, but as a side effect delete and updates
	   will set it to 1 without resetting it. */
	submit_func_called = 0;

	int tmp = db_do_insert(_h, _k, _v, _n, db_postgres_val2str,
		db_postgres_submit_query);

	/* For bulk queries the insert may not be submitted until enough rows are queued */
	if (submit_func_called)
	{
		/* Query was submitted.
		   Result must be handled. */
		if (db_postgres_store_result(_h, &_r) != 0)
			LM_WARN("unexpected result returned\n");
	}

	if (_r)
		db_free_result(_r);

	if (CON_HAS_INSLIST(_h))
		CON_RESET_INSLIST(_h);

	return tmp;
}
Example #3
0
/**
 * Insert a row into a specified table.
 * \param _h structure representing database connection
 * \param _k key names
 * \param _v values of the keys
 * \param _n number of key=value pairs
 * \return zero on success, negative value on failure
 */
int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
		const int _n)
{
	if(unlikely(db_mysql_insert_all_delayed==1))
		return db_do_insert_delayed(_h, _k, _v, _n, db_mysql_val2str,
				db_mysql_submit_query);
	else
		return db_do_insert(_h, _k, _v, _n, db_mysql_val2str,
				db_mysql_submit_query);
}
Example #4
0
/*!
 * \brief Insert a row into specified table
 * \param _h structure representing database connection
 * \param _k key names
 * \param _v values of the keys
 * \param _n number of key=value pairs
 * \return 0 on success, negative on failure
 */
int db_postgres_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
		const int _n)
{
	db1_res_t* _r = NULL;

	int tmp = db_do_insert(_h, _k, _v, _n, db_postgres_val2str, db_postgres_submit_query);
	// finish the async query, otherwise the next query will not complete
	if (db_postgres_store_result(_h, &_r) != 0)
		LM_WARN("unexpected result returned");
	
	if (_r)
		db_free_result(_r);

	return tmp;
}
Example #5
0
int db_sqlite_insert(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n)
{
	int ret=-1;
	sqlite3_stmt* stmt;
#ifdef SQLITE_BIND
	db_ps_t ps;

	CON_SET_CURR_PS(_h, &ps);
#else
	CON_RESET_CURR_PS(_h);
#endif
	ret = db_do_insert(_h, _k, _v, _n, db_sqlite_val2str,
								db_sqlite_submit_dummy_query);
	if (ret != 0) {
		return ret;
	}

again:
	ret=sqlite3_prepare_v2(CON_CONNECTION(_h),
			query_holder.s, query_holder.len, &stmt, NULL);
	if (ret==SQLITE_BUSY)
		goto again;
	if (ret!=SQLITE_OK)
		LM_ERR("failed to prepare: (%s)\n",
				sqlite3_errmsg(CON_CONNECTION(_h)));

#ifdef SQLITE_BIND
	if ((ret=db_sqlite_bind_values(stmt, _v, _n)) != SQLITE_OK) {
		LM_ERR("failed to bind values (%d)\n", ret);
		return -1;
	}
#endif

again2:
	ret = sqlite3_step(stmt);
	if (ret==SQLITE_BUSY)
		goto again2;

	if (ret != SQLITE_DONE) {
		LM_ERR("insert query failed %s\n", sqlite3_errmsg(CON_CONNECTION(_h)));
		return -1;
	}

	sqlite3_finalize(stmt);

	return 0;
}
Example #6
0
/*
 * Insert a row into specified table
 * _h: structure representing database connection
 * _k: key names
 * _v: values of the keys
 * _n: number of key=value pairs
 */
int db_oracle_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
		int _n)
{
	query_data_t cb;
	int rc;

	if (!_h || !CON_TABLE(_h)) {
		LM_ERR("invalid parameter value\n");
		return -1;
	}

	cb._rs = NULL;
	cb._v  = _v;
	cb._n  = _n;
	cb._w  = NULL;
	cb._nw = 0;
	CON_ORA(_h)->pqdata = &cb;
	CON_ORA(_h)->bindpos = 0;
	rc = db_do_insert(_h, _k, _v, _n, db_oracle_val2str, db_oracle_submit_query);
	CON_ORA(_h)->pqdata = NULL;	/* paranoid for next call */
	return rc;
}
Example #7
0
/**
 * Insert a row into a specified table.
 * \param _h structure representing database connection
 * \param _k key names
 * \param _v values of the keys
 * \param _n number of key=value pairs
 * \return zero on success, negative value on failure
 */
int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n)
{
	return db_do_insert(_h, _k, _v, _n, db_mysql_val2str,
	db_mysql_submit_query);
}
Example #8
0
/*
 * Insert a row into specified table
 * _h: structure representing database connection
 * _k: key names
 * _v: values of the keys
 * _n: number of key=value pairs
 */
int db_unixodbc_insert(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n)
{
	CON_RESET_CURR_PS(_h); /* no prepared statements support */
	return db_do_insert(_h, _k, _v, _n, db_unixodbc_val2str,
		db_unixodbc_submit_query);
}