本文整理汇总了C++中FLFieldMetaData::length方法的典型用法代码示例。如果您正苦于以下问题:C++ FLFieldMetaData::length方法的具体用法?C++ FLFieldMetaData::length怎么用?C++ FLFieldMetaData::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FLFieldMetaData
的用法示例。
在下文中一共展示了FLFieldMetaData::length方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nextCounter
QVariant FLUtil::nextCounter( const QString & name, FLSqlCursor * cursor_ ) {
if ( !cursor_ )
return QVariant();
FLTableMetaData *tMD = cursor_->metadata();
if ( !tMD )
return QVariant();
FLFieldMetaData *field = tMD->field( name );
if ( !field )
return QVariant();
int type = field->type();
if ( type != QVariant::String && type != QVariant::Double )
return QVariant();
unsigned int len = field->length();
QString cadena;
FLSqlQuery q( 0, cursor_->db()->connectionName() );
q.setForwardOnly( true );
q.setTablesList( tMD->name() );
q.setSelect( name );
q.setFrom( tMD->name() );
q.setWhere( "LENGTH(" + name + ")=" + QString::number( len ) );
q.setOrderBy( name + " DESC" );
if ( !q.exec() )
return QVariant();
double maxRange = pow( 10, len );
double numero = maxRange;
while ( numero >= maxRange ) {
if ( !q.next() ) {
numero = 1;
break;
}
numero = q.value( 0 ).toDouble();
numero++;
}
if ( type == QVariant::String ) {
cadena = QString::number( numero, 'f', 0 );
if ( cadena.length() < len ) {
QString str;
str.fill( '0', ( len - cadena.length() ) );
cadena = str + cadena;
}
return QVariant( cadena );
}
if ( type == QVariant::Double )
return QVariant( numero );
return QVariant();
}
示例2: sqlCreateTable
QString SqliteDriver::sqlCreateTable(FLTableMetaData *tmd)
{
#ifndef FL_QUICK_CLIENT
if (!tmd)
return QString::null;
QString primaryKey(QString::null);
QString sql = "CREATE TABLE " + tmd->name() + " (";
FLFieldMetaData *field;
FLTableMetaData::FLFieldMetaDataList *fieldList = tmd->fieldList();
unsigned int unlocks = 0;
QDictIterator<FLFieldMetaData> it(*fieldList);
while ((field = it.current()) != 0) {
++it;
if (field->type() == FLFieldMetaData::Unlock)
unlocks++;
}
if (unlocks > 1) {
#ifdef FL_DEBUG
qWarning("FLManager : " + QApplication::tr("No se ha podido crear la tabla ") + tmd->name());
qWarning("FLManager : " + QApplication::tr("Hay más de un campo tipo unlock. Solo puede haber uno."));
#endif
return QString::null;
}
QDictIterator<FLFieldMetaData> it2(*fieldList);
while ((field = it2.current()) != 0) {
++it2;
sql += field->name();
switch (field->type()) {
case QVariant::Int:
sql += " INTEGER";
break;
case QVariant::UInt:
sql += " INTEGER";
break;
case QVariant::Bool:
case FLFieldMetaData::Unlock:
sql += " BOOLEAN";
break;
case QVariant::Double:
sql += " FLOAT";
break;
case QVariant::Time:
sql += " VARCHAR(20)";
break;
case QVariant::Date:
sql += " VARCHAR(20)";
break;
case QVariant::Pixmap:
sql += " TEXT";
break;
case QVariant::String:
sql += " VARCHAR";
break;
case QVariant::StringList:
sql += " TEXT";
break;
case QVariant::ByteArray:
sql += " CLOB";
break;
case FLFieldMetaData::Serial:
sql += " INTEGER";
if (!field->isPrimaryKey())
sql += " PRIMARY KEY";
break;
}
int longitud = field->length();
if (longitud > 0)
sql += "(" + QString::number(longitud) + ")";
if (field->isPrimaryKey()) {
if (primaryKey.isEmpty()) {
sql += " PRIMARY KEY";
primaryKey = field->name();
} else {
#ifdef FL_DEBUG
qWarning(QApplication::tr("FLManager : Tabla -> ") +
tmd->name() + QApplication::tr(" . Se ha intentado poner una segunda clave primaria para el campo ") +
field->name() + QApplication::tr(" , pero el campo ") + primaryKey +
QApplication::tr(" ya es clave primaria. Sólo puede existir una clave primaria en FLTableMetaData, use FLCompoundKey para crear claves compuestas."));
#endif
return QString::null;
}
} else {
//.........这里部分代码省略.........
示例3: alterTable
//.........这里部分代码省略.........
delete oldMTD;
if (newMTD)
delete newMTD;
return false;
}
FLTableMetaData::FLFieldMetaDataList *fieldList = oldMTD->fieldList();
FLFieldMetaData *oldField = 0;
if (!fieldList) {
#ifdef FL_DEBUG
qWarning("FLManager::alterTable : " + QApplication::tr("Los antiguos metadatos no tienen campos."));
#endif
if ((oldMTD != newMTD) && oldMTD)
delete oldMTD;
if (newMTD)
delete newMTD;
return false;
}
QString renameOld = oldMTD->name().left(6) + "alteredtable" + QDateTime::currentDateTime().toString("ddhhssz");
if (!db_->dbAux()) {
if ((oldMTD != newMTD) && oldMTD)
delete oldMTD;
if (newMTD)
delete newMTD;
return false;
}
db_->dbAux() ->transaction();
if (!key.isEmpty() && key.length() == 40) {
QSqlCursor c("flfiles", true, db_->dbAux());
c.setForwardOnly(true);
QSqlRecord *buffer;
c.setFilter("nombre='" + renameOld + ".mtd'");
c.select();
if (!c.next()) {
buffer = c.primeInsert();
buffer->setValue("nombre", renameOld + ".mtd");
buffer->setValue("contenido", mtd1);
buffer->setValue("sha", key);
c.insert();
}
}
QSqlQuery q(QString::null, db_->dbAux());
if (!q.exec("CREATE TABLE " + renameOld + " AS SELECT * FROM " + oldMTD->name() + ";") || !q.exec("DROP TABLE " + oldMTD->name() + ";")) {
#ifdef FL_DEBUG
qWarning("FLManager::alterTable : " + QApplication::tr("No se ha podido renombrar la tabla antigua."));
#endif
db_->dbAux() ->rollback();
if ((oldMTD != newMTD) && oldMTD)
delete oldMTD;
if (newMTD)
delete newMTD;
return false;
}
if (!db_->manager()->createTable(newMTD)) {
db_->dbAux() ->rollback();
if ((oldMTD != newMTD) && oldMTD)
示例4: while
FLTableMetaData *FLManager::metadata(QDomElement *mtd, bool quick)
{
if (!mtd)
return 0;
QString name, a, q;
bool v = true, ed = true, cw = true, dl = false;
QDomNode no = mtd->firstChild();
while (!no.isNull()) {
QDomElement e = no.toElement();
if (!e.isNull()) {
if (e.tagName() == "field") {
no = no.nextSibling();
continue;
}
if (e.tagName() == "name") {
name = e.text();
no = no.nextSibling();
continue;
}
if (e.tagName() == "query") {
q = e.text();
no = no.nextSibling();
continue;
}
if (e.tagName() == "alias") {
a = e.text().mid(30, e.text().length() - 32);
a = FLUtil::translate("MetaData", a);
no = no.nextSibling();
continue;
}
if (e.tagName() == "visible") {
v = (e.text() == "true");
no = no.nextSibling();
continue;
}
if (e.tagName() == "editable") {
ed = (e.text() == "true");
no = no.nextSibling();
continue;
}
if (e.tagName() == "concurWarn") {
cw = (e.text() == "true");
no = no.nextSibling();
continue;
}
if (e.tagName() == "detectLocks") {
dl = (e.text() == "true");
no = no.nextSibling();
continue;
}
}
no = no.nextSibling();
}
FLTableMetaData *tmd = new FLTableMetaData(name, a, q);
FLCompoundKey *cK = 0;
QStringList assocs;
tmd->setConcurWarn(cw);
tmd->setDetectLocks(dl);
no = mtd->firstChild();
while (!no.isNull()) {
QDomElement e = no.toElement();
if (!e.isNull()) {
if (e.tagName() == "field") {
FLFieldMetaData *f = metadataField(&e, v, ed);
if (!tmd)
tmd = new FLTableMetaData(name, a, q);
tmd->addFieldMD(f);
if (f->isCompoundKey()) {
if (!cK)
cK = new FLCompoundKey();
cK->addFieldMD(f);
}
if (!f->associatedFieldName().isEmpty()) {
assocs.append(f->associatedFieldName());
assocs.append(f->associatedFieldFilterTo());
assocs.append(f->name());
}
no = no.nextSibling();
continue;
}
}
no = no.nextSibling();
}
tmd->setCompoundKey(cK);
QString aWith, aBy;
for (QStringList::Iterator it = assocs.begin(); it != assocs.end(); ++it) {
aWith = (*it);
++it;
aBy = (*it);
++it;
tmd->field((*it))->setAssociatedField(tmd->field(aWith), aBy);
}
//.........这里部分代码省略.........