1 #include <cherokee/common-internal.h>
2 #include <cherokee/cherokee.h>
3 #include "handler_osm_db.h"
6 ret_t
handler_osm_db_connection_new(cherokee_buffer_t
*host
, cint_t port
, cherokee_buffer_t
*username
, cherokee_buffer_t
* password
, cherokee_buffer_t
*dbname
, Mapi
*connection
) {
7 *connection
= mapi_connect(host
->buf
, port
, username
->buf
, password
->buf
, "sql", dbname
->buf
);
9 if (!mapi_error(*connection
)) {
13 mapi_explain(*connection
, stderr
);
19 cherokee_list_content_free_item_ptr (cherokee_list_t
*head
, void **item
)
21 cherokee_list_del (head
);
22 *item
= LIST_ITEM(head
)->info
;
29 run_sql(cherokee_handler_osm_t
*hdl
, cherokee_buffer_t
*sql
, cherokee_buffer_t
*buf
, ret_t (*callback
)()) {
30 ret_t ret
= ret_error
;
31 MapiHdl mapi_hdl
= NULL
;
32 TRACE("sql", "%s\n", sql
->buf
);
33 if ((mapi_hdl
= mapi_query(hdl
->dbh
, sql
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
34 TRACE("sql", "DONE\n");
36 ret
= callback(hdl
, &mapi_hdl
, buf
);
39 mapi_close_handle(mapi_hdl
);
41 mapi_explain(hdl
->dbh
, stderr
);
48 run_sql2(cherokee_handler_osm_t
*hdl
, cherokee_buffer_t
*sql1
, cherokee_buffer_t
*sql2
, cherokee_buffer_t
*buf
, ret_t (*callback
)()) {
49 ret_t ret
= ret_error
;
50 MapiHdl mapi_hdl1
= NULL
;
51 MapiHdl mapi_hdl2
= NULL
;
53 TRACE("sql", "%s\n", sql1
->buf
);
54 if ((mapi_hdl1
= mapi_query(hdl
->dbh
, sql1
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
55 TRACE("sql", "%s\n", sql2
->buf
);
56 if ((mapi_hdl2
= mapi_query(hdl
->dbh
, sql2
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
57 TRACE("sql", "DONE\n");
59 ret
= callback(hdl
, &mapi_hdl1
, &mapi_hdl2
, buf
);
62 mapi_close_handle(mapi_hdl2
);
64 mapi_explain(hdl
->dbh
, stderr
);
65 mapi_close_handle(mapi_hdl1
);
67 mapi_explain(hdl
->dbh
, stderr
);
73 run_sql3(cherokee_handler_osm_t
*hdl
, cherokee_buffer_t
*sql1
, cherokee_buffer_t
*sql2
, cherokee_buffer_t
*sql3
, cherokee_buffer_t
*buf
, ret_t (*callback
)()) {
74 ret_t ret
= ret_error
;
75 MapiHdl mapi_hdl1
= NULL
;
76 MapiHdl mapi_hdl2
= NULL
;
77 MapiHdl mapi_hdl3
= NULL
;
79 TRACE("sql", "%s\n", sql1
->buf
);
80 if ((mapi_hdl1
= mapi_query(hdl
->dbh
, sql1
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
81 TRACE("sql", "%s\n", sql2
->buf
);
82 if ((mapi_hdl2
= mapi_query(hdl
->dbh
, sql2
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
83 TRACE("sql", "%s\n", sql3
->buf
);
84 if ((mapi_hdl3
= mapi_query(hdl
->dbh
, sql3
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
85 TRACE("sql", "DONE\n");
87 ret
= callback(hdl
, &mapi_hdl1
, &mapi_hdl2
, &mapi_hdl3
, buf
);
90 // mapi_cache_freeup(mapi_hdl3, 100);
91 mapi_close_handle(mapi_hdl3
);
93 mapi_explain(hdl
->dbh
, stderr
);
94 mapi_close_handle(mapi_hdl2
);
96 mapi_explain(hdl
->dbh
, stderr
);
97 mapi_close_handle(mapi_hdl1
);
99 mapi_explain(hdl
->dbh
, stderr
);
106 run_sql4(cherokee_handler_osm_t
*hdl
, cherokee_buffer_t
*sql1
, cherokee_buffer_t
*sql2
, cherokee_buffer_t
*sql3
, cherokee_buffer_t
*sql4
, cherokee_buffer_t
*buf
, ret_t (*callback
)()) {
107 ret_t ret
= ret_error
;
108 MapiHdl mapi_hdl1
= NULL
;
109 MapiHdl mapi_hdl2
= NULL
;
110 MapiHdl mapi_hdl3
= NULL
;
111 MapiHdl mapi_hdl4
= NULL
;
113 TRACE("sql", "%s\n", sql1
->buf
);
114 if ((mapi_hdl1
= mapi_query(hdl
->dbh
, sql1
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
115 TRACE("sql", "%s\n", sql2
->buf
);
116 if ((mapi_hdl2
= mapi_query(hdl
->dbh
, sql2
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
117 TRACE("sql", "%s\n", sql3
->buf
);
118 if ((mapi_hdl3
= mapi_query(hdl
->dbh
, sql3
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
119 TRACE("sql", "%s\n", sql4
->buf
);
120 if ((mapi_hdl4
= mapi_query(hdl
->dbh
, sql4
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
121 TRACE("sql", "DONE\n");
122 if (callback
!= NULL
)
123 ret
= callback(hdl
, &mapi_hdl1
, &mapi_hdl2
, &mapi_hdl3
, &mapi_hdl4
, buf
);
126 // mapi_cache_freeup(mapi_hdl4, 100);
127 mapi_close_handle(mapi_hdl4
);
129 mapi_explain(hdl
->dbh
, stderr
);
130 mapi_close_handle(mapi_hdl3
);
132 mapi_explain(hdl
->dbh
, stderr
);
133 mapi_close_handle(mapi_hdl2
);
135 mapi_explain(hdl
->dbh
, stderr
);
136 mapi_close_handle(mapi_hdl1
);
138 mapi_explain(hdl
->dbh
, stderr
);
144 run_sql5(cherokee_handler_osm_t
*hdl
, cherokee_buffer_t
*sql1
, cherokee_buffer_t
*sql2
, cherokee_buffer_t
*sql3
, cherokee_buffer_t
*sql4
, cherokee_buffer_t
*sql5
, cherokee_buffer_t
*buf
, ret_t (*callback
)()) {
145 ret_t ret
= ret_error
;
146 MapiHdl mapi_hdl1
= NULL
;
147 MapiHdl mapi_hdl2
= NULL
;
148 MapiHdl mapi_hdl3
= NULL
;
149 MapiHdl mapi_hdl4
= NULL
;
150 MapiHdl mapi_hdl5
= NULL
;
152 TRACE("sql", "%s\n", sql1
->buf
);
153 if ((mapi_hdl1
= mapi_query(hdl
->dbh
, sql1
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
154 TRACE("sql", "%s\n", sql2
->buf
);
155 if ((mapi_hdl2
= mapi_query(hdl
->dbh
, sql2
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
156 TRACE("sql", "%s\n", sql3
->buf
);
157 if ((mapi_hdl3
= mapi_query(hdl
->dbh
, sql3
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
158 TRACE("sql", "%s\n", sql4
->buf
);
159 if ((mapi_hdl4
= mapi_query(hdl
->dbh
, sql4
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
160 TRACE("sql", "%s\n", sql5
->buf
);
161 if ((mapi_hdl5
= mapi_query(hdl
->dbh
, sql5
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
162 TRACE("sql", "DONE\n");
163 if (callback
!= NULL
)
164 ret
= callback(hdl
, &mapi_hdl1
, &mapi_hdl2
, &mapi_hdl3
, &mapi_hdl4
, &mapi_hdl5
, buf
);
167 // mapi_cache_freeup(mapi_hdl5, 100);
168 mapi_close_handle(mapi_hdl5
);
170 mapi_explain(hdl
->dbh
, stderr
);
171 mapi_close_handle(mapi_hdl4
);
173 mapi_explain(hdl
->dbh
, stderr
);
174 mapi_close_handle(mapi_hdl3
);
176 mapi_explain(hdl
->dbh
, stderr
);
177 mapi_close_handle(mapi_hdl2
);
179 mapi_explain(hdl
->dbh
, stderr
);
180 mapi_close_handle(mapi_hdl1
);
182 mapi_explain(hdl
->dbh
, stderr
);