本文整理汇总了C++中DatabaseConnectionPtr::sqlConnection方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseConnectionPtr::sqlConnection方法的具体用法?C++ DatabaseConnectionPtr::sqlConnection怎么用?C++ DatabaseConnectionPtr::sqlConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnectionPtr
的用法示例。
在下文中一共展示了DatabaseConnectionPtr::sqlConnection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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");
}
}
示例3: 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());
}
}
示例4: 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());
//.........这里部分代码省略.........