这段代码
table_edges[ this_relationship ] = boost::add_edge(
table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ],
table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ],
this_relationship,
rg
).first;
ds.union_set(
table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ],
table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ]
);
给出了这个错误和许多其他关于 get
/usr/include/boost/pending/detail/disjoint_sets.hpp:59:33: error: no matching function for call to 'get(long unsigned int*&, long unsigned int&)'</p>
我正在使用捆绑的属性。
typedef boost::adjacency_list <
boost::vecS,
boost::vecS,
boost::undirectedS,
string,
foreign_key_relationship
> relational_graph;
等级和父类型定义是全局声明的。
如何解决此错误?
struct foreign_key_relationship{
string parent_table;
string parent_column;
string child_table;
string child_column;
foreign_key_relationship(){}
foreign_key_relationship( string pt, string pc, string ct, string cc ) : parent_table( pt ), parent_column( pc ), child_table( ct ), child_column( cc ) {}
};
inline bool operator==(const foreign_key_relationship& lhs, const foreign_key_relationship& rhs)
{
return
lhs.parent_table == rhs.parent_table
&& lhs.parent_column == rhs.parent_column
&& lhs.child_table == rhs.child_table
&& lhs.child_column == rhs.child_column
;
}
inline bool operator<(const foreign_key_relationship& lhs, const foreign_key_relationship& rhs)
{
return
lhs.parent_table < rhs.parent_table
&& lhs.parent_column < rhs.parent_column
&& lhs.child_table < rhs.child_table
&& lhs.child_column < rhs.child_column
;
}
typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, string, foreign_key_relationship > relational_graph;
typedef boost::graph_traits<relational_graph>::vertex_descriptor relational_vertex;
typedef boost::graph_traits<relational_graph>::vertices_size_type relational_vertex_index;
typedef boost::graph_traits<relational_graph>::edge_descriptor relational_edge;
typedef relational_vertex_index* relational_rank;
typedef relational_vertex* relational_parent;
void libpqxx_error( const pqxx_exception &e ){
cerr << "*** Caught pqxx_exception:\n";
cerr << e.base().what() << "\n";
const sql_error *s=dynamic_cast<const sql_error*>(&e.base());
if (s) std::cerr << "Query was: " << s->query() << "\n";
}
void connect_relational_vertices( map< foreign_key_relationship, relational_edge > &table_edges, result &foreign_keys, set<string> &tables_to_connect, map< string, relational_vertex > &table_vertices, relational_graph &rg, boost::disjoint_sets<relational_rank, relational_parent> &ds ){
for( unsigned i=0; i<foreign_keys.size(); i++ ){
foreign_key_relationship this_relationship(
foreign_keys[i]["parent_table"].c_str(),
foreign_keys[i]["parent_column"].c_str(),
foreign_keys[i]["child_table"].c_str(),
foreign_keys[i]["child_column"].c_str()
);
if( !table_edges.count( this_relationship ) && tables_to_connect.count( foreign_keys[i]["parent_table"].c_str() ) && tables_to_connect.count( foreign_keys[i]["child_table"].c_str() ) ){
table_edges[ this_relationship ] = boost::add_edge(
table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ],
table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ],
this_relationship,
rg
).first;
ds.union_set( table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ], table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ] );
}
}
}
void add_possible_linking_vertex( result &foreign_keys, map< string, relational_vertex > &table_vertices, relational_graph &rg ){
for( unsigned i=0; i<foreign_keys.size(); i++ ){
if( !table_vertices.count( foreign_keys[i]["parent_table"].c_str() ) ){
table_vertices[ foreign_keys[i]["parent_table"].c_str() ] = boost::add_vertex( foreign_keys[i]["parent_table"].c_str(), rg );
break;
}
if( foreign_keys[i]["child_table"].c_str() ){
table_vertices[ foreign_keys[i]["child_table"].c_str() ] = boost::add_vertex( foreign_keys[i]["child_table"].c_str(), rg );
break;
}
}
}
set< foreign_key_relationship > get_foreign_keys( transaction_base &t, set<string> tables_to_connect ){
try{
result foreign_keys = t.prepared("get_foreign_keys").exec();
set< foreign_key_relationship > relational_routes;
if( tables_to_connect.size() ){
relational_graph rg;
map< string, relational_vertex > table_vertices;
for( string table: tables_to_connect )
table_vertices[ table ] = boost::add_vertex( table, rg );
std::vector<relational_vertex_index> rank( num_vertices(rg) );
std::vector<relational_vertex> parent( num_vertices(rg) );
boost::disjoint_sets<relational_rank, relational_parent> ds(&rank[0], &parent[0]);
boost::initialize_incremental_components(rg, ds);
boost::incremental_components(rg, ds);
map< foreign_key_relationship, relational_edge > table_edges;
for( unsigned i=0; i<foreign_keys.size(); i++ )
connect_relational_vertices( table_edges, foreign_keys, tables_to_connect, table_vertices, rg, ds );
}
return relational_routes;
}
catch( const pqxx_exception &e ){
libpqxx_error( e );
set< foreign_key_relationship > relational_routes;
return relational_routes;
}
}
我正在使用 libpqxx,查找所有外键关系的查询在这里。