db.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 Fhg Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #ifndef DB_H
  28. #define DB_H
  29. #include "db_key.h"
  30. #include "db_op.h"
  31. #include "db_val.h"
  32. #include "db_con.h"
  33. #include "db_row.h"
  34. #include "db_res.h"
  35. /*
  36. * Specify table name that will be used for
  37. * subsequent operations
  38. */
  39. typedef int (*db_use_table_f)(db_con_t* _h, const char* _t);
  40. /*
  41. * Initialize database connection and
  42. * obtain the connection handle
  43. */
  44. typedef db_con_t* (*db_init_f) (const char* _sqlurl);
  45. /*
  46. * Close a database connection and free
  47. * all memory used
  48. */
  49. typedef void (*db_close_f) (db_con_t* _h);
  50. /*
  51. * Query table for specified rows
  52. * _h: structure representing database connection
  53. * _k: key names
  54. * _op: conditions
  55. * _v: values of the keys that must match
  56. * _c: column names to return
  57. * _n: nmber of key=values pairs to compare
  58. * _nc: number of columns to return
  59. * _o: order by the specified column
  60. * _r: Result will be stored in this variable
  61. * NULL if there is no result
  62. */
  63. typedef int (*db_query_f) (db_con_t* _h, db_key_t* _k,
  64. db_op_t* _op, db_val_t* _v,
  65. db_key_t* _c, int _n, int _nc,
  66. db_key_t _o, db_res_t** _r);
  67. /*
  68. * Raw SQL query, database specific !
  69. */
  70. typedef int (*db_raw_query_f) (db_con_t* _h, char* _s, db_res_t** _r);
  71. /*
  72. * Free a result allocated by db_query
  73. * _h: structure representing database connection
  74. * _r: db_res structure
  75. */
  76. typedef int (*db_free_query_f) (db_con_t* _h, db_res_t* _r);
  77. /*
  78. * Insert a row into specified table
  79. * _h: structure representing database connection
  80. * _k: key names
  81. * _v: values of the keys
  82. * _n: number of key=value pairs
  83. */
  84. typedef int (*db_insert_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
  85. /*
  86. * Delete a row from the specified table
  87. * _h: structure representing database connection
  88. * _k: key names
  89. * _o: operators
  90. * _v: values of the keys that must match
  91. * _n: number of key=value pairs
  92. */
  93. typedef int (*db_delete_f) (db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n);
  94. /*
  95. * Update some rows in the specified table
  96. * _h: structure representing database connection
  97. * _k: key names
  98. * _o: operators
  99. * _v: values of the keys that must match
  100. * _uk: updated columns
  101. * _uv: updated values of the columns
  102. * _n: number of key=value pairs
  103. * _un: number of columns to update
  104. */
  105. typedef int (*db_update_f) (db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
  106. db_key_t* _uk, db_val_t* _uv, int _n, int _un);
  107. typedef struct db_func{
  108. db_use_table_f use_table; /* Specify table name */
  109. db_init_f init; /* Initialize dabase connection */
  110. db_close_f close; /* Close database connection */
  111. db_query_f query; /* query a table */
  112. db_raw_query_f raw_query; /* Raw query - SQL */
  113. db_free_query_f free_query; /* Free a query result */
  114. db_insert_f insert; /* Insert into table */
  115. db_delete_f delete; /* Delete from table */
  116. db_update_f update; /* Update table */
  117. } db_func_t;
  118. /*
  119. * Bind database module functions
  120. * returns TRUE if everything went OK
  121. * FALSE otherwise
  122. */
  123. extern db_func_t dbf;
  124. #define db_use_table (dbf.use_table)
  125. #define db_init (dbf.init)
  126. #define db_close (dbf.close)
  127. #define db_query (dbf.query)
  128. #define db_raw_query (dbf.raw_query)
  129. #define db_free_query (dbf.free_query)
  130. #define db_insert (dbf.insert)
  131. #define db_delete (dbf.delete)
  132. #define db_update (dbf.update)
  133. int bind_dbmod(void);
  134. #endif /* DB_H */