1 #include <cherokee/cherokee.h>
2 #include "handler_osm_db.h"
5 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
) {
6 *connection
= mapi_connect(host
->buf
, port
, username
->buf
, password
->buf
, "sql", dbname
->buf
);
8 if (!mapi_error(*connection
)) {
12 mapi_explain(*connection
, stderr
);
18 cherokee_list_content_free_item_ptr (cherokee_list_t
*head
, void **item
)
20 cherokee_list_del (head
);
21 *item
= LIST_ITEM(head
)->info
;
28 run_sql(cherokee_handler_osm_t
*hdl
, cherokee_buffer_t
*sql
, cherokee_buffer_t
*buf
, ret_t (*callback
)()) {
29 ret_t ret
= ret_error
;
30 MapiHdl mapi_hdl
= NULL
;
31 TRACE("sql", "%s\n", sql
->buf
);
32 if ((mapi_hdl
= mapi_query(hdl
->dbh
, sql
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
33 TRACE("sql", "DONE\n");
35 ret
= callback(hdl
, &mapi_hdl
, buf
);
38 mapi_close_handle(mapi_hdl
);
40 mapi_explain(hdl
->dbh
, stderr
);
47 run_sql2(cherokee_handler_osm_t
*hdl
, cherokee_buffer_t
*sql1
, cherokee_buffer_t
*sql2
, cherokee_buffer_t
*buf
, ret_t (*callback
)()) {
48 ret_t ret
= ret_error
;
49 MapiHdl mapi_hdl1
= NULL
;
50 MapiHdl mapi_hdl2
= NULL
;
52 TRACE("sql", "%s\n", sql1
->buf
);
53 if ((mapi_hdl1
= mapi_query(hdl
->dbh
, sql1
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
54 TRACE("sql", "%s\n", sql2
->buf
);
55 if ((mapi_hdl2
= mapi_query(hdl
->dbh
, sql2
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
56 TRACE("sql", "DONE\n");
58 ret
= callback(hdl
, &mapi_hdl1
, &mapi_hdl2
, buf
);
61 mapi_close_handle(mapi_hdl2
);
63 mapi_explain(hdl
->dbh
, stderr
);
64 mapi_close_handle(mapi_hdl1
);
66 mapi_explain(hdl
->dbh
, stderr
);
72 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
)()) {
73 ret_t ret
= ret_error
;
74 MapiHdl mapi_hdl1
= NULL
;
75 MapiHdl mapi_hdl2
= NULL
;
76 MapiHdl mapi_hdl3
= NULL
;
78 TRACE("sql", "%s\n", sql1
->buf
);
79 if ((mapi_hdl1
= mapi_query(hdl
->dbh
, sql1
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
80 TRACE("sql", "%s\n", sql2
->buf
);
81 if ((mapi_hdl2
= mapi_query(hdl
->dbh
, sql2
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
82 TRACE("sql", "%s\n", sql3
->buf
);
83 if ((mapi_hdl3
= mapi_query(hdl
->dbh
, sql3
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
84 TRACE("sql", "DONE\n");
86 ret
= callback(hdl
, &mapi_hdl1
, &mapi_hdl2
, &mapi_hdl3
, buf
);
89 // mapi_cache_freeup(mapi_hdl3, 100);
90 mapi_close_handle(mapi_hdl3
);
92 mapi_explain(hdl
->dbh
, stderr
);
93 mapi_close_handle(mapi_hdl2
);
95 mapi_explain(hdl
->dbh
, stderr
);
96 mapi_close_handle(mapi_hdl1
);
98 mapi_explain(hdl
->dbh
, stderr
);
105 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
)()) {
106 ret_t ret
= ret_error
;
107 MapiHdl mapi_hdl1
= NULL
;
108 MapiHdl mapi_hdl2
= NULL
;
109 MapiHdl mapi_hdl3
= NULL
;
110 MapiHdl mapi_hdl4
= NULL
;
112 TRACE("sql", "%s\n", sql1
->buf
);
113 if ((mapi_hdl1
= mapi_query(hdl
->dbh
, sql1
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
114 TRACE("sql", "%s\n", sql2
->buf
);
115 if ((mapi_hdl2
= mapi_query(hdl
->dbh
, sql2
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
116 TRACE("sql", "%s\n", sql3
->buf
);
117 if ((mapi_hdl3
= mapi_query(hdl
->dbh
, sql3
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
118 TRACE("sql", "%s\n", sql4
->buf
);
119 if ((mapi_hdl4
= mapi_query(hdl
->dbh
, sql4
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
120 TRACE("sql", "DONE\n");
121 if (callback
!= NULL
)
122 ret
= callback(hdl
, &mapi_hdl1
, &mapi_hdl2
, &mapi_hdl3
, &mapi_hdl4
, buf
);
125 // mapi_cache_freeup(mapi_hdl4, 100);
126 mapi_close_handle(mapi_hdl4
);
128 mapi_explain(hdl
->dbh
, stderr
);
129 mapi_close_handle(mapi_hdl3
);
131 mapi_explain(hdl
->dbh
, stderr
);
132 mapi_close_handle(mapi_hdl2
);
134 mapi_explain(hdl
->dbh
, stderr
);
135 mapi_close_handle(mapi_hdl1
);
137 mapi_explain(hdl
->dbh
, stderr
);
143 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
)()) {
144 ret_t ret
= ret_error
;
145 MapiHdl mapi_hdl1
= NULL
;
146 MapiHdl mapi_hdl2
= NULL
;
147 MapiHdl mapi_hdl3
= NULL
;
148 MapiHdl mapi_hdl4
= NULL
;
149 MapiHdl mapi_hdl5
= NULL
;
151 TRACE("sql", "%s\n", sql1
->buf
);
152 if ((mapi_hdl1
= mapi_query(hdl
->dbh
, sql1
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
153 TRACE("sql", "%s\n", sql2
->buf
);
154 if ((mapi_hdl2
= mapi_query(hdl
->dbh
, sql2
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
155 TRACE("sql", "%s\n", sql3
->buf
);
156 if ((mapi_hdl3
= mapi_query(hdl
->dbh
, sql3
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
157 TRACE("sql", "%s\n", sql4
->buf
);
158 if ((mapi_hdl4
= mapi_query(hdl
->dbh
, sql4
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
159 TRACE("sql", "%s\n", sql5
->buf
);
160 if ((mapi_hdl5
= mapi_query(hdl
->dbh
, sql5
->buf
)) != NULL
&& mapi_error(hdl
->dbh
) == MOK
) {
161 TRACE("sql", "DONE\n");
162 if (callback
!= NULL
)
163 ret
= callback(hdl
, &mapi_hdl1
, &mapi_hdl2
, &mapi_hdl3
, &mapi_hdl4
, &mapi_hdl5
, buf
);
166 // mapi_cache_freeup(mapi_hdl5, 100);
167 mapi_close_handle(mapi_hdl5
);
169 mapi_explain(hdl
->dbh
, stderr
);
170 mapi_close_handle(mapi_hdl4
);
172 mapi_explain(hdl
->dbh
, stderr
);
173 mapi_close_handle(mapi_hdl3
);
175 mapi_explain(hdl
->dbh
, stderr
);
176 mapi_close_handle(mapi_hdl2
);
178 mapi_explain(hdl
->dbh
, stderr
);
179 mapi_close_handle(mapi_hdl1
);
181 mapi_explain(hdl
->dbh
, stderr
);