Ticket #208: Export2DB.diff
File Export2DB.diff, 3.8 KB (added by calinm, 5 months ago) |
---|
-
Export2DB.cpp
65 65 66 66 } 67 67 68 68 69 void Export2DB::createTables() 69 70 { 70 71 PGresult *result = PQexec(mycon, "CREATE TABLE nodes (ID integer PRIMARY KEY, lon decimal(11,8), lat decimal(11,8), numOfUse smallint);"); 72 if (PQresultStatus(result) != PGRES_COMMAND_OK) 73 { 74 std::cerr << "create Nodes failed: " 75 << PQerrorMessage(mycon) 76 << std::endl; 77 PQclear(result); 78 } 79 71 80 std::cout << "Nodes table created" << std::endl; 72 result = PQexec(mycon, "CREATE TABLE ways (gid integer, class_id integer, length double precision, name char(200), x1 double precision, y1 double precision, x2 double precision,y2 double precision, reverse_cost double precision,rule text, to_cost double precision, PRIMARY KEY(gid)); SELECT AddGeometryColumn('ways','the_geom',4326,'MULTILINESTRING',2);"); 73 std::cout << "Ways table created" << std::endl; 81 result = PQexec(mycon, "CREATE TABLE ways (gid integer, class_id integer not null, length double precision, name char(200), x1 double precision, y1 double precision, x2 double precision,y2 double precision, reverse_cost double precision,rule text, to_cost double precision, PRIMARY KEY(gid)); SELECT AddGeometryColumn('ways','the_geom',4326,'MULTILINESTRING',2);"); 82 if (PQresultStatus(result) != PGRES_COMMAND_OK) 83 { 84 std::cerr << "create ways failed: " 85 << PQerrorMessage(mycon) 86 << std::endl; 87 PQclear(result); 88 } else { 89 std::cout << "Ways table created" << std::endl; 90 } 74 91 result = PQexec(mycon, "CREATE TABLE types (id integer, name char(200));"); 75 std::cout << "Types table created" << std::endl; 92 if (PQresultStatus(result) != PGRES_COMMAND_OK) 93 { 94 std::cerr << "create types failed: " 95 << PQerrorMessage(mycon) 96 << std::endl; 97 PQclear(result); 98 } else { 99 std::cout << "Types table created" << std::endl; 100 } 76 101 result = PQexec(mycon, "CREATE TABLE classes (id integer, type_id integer, name char(200), cost double precision);"); 77 std::cout << "Classes table created" << std::endl; 102 if (PQresultStatus(result) != PGRES_COMMAND_OK) 103 { 104 std::cerr << "create classes failed: " 105 << PQerrorMessage(mycon) 106 << std::endl; 107 PQclear(result); 108 } else { 109 std::cout << "Classes table created" << std::endl; 110 } 78 111 } 79 112 80 113 void Export2DB::dropTables() … … 110 143 query+=", name"; 111 144 query+=") values("; 112 145 113 query+=boost::lexical_cast<std::string>(way->id) + ", (SELECT id FROM classes WHERE name ='" + boost::lexical_cast<std::string>(way->clss) + "')," + boost::lexical_cast<std::string>(way->length) + "," 146 query+=boost::lexical_cast<std::string>(way->id) + 147 ", (SELECT id FROM classes WHERE name ='" + boost::lexical_cast<std::string>(way->clss) + "' and type_id = (select id from types where name='"+ boost::lexical_cast<std::string>(way->type) + "'))," 148 + boost::lexical_cast<std::string>(way->length) + "," 114 149 + boost::lexical_cast<std::string>(way->m_NodeRefs.front()->lon) + ","+ boost::lexical_cast<std::string>(way->m_NodeRefs.front()->lat) + "," 115 150 + boost::lexical_cast<std::string>(way->m_NodeRefs.back()->lon) + ","+ boost::lexical_cast<std::string>(way->m_NodeRefs.back()->lat) + ","; 116 151 query+="GeometryFromText('" + way->geom +"', 4326)"; … … 129 164 query+=");"; 130 165 //std::cout << query <<std::endl; 131 166 PGresult *result = PQexec(mycon, query.c_str()); 167 if (PQresultStatus(result) != PGRES_COMMAND_OK) 168 { 169 std::cerr << "create Nodes failed: " 170 << PQerrorMessage(mycon) 171 << std::endl; 172 std::cerr << "SQL:" << std::endl << query << std::endl; 173 PQclear(result); 174 } 132 175 } 133 176 134 177 void Export2DB::exportType(Type* type)