本文整理汇总了C++中DatabaseConnectionPtr类的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseConnectionPtr类的具体用法?C++ DatabaseConnectionPtr怎么用?C++ DatabaseConnectionPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DatabaseConnectionPtr类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: query
void
SqlSubscriberMap::put(const DatabaseConnectionPtr& connection,
const SubscriberRecordKey& key,
const SubscriberRecord& record)
{
QString driver = connection->sqlConnection().driverName();
QSqlQuery query(connection->sqlConnection());
ostringstream queryString;
queryString << "UPDATE " << _table
<< " SET topicName = ?, link = '" << (record.link ? "true" : "false")
<< "', obj = ?, cost = '" << record.cost
<< "', theTopic = ? WHERE topic = ? AND id = ?;";
query.prepare(queryString.str().c_str());
query.bindValue(0, record.topicName.c_str());
query.bindValue(1, _communicator->proxyToString(record.obj).c_str());
query.bindValue(2, _communicator->proxyToString(record.theTopic).c_str());
query.bindValue(3, _communicator->identityToString(key.topic).c_str());
query.bindValue(4, _communicator->identityToString(key.id).c_str());
if(!query.exec())
{
throwDatabaseException(__FILE__, __LINE__, query.lastError());
}
if(query.numRowsAffected() == 0)
{
//
// We do a find since some databases (MySQL) return 0 for number of rows affected
// if row exists but data was not changed from previous values.
//
try
{
find(connection, key);
}
catch(const NotFoundException&)
{
QSqlQuery insertQuery(connection->sqlConnection());
queryString.str("");
queryString << "INSERT INTO " << _table << " VALUES(?, ?, ?, '" << (record.link ? "true" : "false")
<< "', ?, '" << record.cost << "', ?);";
insertQuery.prepare(queryString.str().c_str());
insertQuery.bindValue(0, _communicator->identityToString(key.topic).c_str());
insertQuery.bindValue(1, _communicator->identityToString(key.id).c_str());
insertQuery.bindValue(2, record.topicName.c_str());
insertQuery.bindValue(3, _communicator->proxyToString(record.obj).c_str());
insertQuery.bindValue(4, _communicator->proxyToString(record.theTopic).c_str());
if(!insertQuery.exec())
{
throwDatabaseException(__FILE__, __LINE__, insertQuery.lastError());
}
}
}
_qosMap.put(connection, key, record.theQoS);
}
示例2: query
IceGrid::ApplicationInfo
SqlStringApplicationInfoDict::find(const DatabaseConnectionPtr& connection,
const string& name)
{
QSqlQuery query(connection->sqlConnection());
string queryString = "SELECT * FROM ";
queryString += _table;
queryString += " WHERE name = ?;";
query.prepare(queryString.c_str());
query.bindValue(0, name.c_str());
if(!query.exec())
{
throwDatabaseException(__FILE__, __LINE__, query.lastError());
}
if(query.next())
{
IceGrid::ApplicationInfo info;
info.uuid = query.value(1).toString().toUtf8().data();
info.createTime = query.value(2).toLongLong();
info.createUser = query.value(3).toString().toUtf8().data();
info.updateTime = query.value(4).toLongLong();
info.updateUser = query.value(5).toString().toUtf8().data();
info.revision = query.value(6).toInt();
QByteArray bytes = query.value(7).toByteArray();
IceInternal::InstancePtr instance = IceInternal::getInstance(_communicator);
IceInternal::BasicStream stream(instance.get(), connection->getEncoding());
stream.b.resize(bytes.size());
::memcpy(&stream.b[0], bytes.data(), bytes.size());
stream.i = stream.b.begin();
stream.startReadEncaps();
stream.read(info.descriptor);
stream.readPendingObjects();
stream.endReadEncaps();
return info;
}
else
{
throw NotFoundException(__FILE__, __LINE__);
}
}
示例3: InitializationException
DatabaseCache::DatabaseCache(const Ice::CommunicatorPtr& communicator,
const string& type,
const string& name,
const string& host,
int port,
const string& user,
const string& password,
bool requiresBlob)
{
Ice::PropertiesPtr properties = communicator->getProperties();
//
// File lock to prevent multiple process open the same db env.
//
if(type == "QSQLITE")
{
_fileLock = new IceUtilInternal::FileLock(name + ".lock");
}
_connection = QSqlDatabase::addDatabase(type.c_str(), IceUtil::generateUUID().c_str());
_connection.setDatabaseName(name.c_str());
_connection.setHostName(host.c_str());
if(port != 0)
{
_connection.setPort(port);
}
_connection.setUserName(user.c_str());
_connection.setPassword(password.c_str());
DatabaseConnectionPtr connection = DatabaseConnectionPtr::dynamicCast(getConnection());
QSqlDriver* driver = connection->sqlConnection().driver();
if(!driver->hasFeature(QSqlDriver::Transactions))
{
throw Ice::InitializationException(__FILE__, __LINE__, "SQL database driver requires transaction support");
}
if(!driver->hasFeature(QSqlDriver::Unicode))
{
throw Ice::InitializationException(__FILE__, __LINE__, "SQL database driver requires unicode support");
}
if(requiresBlob && connection->sqlConnection().driverName() != "QODBC" && !driver->hasFeature(QSqlDriver::BLOB))
{
throw Ice::InitializationException(__FILE__, __LINE__, "SQL database driver requires blob support");
}
}
示例4: query
void
SqlStringApplicationInfoDict::clear(const DatabaseConnectionPtr& connection)
{
QSqlQuery query(connection->sqlConnection());
string queryString = "DELETE FROM ";
queryString += _table;
queryString += ";";
if(!query.exec(queryString.c_str()))
{
throwDatabaseException(__FILE__, __LINE__, query.lastError());
}
}
示例5: stream
void
SqlStringApplicationInfoDict::put(const DatabaseConnectionPtr& connection,
const string& name,
const ApplicationInfo& info)
{
IceInternal::InstancePtr instance = IceInternal::getInstance(_communicator);
IceInternal::BasicStream stream(instance.get());
stream.startWriteEncaps();
info.descriptor.__write(&stream);
stream.writePendingObjects();
stream.endWriteEncaps();
QSqlQuery query(connection->sqlConnection());
ostringstream queryString;
queryString << "UPDATE " << _table << " SET uuid = ?, createTime = '" << info.createTime
<< "', createUser = ?, updateTime = '" << info.updateTime << "', updateUser = ?, revision = '"
<< info.revision << "', descriptor = ";
QString driver = connection->sqlConnection().driverName();
if(driver == "QPSQL" || driver == "QODBC")
{
vector<Ice::Byte> bytes(stream.b.size());
::memcpy(&bytes[0], stream.b.begin(), stream.b.size());
if(driver == "QPSQL")
{
queryString << "E'" << escapePsqlBinary(bytes) << "'";
}
else
{
queryString << "0x" << escapeOdbcBinary(bytes);
}
}
else
{
queryString << "?";
}
queryString << " WHERE name = ?;";
query.prepare(queryString.str().c_str());
int placeholder = 0;
query.bindValue(placeholder++, info.uuid.c_str());
query.bindValue(placeholder++, info.createUser.c_str());
query.bindValue(placeholder++, info.updateUser.c_str());
if(driver != "QPSQL" && driver != "QODBC")
{
QByteArray bytes;
bytes.resize(static_cast<int>(stream.b.size()));
::memcpy(bytes.data(), stream.b.begin(), stream.b.size());
QVariant descriptor(bytes);
query.bindValue(placeholder++, descriptor);
}
query.bindValue(placeholder, name.c_str());
if(!query.exec())
{
throwDatabaseException(__FILE__, __LINE__, query.lastError());
}
if(query.numRowsAffected() == 0)
{
//
// We do a find since some databases (MySQL) return 0 for number of rows affected
// if row exists but data was not changed from previous values.
//
try
{
find(connection, name);
}
catch(const NotFoundException&)
{
QSqlQuery insertQuery(connection->sqlConnection());
queryString.str("");
queryString << "INSERT INTO " << _table << " VALUES(?, ?, '" << info.createTime << "', ?, '"
<< info.updateTime << "', ?, '" << info.revision << "', ";
if(driver == "QPSQL" || driver == "QODBC")
{
vector<Ice::Byte> bytes(stream.b.size());
::memcpy(&bytes[0], stream.b.begin(), stream.b.size());
if(driver == "QPSQL")
{
queryString << "E'" << escapePsqlBinary(bytes) << "'";
}
else
{
queryString << "0x" << escapeOdbcBinary(bytes);
}
}
else
{
queryString << "?";
}
queryString << ");";
insertQuery.prepare(queryString.str().c_str());
//.........这里部分代码省略.........