km_row.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * MySQL module row related functions
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. * Copyright (C) 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. /*! \file
  24. * \brief DB_MYSQL :: Row related functions
  25. * \ingroup db_mysql
  26. * Module: \ref db_mysql
  27. */
  28. #include "../../dprint.h"
  29. #include "../../mem/mem.h"
  30. #include "../../lib/srdb1/db_row.h"
  31. #include "../../lib/srdb1/db_val.h"
  32. #include "km_my_con.h"
  33. #include "km_val.h"
  34. #include "km_row.h"
  35. #include "km_res.h"
  36. /*!
  37. * \brief Convert a row from result into DB API representation
  38. * \param _h database connection
  39. * \param _res database result in the DB API representation
  40. * \param _r database result row
  41. * \return 0 on success, -1 on failure
  42. */
  43. int db_mysql_convert_row(const db1_con_t* _h, db1_res_t* _res, db_row_t* _r)
  44. {
  45. unsigned long* lengths;
  46. int i;
  47. if ((!_h) || (!_res) || (!_r)) {
  48. LM_ERR("invalid parameter value\n");
  49. return -1;
  50. }
  51. if (db_allocate_row(_res, _r) != 0) {
  52. LM_ERR("could not allocate row");
  53. return -2;
  54. }
  55. lengths = mysql_fetch_lengths(RES_RESULT(_res));
  56. for(i = 0; i < RES_COL_N(_res); i++) {
  57. if (db_str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]),
  58. ((MYSQL_ROW)RES_ROW(_res))[i], lengths[i], 0) < 0) {
  59. LM_ERR("failed to convert value\n");
  60. LM_DBG("free row at %p\n", _r);
  61. db_free_row(_r);
  62. return -3;
  63. }
  64. }
  65. return 0;
  66. }