本文整理汇总了C++中QSqlIndex::field方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlIndex::field方法的具体用法?C++ QSqlIndex::field怎么用?C++ QSqlIndex::field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlIndex
的用法示例。
在下文中一共展示了QSqlIndex::field方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compare_recs
static int compare_recs(const QSqlRecord* buf1, const QSqlRecord* buf2,
const QSqlIndex& idx)
{
int cmp = 0;
int i = 0;
const QString fn(idx.field(i).name());
const QSqlField f1 = buf1->field(fn);
if (f1.isValid()) {
switch (f1.type()) { // ### more types?
case QVariant::String:
cmp = f1.value().toString().trimmed().compare(
buf2->value(fn).toString().trimmed());
break;
default:
if (f1.value().toDouble() < buf2->value(fn).toDouble())
cmp = -1;
else if (f1.value().toDouble() > buf2->value(fn).toDouble())
cmp = 1;
}
}
if (idx.isDescending(i))
cmp = -cmp;
return cmp;
}
示例2: primaryKeyIndex
int TableSchema::primaryKeyIndex() const
{
QSqlTableModel model;
model.setTable(tablename);
QSqlIndex index = model.primaryKey();
if (index.isEmpty()) {
return -1;
}
QSqlField fi = index.field(0);
return model.record().indexOf(fi.name());
}
示例3: primaryKeyFieldName
QString TableSchema::primaryKeyFieldName() const
{
QSqlTableModel model;
model.setTable(tablename);
QSqlIndex index = model.primaryKey();
if (index.isEmpty()) {
return QString();
}
QSqlField fi = index.field(0);
return fi.name();
}
示例4: index_matches
static bool index_matches(const Q3SqlCursor* cur, const QSqlRecord* buf,
const QSqlIndex& idx)
{
bool indexEquals = false;
for (int i = 0; i < idx.count(); ++i) {
const QString fn(idx.field(i).name());
if (cur->value(fn) == buf->value(fn))
indexEquals = true;
else {
indexEquals = false;
break;
}
}
return indexEquals;
}
示例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;
}