forked from mmd-osm/Overpass-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
696 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include <cctype> | ||
#include <iostream> | ||
#include <map> | ||
#include <set> | ||
#include <string> | ||
#include <stdlib.h> | ||
#include <vector> | ||
#include "expat_justparse_interface.h" | ||
#include "script_datatypes.h" | ||
#include "script_queries.h" | ||
#include "script_tools.h" | ||
#include "statement_factory.h" | ||
#include "user_interface.h" | ||
|
||
#include <mysql.h> | ||
|
||
using namespace std; | ||
|
||
static int output_mode(HTML); | ||
|
||
MYSQL* mysql(NULL); | ||
|
||
vector< Statement* > statement_stack; | ||
vector< string > text_stack; | ||
|
||
void start(const char *el, const char **attr) | ||
{ | ||
Statement* statement(generate_statement(el)); | ||
if (statement) | ||
{ | ||
statement->set_attributes(attr); | ||
statement_stack.push_back(statement); | ||
text_stack.push_back(get_parsed_text()); | ||
reset_parsed_text(); | ||
} | ||
} | ||
|
||
void end(const char *el) | ||
{ | ||
if ((is_known_element(el)) && (statement_stack.size() > 1)) | ||
{ | ||
Statement* statement(statement_stack.back()); | ||
statement->add_final_text(get_parsed_text()); | ||
reset_parsed_text(); | ||
//Include an end-control to catch e.g. empty query-statements? | ||
statement_stack.pop_back(); | ||
statement_stack.back()->add_statement(statement, text_stack.back()); | ||
text_stack.pop_back(); | ||
} | ||
else if ((is_known_element(el)) && (statement_stack.size() == 1)) | ||
statement_stack.front()->add_final_text(get_parsed_text()); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
string xml_raw(get_xml_raw()); | ||
if (display_encoding_errors(cout)) | ||
return 0; | ||
if (display_parse_errors(cout, xml_raw)) | ||
return 0; | ||
|
||
parse(xml_raw, start, end); | ||
if (display_parse_errors(cout, xml_raw)) | ||
return 0; | ||
// getting special information for rules | ||
string rule_name(""); | ||
int rule_replace(0); | ||
Root_Statement* root_statement(dynamic_cast< Root_Statement* >(statement_stack.front())); | ||
if (root_statement) | ||
{ | ||
rule_name = root_statement->get_rule_name(); | ||
rule_replace = root_statement->get_rule_replace(); | ||
} | ||
if (rule_name == "") | ||
add_static_error("Adding a rule requires the name of the rule."); | ||
if (rule_replace) | ||
add_static_error("Providing a version-id while adding a rule is not allowed."); | ||
|
||
xml_raw = xml_raw.substr(xml_raw.find("<osm-script")); | ||
xml_raw = xml_raw.substr(xml_raw.find('>') + 1); | ||
if (xml_raw.find("</osm-script>") != string::npos) | ||
xml_raw = xml_raw.substr(0, xml_raw.find("</osm-script>")); | ||
else | ||
add_static_error("No content between start and end of the root-tag."); | ||
|
||
if (display_static_errors(cout, xml_raw)) | ||
return 0; | ||
|
||
//Sanity-Check | ||
|
||
mysql = mysql_init(NULL); | ||
|
||
if (!mysql_real_connect(mysql, "localhost", "osm", "osm", "osm", 0, NULL, | ||
CLIENT_LOCAL_FILES)) | ||
{ | ||
runtime_error("Connection to database failed.\n", cout); | ||
return 0; | ||
} | ||
|
||
out_header(cout, output_mode); | ||
|
||
int body_id(int_query(mysql, "select max(id) from rule_bodys")+1); | ||
|
||
ostringstream temp; | ||
temp<<"select id from rule_names where name = '"; | ||
escape_insert(temp, rule_name); | ||
temp<<'\''; | ||
int name_id(int_query(mysql, temp.str())); | ||
|
||
if (name_id) | ||
{ | ||
temp.str(""); | ||
temp<<"Rule '"<<rule_name<<"' already exists in the database."; | ||
runtime_error(temp.str(), cout); | ||
out_footer(cout, output_mode); | ||
return 0; | ||
} | ||
|
||
name_id = int_query(mysql, "select max(id) from rule_names") + 1; | ||
temp.str(""); | ||
temp<<"insert rule_names values ("<<name_id<<", '"; | ||
escape_insert(temp, rule_name); | ||
temp<<"')"; | ||
mysql_query(mysql, temp.str().c_str()); | ||
|
||
temp.str(""); | ||
temp<<"insert rule_bodys values ("<<body_id<<", "<<name_id<<", '"; | ||
escape_insert(temp, xml_raw); | ||
temp<<"')"; | ||
mysql_query(mysql, temp.str().c_str()); | ||
|
||
temp.str(""); | ||
temp<<"Rule '"<<rule_name<<"' successfully updated."; | ||
runtime_remark(temp.str(), cout); | ||
|
||
//Rule execution | ||
|
||
out_footer(cout, output_mode); | ||
|
||
mysql_close(mysql); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
PATH=./:$PATH | ||
CONFIRM=$1 | ||
if [[ $1 != "YES" ]]; then | ||
{ | ||
read -p "Proceeding will drop the current derived data in database osm. Do you really want to continue? " CONFIRM | ||
}; | ||
fi | ||
|
||
if [[ $CONFIRM != "YES" ]]; then | ||
{ | ||
echo "Aborted on user request" | ||
exit 0 | ||
}; | ||
fi | ||
|
||
|
||
echo "drop table if exists rule_names, rule_bodys, conflicts, conflict_classes, node_conflicts, way_conflicts, relation_conflicts, areas, area_segments, area_tags;" >init_derived_data.sql | ||
|
||
echo "create table rule_names (id int, name varchar(21844));" >>init_derived_data.sql | ||
|
||
echo "create table rule_bodys (id int, rule int, source varchar(21844));" >>init_derived_data.sql | ||
|
||
echo "create table conflicts (id int, message varchar(21844));" >>init_derived_data.sql | ||
echo "create table node_conflicts (id int, conflict int);" >>init_derived_data.sql | ||
echo "create table way_conflicts (id int, conflict int);" >>init_derived_data.sql | ||
echo "create table relation_conflicts (id int, conflict int);" >>init_derived_data.sql | ||
|
||
echo "create table areas (id int);" >>init_derived_data.sql | ||
echo "create table area_segments (id int, lat_idx int, min_lat int, min_lon int, max_lat int, max_lon int);" >>init_derived_data.sql | ||
echo "create table area_tags (id int, key_ int unsigned, value_ int unsigned);" >>init_derived_data.sql | ||
|
||
echo "alter table rule_names add unique key(id), add key(name);" >>init_derived_data.sql | ||
echo "alter table rule_bodys add key(id), add key(rule);" >>init_derived_data.sql | ||
echo "alter table conflicts add unique key(id);" >>init_derived_data.sql | ||
echo "insert conflicts values (0, '');" >>init_derived_data.sql | ||
echo "alter table node_conflicts add key(id);" >>init_derived_data.sql | ||
echo "alter table way_conflicts add key(id);" >>init_derived_data.sql | ||
echo "alter table relation_conflicts add key(id);" >>init_derived_data.sql | ||
echo "alter table areas add unique key(id);" >>init_derived_data.sql | ||
echo "insert areas values (0);" >>init_derived_data.sql | ||
echo "alter table area_segments add key(id), add index(lat_idx, min_lon);" >>init_derived_data.sql | ||
echo "alter table area_tags add key(id);" >>init_derived_data.sql | ||
|
||
|
||
echo "Creating tables for derived data ... " | ||
|
||
mysql -u osm -posm osm <init_derived_data.sql |
Oops, something went wrong.