# Type db_res_t

This type represents a result returned by `db_query` function (see below). The result can consist of zero or more rows (see `db_row_t` description).

A variable of type `db_res_t` returned by `db_query` function uses dynamically allocated memory, don't forget to call `db_free_result` if you don't need the variable anymore. You will encounter memory leaks if you fail to do this !

In addition to zero or more rows, each `db_res_t` object contains also an array of `db_key_t` objects. The objects represent keys (names of columns).

    typedef struct db_res {
        struct {
            db_key_t* keys;    /* Array of column names */
            db_type_t* types;  /* Array of column types */
            int n;             /* Number of columns */
        } col;
        struct db_row* rows;   /* Array of rows */
        int n;                 /* Number of rows */
    } db_res_t;

- `RES_NAMES(res)` Macro.

  Use this macro if you want to obtain pointer to an array of cell names.

  ## RES_NAMES Macro

      ...
      db_key_t* column_names = ROW_NAMES(row);
      ...

- `RES_COL_N(res)` Macro.

  Use this macro if you want to get the number of columns in the result.

  ## RES_COL_N Macro

      ...
      int ncol = RES_COL_N(res);
      for(i = 0; i < ncol; i++) {
          /* do something with the column */
      }
      ...

- `RES_ROWS(res)` Macro.

  Use this macro if you need to obtain pointer to array of rows.

  ## RES_ROWS Macro

      ...
      db_row_t* rows = RES_ROWS(res);
      ...

- `RES_ROW_N(res)` Macro.

  Use this macro if you need to obtain the number of rows in the result.

  ## RES_ROW_N Macro

      ...
      int n = RES_ROW_N(res);
      ...