km_row.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * $Id$
  3. *
  4. * MySQL module row related functions
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. * Copyright (C) 2008 1&1 Internet AG
  8. *
  9. * This file is part of Kamailio, a free SIP server.
  10. *
  11. * Kamailio is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version
  15. *
  16. * Kamailio is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. */
  25. /*! \file
  26. * \brief DB_MYSQL :: Row related functions
  27. * \ingroup db_mysql
  28. * Module: \ref db_mysql
  29. */
  30. #include "../../dprint.h"
  31. #include "../../mem/mem.h"
  32. #include "../../lib/srdb1/db_row.h"
  33. #include "../../lib/srdb1/db_val.h"
  34. #include "km_my_con.h"
  35. #include "km_val.h"
  36. #include "km_row.h"
  37. #include "km_res.h"
  38. /*!
  39. * \brief Convert a row from result into DB API representation
  40. * \param _h database connection
  41. * \param _res database result in the DB API representation
  42. * \param _r database result row
  43. * \return 0 on success, -1 on failure
  44. */
  45. int db_mysql_convert_row(const db1_con_t* _h, db1_res_t* _res, db_row_t* _r)
  46. {
  47. unsigned long* lengths;
  48. int i;
  49. if ((!_h) || (!_res) || (!_r)) {
  50. LM_ERR("invalid parameter value\n");
  51. return -1;
  52. }
  53. if (db_allocate_row(_res, _r) != 0) {
  54. LM_ERR("could not allocate row");
  55. return -2;
  56. }
  57. lengths = mysql_fetch_lengths(RES_RESULT(_res));
  58. for(i = 0; i < RES_COL_N(_res); i++) {
  59. if (db_str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]),
  60. ((MYSQL_ROW)RES_ROW(_res))[i], lengths[i], 0) < 0) {
  61. LM_ERR("failed to convert value\n");
  62. LM_DBG("free row at %p\n", _r);
  63. db_free_row(_r);
  64. return -3;
  65. }
  66. }
  67. return 0;
  68. }