本文整理汇总了C++中ConnectionPtr::prepareStatement方法的典型用法代码示例。如果您正苦于以下问题:C++ ConnectionPtr::prepareStatement方法的具体用法?C++ ConnectionPtr::prepareStatement怎么用?C++ ConnectionPtr::prepareStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionPtr
的用法示例。
在下文中一共展示了ConnectionPtr::prepareStatement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
/* The test requires a db named "test" on localhost and a user "lksm" in
* "test" database. The tests are run against a table called "dpak"
* which has the following ddl:
* create table dpak
* (col1 int not null
* col2 char(20) null);
* create unique index index1 on dpak(col1);
*/
int main(int argc, char** argv)
{
if(argc < 3)
{
cerr << "usage: pgdbtest mode col1_val col2_val" << endl;
}
string mode(argv[1]);
int col1_val = atoi(argv[2]);
string col2_val(argv[3]);
ConnectionPtr conn = DBManager::getConnection("lksm", "", "localhost/test", DBConnection::POSTGRES_CONNECTION);
try
{
if(strcmp(mode.c_str(), "0")==0)
{
string query = col2_val;
PreparedStatementPtr stmt = conn->prepareStatement(query.c_str());
cerr<<"PSTMT created successfully." << endl;
executePreparedStatement(stmt);
}
else if(strcmp(mode.c_str(), "1")==0)
{
begin(conn);
sleep(5);
updateVal(conn, col1_val, col2_val.c_str());
sleep(10);
commit(conn);
}
else if(strcmp(mode.c_str(), "2")==0)
{
begin(conn);
sleep(5);
updateVal(conn, col1_val, col2_val.c_str());
sleep(10);
commit(conn);
}
else if(strcmp(mode.c_str(), "3")==0)
{
begin(conn);
sleep(2);
updateVal(conn, col1_val, col2_val.c_str());
sleep(5);
rollback(conn);
}
}catch(DBException &e){
cerr << "DBException: " << e.getMessage() << endl;
}catch(BaseException &e){
cerr << "BaseException: " << e.getMessage() << endl;
}
return 0;
}