Ticket #208: Export2DB.diff

File Export2DB.diff, 3.8 KB (added by calinm, 5 months ago)

Diff

  • Export2DB.cpp

     
    6565 
    6666} 
    6767 
     68 
    6869void Export2DB::createTables() 
    6970{ 
    7071        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 
    7180        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        } 
    7491        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        } 
    76101        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        } 
    78111} 
    79112 
    80113void Export2DB::dropTables() 
     
    110143                query+=", name"; 
    111144        query+=") values("; 
    112145         
    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) + ","  
    114149                 + boost::lexical_cast<std::string>(way->m_NodeRefs.front()->lon) + ","+ boost::lexical_cast<std::string>(way->m_NodeRefs.front()->lat) + "," 
    115150                 + boost::lexical_cast<std::string>(way->m_NodeRefs.back()->lon)  + ","+ boost::lexical_cast<std::string>(way->m_NodeRefs.back()->lat) + ","; 
    116151        query+="GeometryFromText('" + way->geom +"', 4326)"; 
     
    129164        query+=");"; 
    130165                //std::cout << query <<std::endl; 
    131166        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        } 
    132175} 
    133176 
    134177void Export2DB::exportType(Type* type)