本文整理汇总了C++中QSqlQuery::setForwardOnly方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlQuery::setForwardOnly方法的具体用法?C++ QSqlQuery::setForwardOnly怎么用?C++ QSqlQuery::setForwardOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlQuery
的用法示例。
在下文中一共展示了QSqlQuery::setForwardOnly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QSqlQuery
long QgsDb2Provider::featureCount() const
{
// Return the count that we get from the subset.
if ( !mSqlWhereClause.isEmpty() )
return mNumberFeatures;
// On LUW, this could be selected from syscat.tables but I'm not sure if this
// is actually correct if RUNSTATS hasn't been done.
// On z/OS, we don't have access to the system catalog.
// Use count(*) as the easiest approach
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
QString sql = "SELECT COUNT(*) FROM %1.%2";
QString statement = QString( sql ).arg( mSchemaName, mTableName );
QgsDebugMsg( statement );
if ( query.exec( statement ) && query.next() )
{
QgsDebugMsg( QString( "count: %1" ).arg( query.value( 0 ).toInt() ) );
return query.value( 0 ).toInt();
}
else
{
QgsDebugMsg( "Failed" );
QgsDebugMsg( query.lastError().text() );
return -1;
}
}
示例2: schemas
QStringList QgsMssqlConnection::schemas( const QString &uri, QString *errorMessage )
{
QgsDataSourceUri dsUri( uri );
// connect to database
QSqlDatabase db = getDatabase( dsUri.service(), dsUri.host(), dsUri.database(), dsUri.username(), dsUri.password() );
if ( !openDatabase( db ) )
{
if ( errorMessage )
*errorMessage = db.lastError().text();
return QStringList();
}
const QString sql = QStringLiteral( "select s.name as schema_name from sys.schemas s" );
QSqlQuery q = QSqlQuery( db );
q.setForwardOnly( true );
if ( !q.exec( sql ) )
{
if ( errorMessage )
*errorMessage = q.lastError().text();
return QStringList();
}
QStringList result;
while ( q.next() )
{
const QString schemaName = q.value( 0 ).toString();
result << schemaName;
}
return result;
}
示例3: QString
bool QgsDb2Provider::changeGeometryValues( const QgsGeometryMap &geometry_map )
{
if ( geometry_map.isEmpty() )
return true;
if ( mFidColName.isEmpty() )
return false;
for ( QgsGeometryMap::const_iterator it = geometry_map.constBegin(); it != geometry_map.constEnd(); ++it )
{
QgsFeatureId fid = it.key();
// skip added features
if ( FID_IS_NEW( fid ) )
{
continue;
}
QString statement;
statement = QString( "UPDATE %1.%2 SET %3 = " )
.arg( mSchemaName, mTableName, mGeometryColName );
if ( !mDatabase.isOpen() )
{
QString errMsg;
mDatabase = getDatabase( mConnInfo, errMsg );
if ( !errMsg.isEmpty() )
{
return false;
}
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
statement += QString( "db2gse.%1(CAST (%2 AS BLOB(2M)),%3)" )
.arg( mGeometryColType,
QString( "?" ),
QString::number( mSRId ) );
// set attribute filter
statement += QString( " WHERE %1=%2" ).arg( mFidColName, FID_TO_STRING( fid ) );
QgsDebugMsg( statement );
if ( !query.prepare( statement ) )
{
QgsDebugMsg( query.lastError().text() );
return false;
}
// add geometry param
QByteArray bytea = QByteArray(( char* )it->asWkb(), ( int ) it->wkbSize() );
query.addBindValue( bytea, QSql::In | QSql::Binary );
if ( !query.exec() )
{
QgsDebugMsg( query.lastError().text() );
return false;
}
}
return true;
}
示例4: createSchema
bool QgsMssqlConnection::createSchema( const QString &uri, const QString &schemaName, QString *errorMessage )
{
QgsDataSourceUri dsUri( uri );
// connect to database
QSqlDatabase db = getDatabase( dsUri.service(), dsUri.host(), dsUri.database(), dsUri.username(), dsUri.password() );
if ( !openDatabase( db ) )
{
if ( errorMessage )
*errorMessage = db.lastError().text();
return false;
}
QSqlQuery q = QSqlQuery( db );
q.setForwardOnly( true );
const QString sql = QStringLiteral( "CREATE SCHEMA [%1]" ).arg( schemaName );
if ( !q.exec( sql ) )
{
if ( errorMessage )
*errorMessage = q.lastError().text();
return false;
}
return true;
}
示例5: truncateTable
bool QgsMssqlConnection::truncateTable( const QString &uri, QString *errorMessage )
{
QgsDataSourceUri dsUri( uri );
// connect to database
QSqlDatabase db = getDatabase( dsUri.service(), dsUri.host(), dsUri.database(), dsUri.username(), dsUri.password() );
const QString schema = dsUri.schema();
const QString table = dsUri.table();
if ( !openDatabase( db ) )
{
if ( errorMessage )
*errorMessage = db.lastError().text();
return false;
}
QSqlQuery q = QSqlQuery( db );
q.setForwardOnly( true );
const QString sql = QStringLiteral( "TRUNCATE TABLE [%1].[%2]" ).arg( schema, table );
if ( !q.exec( sql ) )
{
if ( errorMessage )
*errorMessage = q.lastError().text();
return false;
}
return true;
}
示例6: dropTable
bool QgsMssqlConnection::dropTable( const QString &uri, QString *errorMessage )
{
QgsDataSourceUri dsUri( uri );
// connect to database
QSqlDatabase db = getDatabase( dsUri.service(), dsUri.host(), dsUri.database(), dsUri.username(), dsUri.password() );
const QString schema = dsUri.schema();
const QString table = dsUri.table();
if ( !openDatabase( db ) )
{
if ( errorMessage )
*errorMessage = db.lastError().text();
return false;
}
QSqlQuery q = QSqlQuery( db );
q.setForwardOnly( true );
const QString sql = QString( "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[%1].[%2]') AND type in (N'U')) DROP TABLE [%1].[%2]\n"
"DELETE FROM geometry_columns WHERE f_table_schema = '%1' AND f_table_name = '%2'" )
.arg( schema,
table );
if ( !q.exec( sql ) )
{
if ( errorMessage )
*errorMessage = q.lastError().text();
return false;
}
return true;
}
示例7: tables
QStringList SqliteDriver::tables(const QString &typeName) const
{
QStringList res;
if (!isOpen() || !dataBase_)
return res;
int type = typeName.toInt();
QSqlQuery q = createQuery();
q.setForwardOnly(TRUE);
#if (QT_VERSION-0 >= 0x030000)
if ((type & (int)QSql::Tables) && (type & (int)QSql::Views))
q.exec("SELECT name FROM sqlite_master WHERE type='table' OR type='view'");
else if (typeName.isEmpty() || (type & (int)QSql::Tables))
q.exec("SELECT name FROM sqlite_master WHERE type='table'");
else if (type & (int)QSql::Views)
q.exec("SELECT name FROM sqlite_master WHERE type='view'");
#else
q.exec("SELECT name FROM sqlite_master WHERE type='table' OR type='view'");
#endif
if (q.isActive()) {
while (q.next())
res.append(q.value(0).toString());
}
#if (QT_VERSION-0 >= 0x030000)
if (type & (int)QSql::SystemTables) {
// there are no internal tables beside this one:
res.append("sqlite_master");
}
#endif
return res;
}
示例8: cleaner
// This should go into Qt 4.8 once we start using it for Qt Creator
QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key)
{
QMap<QString, QUrl> links;
if (d->m_needsSetup)
return links;
const QLatin1String sqlite("QSQLITE");
const QLatin1String name("HelpManager::linksForKeyword");
DbCleaner cleaner(name);
QSqlDatabase db = QSqlDatabase::addDatabase(sqlite, name);
if (db.driver() && db.driver()->lastError().type() == QSqlError::NoError) {
const QStringList ®isteredDocs = d->m_helpEngine->registeredDocumentations();
foreach (const QString &nameSpace, registeredDocs) {
db.setDatabaseName(d->m_helpEngine->documentationFileName(nameSpace));
if (db.open()) {
QSqlQuery query = QSqlQuery(db);
query.setForwardOnly(true);
query.exec(QString::fromLatin1(linksForKeyQuery).arg(key));
while (query.next()) {
QString title = query.value(0).toString();
if (title.isEmpty()) // generate a title + corresponding path
title = key + QLatin1String(" : ") + query.value(3).toString();
links.insertMulti(title, buildQUrl(query.value(1).toString(),
query.value(2).toString(), query.value(3).toString(),
query.value(4).toString()));
}
}
}
}
示例9: listDatabases
void QgsMssqlNewConnection::listDatabases()
{
testConnection( "master" );
listDatabase->clear();
QString queryStr = "SELECT name FROM master..sysdatabases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')";
QSqlDatabase db = QgsMssqlProvider::GetDatabase( txtService->text().trimmed(),
txtHost->text().trimmed(),
"master",
txtUsername->text().trimmed(),
txtPassword->text().trimmed() );
if ( db.open() )
{
QSqlQuery query = QSqlQuery( db );
query.setForwardOnly( true );
query.exec( queryStr );
if ( !txtService->text().isEmpty() )
{
listDatabase->addItem( "(from service)" );
}
if ( query.isActive() )
{
while ( query.next() )
{
QString name = query.value( 0 ).toString();
listDatabase->addItem( name );
}
listDatabase->setCurrentRow( 0 );
}
db.close();
}
}
示例10: rec
QSqlIndex SqliteDriver::primaryIndex2(const QString &tblname) const
{
QSqlRecordInfo rec(recordInfo(tblname)); // expensive :(
if (!isOpen() || !dataBase_)
return QSqlIndex();
QSqlQuery q = createQuery();
q.setForwardOnly(TRUE);
// finrst find a UNIQUE INDEX
q.exec("PRAGMA index_list('" + tblname + "');");
QString indexname;
while (q.next()) {
if (q.value(2).toInt() == 1) {
indexname = q.value(1).toString();
break;
}
}
if (indexname.isEmpty())
return QSqlIndex();
q.exec("PRAGMA index_info('" + indexname + "');");
QSqlIndex index(tblname, indexname);
while (q.next()) {
QString name = q.value(2).toString();
QSqlVariant::Type type = QSqlVariant::Invalid;
if (rec.contains(name))
type = rec.find(name).type();
index.append(QSqlField(name, type));
}
return index;
}
示例11: load
/*!
Loads Custom tags under the \a key serial from the persistent storage
*/
void cCustomTags::load( SERIAL key )
{
if ( tags_ )
tags_->clear();
QSqlQuery result;
result.setForwardOnly( true );
result.prepare( "SELECT name,type,value FROM tags WHERE serial = ?" );
result.addBindValue( key );
result.exec();
while ( result.next() )
{
QString name = result.value( 0 ).toString();
QString type = result.value( 1 ).toString();
QString value = result.value( 2 ).toString();
if ( !tags_ )
tags_ = new QMap<QString, cVariant>;
if ( type == "String" )
tags_->insert( name, cVariant( value ) );
else if ( type == "Int" )
tags_->insert( name, cVariant( value.toInt() ) );
else if ( type == "Double" )
tags_->insert( name, cVariant( value.toDouble() ) );
}
changed = false;
}
示例12: slotFindTask
void CTaskType::slotFindTask(const QString &text)
{
QList<QVariant> list;
QSqlQuery stored;
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(QCursor(QPixmap("data/picture/additionally/wait.png")));
#endif
list.append((int)actualRecords);
list.append(text);
stored.setForwardOnly(true);
stored = execStored(currentDatabase(), "FindTaskType", storageHashTable(list));
bool empty(false);
while (stored.next()){
empty = true;
}
stored = execStored(currentDatabase(), "FindTaskType", storageHashTable(list));
if (empty) {
fillTaskModel(stored);
}
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
stored.finish();
}
示例13: deleteUser
void SecurityManager::deleteUser(const QString &name)
{
if (isSql()) {
QSqlQuery q;
q.setForwardOnly(true);
q.prepare("delete from trainers where name=:name");
q.bindValue(":name", name.toLower());
q.exec();
return;
}
Member m = member(name);
assert (m.name.length() > 0);
m.name[0] = ':'; //invalid character, will not get loaded when reloading database
memberFile.seek(m.filepos);
members[name].write(&memberFile);
memberFile.flush();
playersByIp.remove(m.ip, name);
authed.remove(name);
members.erase(name);
bannedMembers.remove(name.toLower());
if (bannedIPs.contains(m.ip) && !playersByIp.contains(m.ip)) {
bannedIPs.remove(m.ip);
}
}
示例14: call_query
QSqlError QrSqlHelper::call_query(QrSqlQuery &query, QSqlDatabase *database /* = nullptr */)
{
QSqlError dbError;
if (dbError.isValid()) {
return dbError;
}
QSqlQuery qQuery = QSqlQuery(*database);
qQuery.setForwardOnly(true);
QTime timeQuery;
timeQuery.start ();
qQuery.prepare (query.query ());
query.resolve(qQuery);
if (! qQuery.exec ()) {
qDebug() << "query exec fail, " << query.query ();
return qQuery.lastError ();
}
query.resolveOutput(qQuery, true);
int ms = timeQuery.elapsed ();
// set is print sql query statement or not
if (QrSqlConfig::getInstance ()->getTraceSqlQuery ()) {
qDebug() << "custom sql query "<< "(" <<ms << " ms) : " << query.query ()
<< " by " << database;
}
return QSqlError();
}
示例15: membersForIp
QStringList SecurityManager::membersForIp(const QString &ip)
{
if (isSql()) {
QSqlQuery q;
q.setForwardOnly(true);
if (SQLCreator::databaseType == SQLCreator::SQLite) {
/* On SQLite, there's some bug with the qt driver probably,
but here it oftens return nothing if i use '=' instead of 'like', so... */
q.prepare("select name from trainers where ip like ?");
} else {
q.prepare("select name from trainers where ip=?");
}
q.addBindValue(ip);
q.exec();
QStringList ret;
while (q.next()) {
ret.push_back(q.value(0).toString());
}
return ret;
}
return playersByIp.values(ip);
}