db_row.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. * Copyright (C) 2007-2008 1&1 Internet AG
  6. *
  7. * This file is part of Kamailio, a free SIP server.
  8. *
  9. * Kamailio is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * Kamailio is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. /**
  24. * \file lib/srdb1/db_row.h
  25. * \brief Type that represents a row in a database.
  26. *
  27. * This file holds a type that represents a row in a database, some convenience
  28. * macros and a function for memory managements.
  29. * \ingroup db1
  30. */
  31. #ifndef DB1_ROW_H
  32. #define DB1_ROW_H
  33. #include "db_val.h"
  34. #include "db_res.h"
  35. /**
  36. * Structure holding the result of a query table function.
  37. * It represents one row in a database table. In other words, the row is an
  38. * array of db_val_t variables, where each db_val_t variable represents exactly
  39. * one cell in the table.
  40. */
  41. typedef struct db_row {
  42. db_val_t* values; /**< Columns in the row */
  43. int n; /**< Number of columns in the row */
  44. } db_row_t;
  45. /** Return the columns in the row */
  46. #define ROW_VALUES(rw) ((rw)->values)
  47. /** Return the number of colums */
  48. #define ROW_N(rw) ((rw)->n)
  49. /**
  50. * Release memory used by a row. This method only frees values that are inside
  51. * the row if the free flag of the specific value is set. Otherwise this
  52. * storage must be released when the database specific result free function is
  53. * called. Only string based values are freed if wanted, null values are skipped.
  54. * \param _r row that should be released
  55. * \return zero on success, negative on error
  56. */
  57. int db_free_row(db_row_t* _r);
  58. /**
  59. * Allocate memory for row value.
  60. * \param _res result set
  61. * \param _row filled row
  62. * \return zero on success, negative on errors
  63. */
  64. int db_allocate_row(const db1_res_t* _res, db_row_t* _row);
  65. #endif /* DB1_ROW_H */