Now also parse new diffs
[handlerosm.git] / handler_osm_get_legacy.c
blob92f10d1bf75a04a86b4658ba82918f1895156693
1 #if BYRESULT
2 static ret_t result_id_to_list(cherokee_handler_osm_t *hdl, MapiHdl *anything, cherokee_buffer_t *buf) {
3 if (mapi_get_row_count(*anything) != 0) {
4 while (mapi_fetch_row(*anything)) {
5 char *field = mapi_fetch_field(*anything, 0);
6 if (field != NULL) {
7 cherokee_buffer_add_va (buf, "%s, ", field);
12 cherokee_buffer_drop_ending(buf, 2);
13 return ret_ok;
15 #endif
18 //#define BYRESULT 1
20 #ifdef BYRESULT
21 static void parse_map2(cherokee_handler_osm_t *hdl, cherokee_buffer_t *buf) {
22 double left, bottom, right, top;
23 cherokee_avl_t *arguments = HANDLER_CONN(hdl)->arguments;
25 if (ret_ok == fetch_bbox(arguments, &left, &bottom, &right, &top)) {
26 TRACE ("osmapi", "%s BBOX: %f %f %f %f\n", __func__, left, bottom, right, top);
27 cherokee_buffer_t sql1 = CHEROKEE_BUF_INIT;
28 cherokee_buffer_t nodes = CHEROKEE_BUF_INIT;
29 cherokee_buffer_t relations = CHEROKEE_BUF_INIT;
31 cherokee_buffer_add_va (&sql1, "SELECT id FROM " SQL_NODES " WHERE " SQL_BY_BBOX, BBOX_VA_ARGS);
32 run_sql(hdl, &sql1, &nodes, result_id_to_list);
33 cherokee_buffer_mrproper(&sql1);
35 if (nodes.len > 0) {
36 cherokee_buffer_t sql2 = CHEROKEE_BUF_INIT;
38 cherokee_buffer_add_str (&sql1, "SELECT relation FROM members_node WHERE to_node IN (");
39 cherokee_buffer_add_buffer(&sql1, &nodes);
40 cherokee_buffer_add_str (&sql1, ")");
41 run_sql(hdl, &sql1, &relations, result_id_to_list);
42 cherokee_buffer_mrproper(&sql1);
45 if (relations.len > 0) {
46 cherokee_buffer_add_str (&nodes, ", ");
47 cherokee_buffer_add_str (&sql1, "SELECT to_node FROM members_node WHERE relation IN (");
48 cherokee_buffer_add_buffer(&sql1, &relations);
49 cherokee_buffer_add_str (&sql1, ")");
50 run_sql(hdl, &sql1, &nodes, result_id_to_list);
51 cherokee_buffer_mrproper(&sql1);
54 cherokee_buffer_add_str (&sql1, "SELECT id, long, lat, username, timestamp FROM " SQL_NODES " WHERE id IN (");
55 cherokee_buffer_add_buffer(&sql1, &nodes);
56 cherokee_buffer_add_str (&sql1, ") ORDER BY id");
58 cherokee_buffer_add_str (&sql2, "SELECT node, k, v FROM node_tags WHERE node IN (");
59 cherokee_buffer_add_buffer(&sql2, &nodes);
60 cherokee_buffer_add_str (&sql2, ") ORDER BY node");
62 run_sql2(hdl, &sql1, &sql2, buf, result_nodenew_to_xml);
64 cherokee_buffer_mrproper(&sql1);
65 cherokee_buffer_mrproper(&sql2);
67 cherokee_buffer_mrproper(&nodes);
69 if (relations.len > 0) {
70 cherokee_buffer_t sql3 = CHEROKEE_BUF_INIT;
71 cherokee_buffer_t sql4 = CHEROKEE_BUF_INIT;
73 cherokee_buffer_add_str (&sql1, "SELECT id, username, timestamp FROM relations WHERE id IN (");
74 cherokee_buffer_add_buffer(&sql1, &relations);
75 cherokee_buffer_add_str (&sql1, ") ORDER BY id");
76 cherokee_buffer_add_str (&sql2, "SELECT relation, k, v FROM relation_tags WHERE relation IN (");
77 cherokee_buffer_add_buffer(&sql2, &relations);
78 cherokee_buffer_add_str (&sql2, ") ORDER BY relation");
79 cherokee_buffer_add_str (&sql3, "SELECT relation, to_relation, role FROM members_relation WHERE relation IN (");
80 cherokee_buffer_add_buffer(&sql3, &relations);
81 cherokee_buffer_add_str (&sql3, ") ORDER BY relation, idx");
82 cherokee_buffer_add_str (&sql4, "SELECT relation, to_node, role FROM members_node WHERE relation IN (");
83 cherokee_buffer_add_buffer(&sql4, &relations);
84 cherokee_buffer_add_str (&sql4, ") ORDER BY relation, idx");
86 run_sql4(hdl, &sql1, &sql2, &sql3, &sql4, buf, result_relationway_to_xml);
88 cherokee_buffer_mrproper(&sql1);
89 cherokee_buffer_mrproper(&sql2);
90 cherokee_buffer_mrproper(&sql3);
91 cherokee_buffer_mrproper(&sql4);
94 cherokee_buffer_mrproper(&relations);
98 #else
99 #endif