row.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * $Id$
  3. *
  4. * UNIXODBC module row related functions
  5. *
  6. * Copyright (C) 2005-2006 Marco Lorrai
  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. *
  26. * History:
  27. * --------
  28. * 2005-12-01 initial commit (chgen)
  29. * 2006-05-05 passing proper lengths of column data (sgupta)
  30. */
  31. #include "../../dprint.h"
  32. #include "../../mem/mem.h"
  33. #include "../../lib/srdb1/db_row.h"
  34. #include "../../lib/srdb1/db_val.h"
  35. #include "val.h"
  36. #include "row.h"
  37. #include "connection.h"
  38. /*
  39. * Convert a row from result into db API representation
  40. */
  41. int db_unixodbc_convert_row(const db1_con_t* _h, const db1_res_t* _res, db_row_t* _r,
  42. const unsigned long* lengths)
  43. {
  44. int i;
  45. if ((!_h) || (!_res) || (!_r)) {
  46. LM_ERR("invalid parameter value\n");
  47. return -1;
  48. }
  49. if (db_allocate_row(_res, _r) != 0) {
  50. LM_ERR("could not allocate row");
  51. return -2;
  52. }
  53. for(i = 0; i < RES_COL_N(_res); i++) {
  54. if (db_unixodbc_str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]),
  55. ((CON_ROW(_h))[i]), lengths[i], 1) < 0) {
  56. LM_ERR("failed to convert value\n");
  57. LM_DBG("free row at %p\n", _r);
  58. db_free_row(_r);
  59. return -3;
  60. }
  61. }
  62. return 0;
  63. }