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

Function db_mysql_fetch_result

modules/db_mysql/dbase.c:1030–1146  ·  view source on GitHub ↗

* Gets a partial result set. * \param _h structure representing the database connection * \param _r pointer to a structure representing the result * \param nrows number of fetched rows * \return zero on success, negative value on failure */

Source from the content-addressed store, hash-verified

1028 * \return zero on success, negative value on failure
1029 */
1030int db_mysql_fetch_result(const db_con_t* _h, db_res_t** _r, const int nrows)
1031{
1032 int rows, i;
1033
1034 if (!_h || !_r || nrows < 0) {
1035 LM_ERR("Invalid parameter value\n");
1036 return -1;
1037 }
1038
1039 /* exit if the fetch count is zero */
1040 if (nrows == 0) {
1041 db_free_result(*_r);
1042 *_r = 0;
1043 return 0;
1044 }
1045
1046 if(*_r==0) {
1047 /* Allocate a new result structure */
1048 *_r = db_new_result();
1049 if (*_r == 0) {
1050 LM_ERR("no memory left\n");
1051 return -2;
1052 }
1053
1054 if (!CON_HAS_PS(_h))
1055 CON_RESULT(_h) = mysql_store_result(CON_CONNECTION(_h));
1056 if (!CON_RESULT(_h)) {
1057 if (mysql_errno(CON_CONNECTION(_h)) > 0) {
1058 LM_ERR("driver error: %s\n", mysql_error(CON_CONNECTION(_h)));
1059 db_free_result(*_r);
1060 *_r = 0;
1061 return -3;
1062 }
1063
1064 if (mysql_field_count(CON_CONNECTION(_h)) == 0) {
1065 (*_r)->col.n = 0;
1066 (*_r)->n = 0;
1067 return 0;
1068 }
1069 }
1070
1071 if (db_mysql_get_columns(_h, *_r) < 0) {
1072 LM_ERR("error while getting column names\n");
1073 return -4;
1074 }
1075
1076 if (CON_HAS_PS(_h)) {
1077 RES_NUM_ROWS(*_r) = mysql_stmt_num_rows(CON_PS_STMT(_h));
1078 } else {
1079 RES_NUM_ROWS(*_r) = mysql_num_rows(CON_RESULT(_h));
1080 }
1081 if (!RES_NUM_ROWS(*_r)) {
1082 LM_DBG("no rows returned from the query\n");
1083 RES_ROWS(*_r) = 0;
1084 return 0;
1085 }
1086
1087 } else {

Callers

nothing calls this directly

Calls 6

db_free_resultFunction · 0.85
db_new_resultFunction · 0.85
db_mysql_get_columnsFunction · 0.85
db_free_rowsFunction · 0.85
db_allocate_rowsFunction · 0.85
db_mysql_convert_rowFunction · 0.85

Tested by

no test coverage detected