本文整理汇总了C++中QSqlIndex::fieldName方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlIndex::fieldName方法的具体用法?C++ QSqlIndex::fieldName怎么用?C++ QSqlIndex::fieldName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlIndex
的用法示例。
在下文中一共展示了QSqlIndex::fieldName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: primaryIndex
void tst_QSqlDriver::primaryIndex()
{
QFETCH_GLOBAL(QString, dbName);
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
QString tablename(qTableName("relTEST1", __FILE__));
//check that we can get primary index using unquoted mixed case table name
QSqlIndex index = db.driver()->primaryIndex(tablename);
QCOMPARE(index.count(), 1);
if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2"))
QCOMPARE(index.fieldName(0), QString::fromLatin1("ID"));
else
QCOMPARE(index.fieldName(0), QString::fromLatin1("id"));
//check that we can get the primary index using a quoted tablename
if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2"))
tablename = tablename.toUpper();
else if (db.driverName().startsWith("QPSQL"))
tablename = tablename.toLower();
if(!db.driverName().startsWith("QODBC") && !db.databaseName().contains("PostgreSql")) {
index = db.driver()->primaryIndex(db.driver()->escapeIdentifier(tablename, QSqlDriver::TableName));
QCOMPARE(index.count(), 1);
}
if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2"))
QCOMPARE(index.fieldName(0), QString::fromLatin1("ID"));
else
QCOMPARE(index.fieldName(0), QString::fromLatin1("id"));
//check that we can not get the primary index using a quoted but incorrect table name casing
if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2"))
tablename = tablename.toLower();
else if (db.driverName().startsWith("QPSQL"))
tablename = tablename.toUpper();
index = db.driver()->primaryIndex(db.driver()->escapeIdentifier(tablename, QSqlDriver::TableName));
if (tst_Databases::isMySQL(db)
|| db.driverName().startsWith("QSQLITE")
|| db.driverName().startsWith("QTDS")
|| tst_Databases::isSqlServer(db)
|| tst_Databases::isMSAccess(db))
QCOMPARE(index.count(), 1); //mysql will always find the table name regardless of casing
else
QCOMPARE(index.count(), 0);
}
示例2: getPrimary
QString getPrimary(QSqlDatabase &db, QString sTable)
{
QString sPrimary = "kbrecordid";
QSqlIndex i = db.driver()->primaryIndex(sTable);
if (i.count()){
sPrimary = i.fieldName(0);
}
return sPrimary;
}
示例3: toString
QString Q3SqlCursor::toString(const QSqlIndex& i, QSqlRecord* rec, const QString& prefix,
const QString& fieldSep, const QString& sep) const
{
QString filter;
bool separator = false;
for(int j = 0; j < i.count(); ++j){
if (rec->isGenerated(j)) {
if(separator) {
filter += QLatin1Char(' ') + sep + QLatin1Char(' ') ;
}
QString fn = i.fieldName(j);
QSqlField f = rec->field(fn);
filter += toString(prefix, &f, fieldSep);
separator = true;
}
}
return filter;
}
示例4: toString
QString QSqlCursor::toString( const QSqlIndex& i, QSqlRecord* rec, const QString& prefix,
const QString& fieldSep, const QString& sep ) const
{
QString filter;
bool separator = FALSE;
for( uint j = 0; j < i.count(); ++j ){
if ( rec->isGenerated( j ) ) {
if( separator ) {
filter += " " + sep + " " ;
}
QString fn = i.fieldName( j );
QSqlField* f = rec->field( fn );
filter += toString( prefix, f, fieldSep );
separator = TRUE;
}
}
return filter;
}
示例5: QStringLiteral
bool QgsDb2GeometryColumns::populateLayerProperty( QgsDb2LayerProperty &layer )
{
if ( !mQuery.isActive() || !mQuery.next() )
{
return false;
}
layer.schemaName = mQuery.value( 0 ).toString().trimmed();
layer.tableName = mQuery.value( 1 ).toString().trimmed();
layer.geometryColName = mQuery.value( 2 ).toString().trimmed();
layer.type = mQuery.value( 3 ).toString();
if ( mQuery.value( 4 ).isNull() )
{
layer.srid.clear();
layer.srsName.clear();
}
else
{
layer.srid = mQuery.value( 4 ).toString();
layer.srsName = mQuery.value( 5 ).toString();
}
layer.extents = QStringLiteral( "0 0 0 0" ); // no extents
if ( ENV_LUW == mEnvironment )
{
if ( !mQuery.value( 6 ).isNull() ) // Don't get values if null
{
layer.extents = QString(
mQuery.value( 6 ).toString() + ' ' +
mQuery.value( 7 ).toString() + ' ' +
mQuery.value( 8 ).toString() + ' ' +
mQuery.value( 9 ).toString() ).trimmed();
}
}
QgsDebugMsg( QStringLiteral( "layer: %1.%2(%3) type='%4' srid='%5' srsName='%6'" )
.arg( layer.schemaName, layer.tableName, layer.geometryColName,
layer.type, layer.srid, layer.srsName ) );
QgsDebugMsg( "Extents: '" + layer.extents + "'" );
layer.pkCols = QStringList();
// Use the Qt functionality to get the primary key information
// to set the FID column.
// We can only use the primary key if it only has one column and
// the type is Integer or BigInt.
QString table = QStringLiteral( "%1.%2" ).arg( layer.schemaName, layer.tableName );
QSqlIndex pk = mDatabase.primaryIndex( table );
if ( pk.count() == 1 )
{
QSqlField pkFld = pk.field( 0 );
QVariant::Type pkType = pkFld.type();
if ( ( pkType == QVariant::Int || pkType == QVariant::LongLong ) )
{
QString fidColName = pk.fieldName( 0 );
layer.pkCols.append( fidColName );
QgsDebugMsg( "pk is: " + fidColName );
}
}
else
{
QgsDebugMsg( "Warning: table primary key count is " + QString::number( pk.count() ) );
}
layer.pkColumnName = layer.pkCols.size() > 0 ? layer.pkCols.at( 0 ) : QString();
return true;
}