Altough SQLite支持关系数据库,我不确定这是在Poco库中实现的。来自 poco-1.6.0-all / Data / SQLite / testsuite / src / SQLiteTest.cpp 的单元测试似乎没有一个例子,我无法找到任何地方明确确认这是可能的。
在http://pocoproject.org/docs/00200-DataUserManual.html的示例中,名称后面有一个简单的选择:
std::string aName;
std::string match("Peter");
ses << "SELECT name FROM names WHERE name=?", into(aName), use(match), now;
让我们说,我希望看到彼得公司的工作,从包含公司描述的不同表格,给出公司ID:
// Untested
std::string aName;
std::string aCompany;
std::string match("Peter");
ses << "SELECT name, company_name FROM names, companies WHERE name=? AND company_id=2",
into(aName), into(aCompany), use(match), now;
我该怎么做?
答案 0 :(得分:1)
这是一个SQL问题;以下是如何使用POCO:
Session tmp (Poco::Data::SQLite::Connector::KEY, "dummy.db");
tmp << "DROP TABLE IF EXISTS Simpsons", now;
tmp << "DROP TABLE IF EXISTS Companies", now;
tmp << "CREATE TABLE IF NOT EXISTS Simpsons (LastName VARCHAR, FirstName VARCHAR)", now;
tmp << "CREATE TABLE IF NOT EXISTS Companies (CompanyName VARCHAR, LastName VARCHAR, FirstName VARCHAR)", now;
tmp << "INSERT INTO Simpsons VALUES(?, ?)", bind("Simpson"), bind("Bart"), now;
tmp << "INSERT INTO Simpsons VALUES(?, ?)", bind("Simpson"), bind("Homer"), now;
tmp << "INSERT INTO Companies VALUES(?, ?, ?)", bind("Microsoft"), bind("Simpson"), bind("Bart"), now;
tmp << "INSERT INTO Companies VALUES(?, ?, ?)", bind("Oracle"), bind("Simpson"), bind("Homer"), now;
std::string fname, lname, cname;
tmp << "SELECT P.FirstName, P.LastName, C.CompanyName "
"FROM Simpsons P, Companies C "
"WHERE P.FirstName = ? AND P.FirstName = C.FirstName", bind("Bart"), into(fname), into(lname), into(cname), now;
std::cout << lname << ',' << fname << " works for " << std::endl;
输出:
辛普森,巴特为微软工作