Ejemplo n.º 1
0
Archivo: res.c Proyecto: mtulio/mtulio
/**
 * Convert a row from the result query into db API representation
 */
int db_postgres_convert_row(const db_con_t* _h, db_res_t* _r, db_row_t* _row,
		char **row_buf)
{
	int col, len;

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

	/* Save the number of columns in the ROW structure */
	ROW_N(_row) = RES_COL_N(_r);

	/* For each column in the row */
	for(col = 0; col < ROW_N(_row); col++) {
		/* compute the len of the value */
		if ( row_buf[col]==NULL || row_buf[col][0]=='\0')
			len = 0;
		else
			len =  strlen(row_buf[col]);

		/* Convert the string representation into the value representation */
		if (db_postgres_str2val(RES_TYPES(_r)[col], &(ROW_VALUES(_row)[col]),
		row_buf[col], len) < 0) {
			LM_ERR("failed to convert value\n");
			LM_DBG("free row at %pn", _row);
			db_free_row(_row);
			return -3;
		}
	}
	return 0;
}
Ejemplo n.º 2
0
/*!
 * \brief Convert a row from the result query into db API representation
 * \param _h database connection
 * \param _r result set
 * \param _row row
 * \param row_buf row buffer
 * \return 0 on success, negative on error
 */
int db_postgres_convert_row(const db1_con_t* _h, db1_res_t* _r, db_row_t* _row,
                            char **row_buf)
{
    int col, col_len;

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

    if (db_allocate_row(_r, _row) != 0) {
        LM_ERR("could not allocate row\n");
        return -2;
    }

    /* For each column in the row */
    for(col = 0; col < ROW_N(_row); col++) {
        /* because it can contain NULL */
        if (!row_buf[col]) {
            col_len = 0;
        } else {
            col_len = strlen(row_buf[col]);
        }
        /* Convert the string representation into the value representation */
        if (db_postgres_str2val(RES_TYPES(_r)[col], &(ROW_VALUES(_row)[col]),
                                row_buf[col], col_len) < 0) {
            LM_ERR("failed to convert value\n");
            LM_DBG("free row at %p\n", _row);
            db_free_row(_row);
            return -3;
        }
    }
    return 0;
}