本文整理汇总了C++中QSqlIndex类的典型用法代码示例。如果您正苦于以下问题:C++ QSqlIndex类的具体用法?C++ QSqlIndex怎么用?C++ QSqlIndex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSqlIndex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sipReleaseType
static PyObject *meth_QSqlIndex_setCursorName(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
const QString* a0;
int a0State = 0;
QSqlIndex *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QSqlIndex, &sipCpp, sipType_QString,&a0, &a0State))
{
Py_BEGIN_ALLOW_THREADS
sipCpp->setCursorName(*a0);
Py_END_ALLOW_THREADS
sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State);
Py_INCREF(Py_None);
return Py_None;
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QSqlIndex, sipName_setCursorName, doc_QSqlIndex_setCursorName);
return NULL;
}
示例2: qGetTableInfo
static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool onlyPIndex = false)
{
QString schema;
QString table(tableName);
int indexOfSeparator = tableName.indexOf(QLatin1Char('.'));
if (indexOfSeparator > -1) {
schema = tableName.left(indexOfSeparator).append(QLatin1Char('.'));
table = tableName.mid(indexOfSeparator + 1);
}
q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info (") + _q_escapeIdentifier(table) + QLatin1String(")"));
QSqlIndex ind;
while (q.next()) {
bool isPk = q.value(5).toInt();
if (onlyPIndex && !isPk)
continue;
QString typeName = q.value(2).toString().toLower();
QSqlField fld(q.value(1).toString(), qGetColumnType(typeName));
if (isPk && (typeName == QLatin1String("integer")))
// INTEGER PRIMARY KEY fields are auto-generated in sqlite
// INT PRIMARY KEY is not the same as INTEGER PRIMARY KEY!
fld.setAutoValue(true);
fld.setRequired(q.value(3).toInt() != 0);
fld.setDefaultValue(q.value(4));
ind.append(fld);
}
return ind;
}
示例3: qGetTableInfo
static QSqlIndex qGetTableInfo(QSqlQuery &q, QString &tableName, bool onlyPIndex = false)
{
QString dbName;
QString table(tableName);
int indexOfSeparator = tableName.indexOf(QLatin1Char('.'));
if (indexOfSeparator > -1) {
dbName = tableName.left(indexOfSeparator +1 );
table = tableName.mid(indexOfSeparator + 1);
}
q.exec(QLatin1String("PRAGMA ") + dbName + QLatin1String("table_info (") + _q_escapeIdentifier(table) + QLatin1String(")"));
const int NAME_IDX = 1;
const int TYPE_IDX = 2;
const int NOTNULL_IDX = 3;
const int DFLT_VALUE_IDX = 4;
const int PK_IDX = 5;
QSqlIndex ind;
while (q.next()) {
bool isPk = q.value(PK_IDX).toInt();
if (onlyPIndex && !isPk)
continue;
QString typeName = q.value(TYPE_IDX).toString().toLower();
QSqlField fld(q.value(NAME_IDX).toString(), qGetColumnType(typeName));
if (isPk && (typeName == QLatin1String("integer")))
// INTEGER PRIMARY KEY fields are auto-generated in sqlite
// INT PRIMARY KEY is not the same as INTEGER PRIMARY KEY!
fld.setAutoValue(true);
fld.setRequired(q.value(NOTNULL_IDX).toInt() != 0);
fld.setDefaultValue(q.value(DFLT_VALUE_IDX));
ind.append(fld);
}
return ind;
}
示例4: 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;
}
示例5: primaryIndex
int Q3SqlCursor::del(bool invalidate)
{
QSqlIndex idx = primaryIndex(false);
if (idx.isEmpty())
return del(qWhereClause(&d->editBuffer, d->nm, QLatin1String("and"), driver()), invalidate);
return del(toString(primaryIndex(), &d->editBuffer, d->nm, QString(QLatin1Char('=')), QLatin1String("and")), invalidate);
}
示例6: qOrderByClause
QString qOrderByClause( const QSqlIndex & i, const QString& prefix = QString::null )
{
QString str;
int k = i.count();
if( k == 0 ) return QString::null;
str = " order by " + i.toString( prefix );
return str;
}
示例7: primaryIndex
int QSqlCursor::del( bool invalidate )
{
QSqlIndex idx = primaryIndex( FALSE );
if ( idx.isEmpty() )
return del( qWhereClause( &d->editBuffer, d->nm, "and", driver() ), invalidate );
else
return del( toString( primaryIndex(), &d->editBuffer, d->nm,
"=", "and" ), invalidate );
}
示例8: qOrderByClause
QString qOrderByClause(const QSqlIndex & i, const QString& prefix = QString())
{
QString str;
int k = i.count();
if(k == 0)
return QString();
str = QLatin1String(" order by ") + i.toString(prefix);
return str;
}
示例9: 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;
}
示例10: editBuffer
QSqlRecord* QSqlCursor::primeUpdate()
{
// memorize the primary keys as they were before the user changed the values in editBuffer
QSqlRecord* buf = editBuffer( TRUE );
QSqlIndex idx = primaryIndex( FALSE );
if ( !idx.isEmpty() )
d->editIndex = toString( idx, buf, d->nm, "=", "and" );
else
d->editIndex = qWhereClause( buf, d->nm, "and", driver() );
return buf;
}
示例11: editBuffer
QSqlRecord* Q3SqlCursor::primeUpdate()
{
// memorize the primary keys as they were before the user changed the values in editBuffer
QSqlRecord* buf = editBuffer(true);
QSqlIndex idx = primaryIndex(false);
if (!idx.isEmpty())
d->editIndex = toString(idx, buf, d->nm, QString(QLatin1Char('=')), QLatin1String("and"));
else
d->editIndex = qWhereClause(buf, d->nm, QLatin1String("and"), driver());
return buf;
}
示例12: 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());
}
示例13: 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();
}
示例14: field
QSqlIndex Q3SqlCursor::index(const QStringList& fieldNames) const
{
QSqlIndex idx;
for (QStringList::ConstIterator it = fieldNames.begin(); it != fieldNames.end(); ++it) {
QSqlField f = field((*it));
if (!f.isValid()) { /* all fields must exist */
idx.clear();
break;
}
idx.append(f);
}
return idx;
}
示例15: 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;
}