Now also parse new diffs
[handlerosm.git] / handler_osm_db.c
blobe6b588d9a51407dbb5c0e1b684c0a0a1679c5941
1 #include <cherokee/common-internal.h>
2 #include <cherokee/cherokee.h>
3 #include "handler_osm_db.h"
4 #include <Mapi.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)) {
10 return ret_ok;
13 mapi_explain(*connection, stderr);
15 return ret_error;
18 ret_t
19 cherokee_list_content_free_item_ptr (cherokee_list_t *head, void **item)
21 cherokee_list_del (head);
22 *item = LIST_ITEM(head)->info;
24 free (head);
25 return ret_ok;
28 ret_t
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");
35 if (callback != NULL)
36 ret = callback(hdl, &mapi_hdl, buf);
37 else
38 ret = ret_ok;
39 mapi_close_handle(mapi_hdl);
40 } else
41 mapi_explain(hdl->dbh, stderr);
43 return ret;
47 ret_t
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");
58 if (callback != NULL)
59 ret = callback(hdl, &mapi_hdl1, &mapi_hdl2, buf);
60 else
61 ret = ret_ok;
62 mapi_close_handle(mapi_hdl2);
63 } else
64 mapi_explain(hdl->dbh, stderr);
65 mapi_close_handle(mapi_hdl1);
66 } else
67 mapi_explain(hdl->dbh, stderr);
69 return ret;
72 ret_t
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");
86 if (callback != NULL)
87 ret = callback(hdl, &mapi_hdl1, &mapi_hdl2, &mapi_hdl3, buf);
88 else
89 ret = ret_ok;
90 // mapi_cache_freeup(mapi_hdl3, 100);
91 mapi_close_handle(mapi_hdl3);
92 } else
93 mapi_explain(hdl->dbh, stderr);
94 mapi_close_handle(mapi_hdl2);
95 } else
96 mapi_explain(hdl->dbh, stderr);
97 mapi_close_handle(mapi_hdl1);
98 } else
99 mapi_explain(hdl->dbh, stderr);
102 return ret;
105 ret_t
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);
124 else
125 ret = ret_ok;
126 // mapi_cache_freeup(mapi_hdl4, 100);
127 mapi_close_handle(mapi_hdl4);
128 } else
129 mapi_explain(hdl->dbh, stderr);
130 mapi_close_handle(mapi_hdl3);
131 } else
132 mapi_explain(hdl->dbh, stderr);
133 mapi_close_handle(mapi_hdl2);
134 } else
135 mapi_explain(hdl->dbh, stderr);
136 mapi_close_handle(mapi_hdl1);
137 } else
138 mapi_explain(hdl->dbh, stderr);
140 return ret;
143 ret_t
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);
165 else
166 ret = ret_ok;
167 // mapi_cache_freeup(mapi_hdl5, 100);
168 mapi_close_handle(mapi_hdl5);
169 } else
170 mapi_explain(hdl->dbh, stderr);
171 mapi_close_handle(mapi_hdl4);
172 } else
173 mapi_explain(hdl->dbh, stderr);
174 mapi_close_handle(mapi_hdl3);
175 } else
176 mapi_explain(hdl->dbh, stderr);
177 mapi_close_handle(mapi_hdl2);
178 } else
179 mapi_explain(hdl->dbh, stderr);
180 mapi_close_handle(mapi_hdl1);
181 } else
182 mapi_explain(hdl->dbh, stderr);
184 return ret;