/full stuff
[handlerosm.git] / handler_osm_db.c
blob93a6a012ced2283f6affb3b632444a6c63811f15
1 #include <cherokee/cherokee.h>
2 #include "handler_osm_db.h"
3 #include <Mapi.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)) {
9 return ret_ok;
12 mapi_explain(*connection, stderr);
14 return ret_error;
17 ret_t
18 cherokee_list_content_free_item_ptr (cherokee_list_t *head, void **item)
20 cherokee_list_del (head);
21 *item = LIST_ITEM(head)->info;
23 free (head);
24 return ret_ok;
27 ret_t
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");
34 if (callback != NULL)
35 ret = callback(hdl, &mapi_hdl, buf);
36 else
37 ret = ret_ok;
38 mapi_close_handle(mapi_hdl);
39 } else
40 mapi_explain(hdl->dbh, stderr);
42 return ret;
46 ret_t
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");
57 if (callback != NULL)
58 ret = callback(hdl, &mapi_hdl1, &mapi_hdl2, buf);
59 else
60 ret = ret_ok;
61 mapi_close_handle(mapi_hdl2);
62 } else
63 mapi_explain(hdl->dbh, stderr);
64 mapi_close_handle(mapi_hdl1);
65 } else
66 mapi_explain(hdl->dbh, stderr);
68 return ret;
71 ret_t
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");
85 if (callback != NULL)
86 ret = callback(hdl, &mapi_hdl1, &mapi_hdl2, &mapi_hdl3, buf);
87 else
88 ret = ret_ok;
89 // mapi_cache_freeup(mapi_hdl3, 100);
90 mapi_close_handle(mapi_hdl3);
91 } else
92 mapi_explain(hdl->dbh, stderr);
93 mapi_close_handle(mapi_hdl2);
94 } else
95 mapi_explain(hdl->dbh, stderr);
96 mapi_close_handle(mapi_hdl1);
97 } else
98 mapi_explain(hdl->dbh, stderr);
101 return ret;
104 ret_t
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);
123 else
124 ret = ret_ok;
125 // mapi_cache_freeup(mapi_hdl4, 100);
126 mapi_close_handle(mapi_hdl4);
127 } else
128 mapi_explain(hdl->dbh, stderr);
129 mapi_close_handle(mapi_hdl3);
130 } else
131 mapi_explain(hdl->dbh, stderr);
132 mapi_close_handle(mapi_hdl2);
133 } else
134 mapi_explain(hdl->dbh, stderr);
135 mapi_close_handle(mapi_hdl1);
136 } else
137 mapi_explain(hdl->dbh, stderr);
139 return ret;
142 ret_t
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);
164 else
165 ret = ret_ok;
166 // mapi_cache_freeup(mapi_hdl5, 100);
167 mapi_close_handle(mapi_hdl5);
168 } else
169 mapi_explain(hdl->dbh, stderr);
170 mapi_close_handle(mapi_hdl4);
171 } else
172 mapi_explain(hdl->dbh, stderr);
173 mapi_close_handle(mapi_hdl3);
174 } else
175 mapi_explain(hdl->dbh, stderr);
176 mapi_close_handle(mapi_hdl2);
177 } else
178 mapi_explain(hdl->dbh, stderr);
179 mapi_close_handle(mapi_hdl1);
180 } else
181 mapi_explain(hdl->dbh, stderr);
183 return ret;