本文整理汇总了C++中QSqlRecord::field方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlRecord::field方法的具体用法?C++ QSqlRecord::field怎么用?C++ QSqlRecord::field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlRecord
的用法示例。
在下文中一共展示了QSqlRecord::field方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StructureTable
QString Browser::StructureTable( QSqlRecord now )
{
QSqlRecord rec = now;
QString createtable;
QString sqltipename;
QStringList CreateTable;
int totalcools = rec.count();
if (totalcools > 0) {
/* sqlite3 table construct from odbc converter */
for (int i = 0; i < totalcools; ++i) {
QSqlField fld = rec.field(i);
QString name = Strtrimmed(fld.name());
QString typeoffield = QString(QVariant::typeToName(fld.type()));
/* fld.isAutoValue() never true from auto_increment mysql ??? */
if (fld.requiredStatus() and i < 2 and typeoffield == "int") {
sqltipename = QString("%1 INTEGER PRIMARY KEY").arg(name);
} else if ( typeoffield == "double" or typeoffield == "int" ) {
sqltipename = QString("%1 NUMERIC").arg(name);
} else if ( typeoffield == "QByteArray") {
sqltipename = QString("%1 BLOB").arg(name);
} else {
sqltipename = QString("%1 TEXT").arg(name);
}
CreateTable.append(sqltipename);
////////qDebug() << "### fieldname " << name;
///////////qDebug() << "### typeoffield " << typeoffield;
}
QString midlecreate = CreateTable.join(",");
midlecreate.prepend(QString("CREATE TABLE %1 (").arg(runningtable));
midlecreate.append(");");
createtable = midlecreate;
}
return createtable;
}
示例2: QDialog
Login::Login(Configuracion *m_config,QWidget *parent) :
QDialog(parent),
ui(new Ui::Login)
{
this->setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint|Qt::WindowTitleHint);
ui->setupUi(this);
//--------------------------------------------
// Conexiones
//--------------------------------------------
connect(ui->btnEmpresa,SIGNAL(clicked()),this,SLOT(btnEmpresa_clicked()));
connect(ui->Crearconfiguracin,SIGNAL(clicked()),this,SLOT(Crearconfiguracion_clicked()));
// TODO - Rellenar en base a fichero de empresas BD terra.
// Relleno combo empresas
QSqlQuery *QryEmpresas = new QSqlQuery(QSqlDatabase::database("terra"));
QryEmpresas->prepare("Select * from empresas");
if(QryEmpresas->exec()) {
while (QryEmpresas->next()) {
QSqlRecord rEmpresa = QryEmpresas->record();
ui->cboEmpresa->addItem(rEmpresa.field("nombre").value().toString());
}
}
this->ui->lineUsuario->setFocus();
}
示例3: Nuevocodigo_cliente
QString Cliente::Nuevocodigo_cliente()
{
QString codigo;
double nCodigo = 1;
QSqlQuery qClientes(Configuracion_global->groupDB);
if(qClientes.exec("select codigo_cliente from clientes order by codigo_cliente desc limit 1"))
{
if (qClientes.next())
{
QSqlRecord registro = qClientes.record();
codigo = registro.field("codigo_cliente").value().toString();
nCodigo = codigo.mid(Configuracion_global->cuenta_clientes.length()).toULong();
nCodigo ++;
codigo = QString::number(nCodigo);
}
}
QString codigo_nuevo;
QString formato = QString("%1.0f").arg(Configuracion_global->digitos_cuentas_contables-Configuracion_global->cuenta_clientes.length());
formato.prepend("%0");
std::string _x = formato.toStdString();
codigo_nuevo.sprintf(_x.c_str(),nCodigo);
codigo_nuevo.prepend(Configuracion_global->cuenta_clientes);
cuenta_iva_repercutido = Configuracion_global->cuenta_iva_repercutido1 +codigo_nuevo;
return codigo_nuevo;
}
示例4: populateDictionary
void QRelation::populateDictionary()
{
if (!isValid())
return;
if (model == NULL)
populateModel();
QSqlRecord record;
for (int i=0; i < model->rowCount(); ++i) {
record = model->record(i);
dictionary[record.field(rel.indexColumn()).value().toString()] =
record.field(rel.displayColumn()).value();
}
m_dictInitialized = true;
}
示例5: init
void TablePrivate::init()
{
Q_Q(Table);
q->setTable(name);
q->setEditStrategy(QSqlTableModel::OnFieldChange);
q->select();
QSqlRecord columnNames = q->record();
int columnCount = columnNames.count();
columns.reserve(columnCount);
for(int i = 0; i < columnCount; ++i) {
Column *column = new Column(columnNames.field(i), q);
column->setIndex(i);
columns.append(column);
columnsByName.insert(column->name(), column);
}
while(q->canFetchMore())
q->fetchMore();
QSqlQuery query = q->query();
int rowCount = q->rowCount();
int idIndex = q->record().indexOf(QLatin1String("id"));
int id = 0;
rows.reserve(rowCount);
rowsById.reserve(rowCount);
for(int i = 0; i < rowCount; ++i) {
query.seek(i);
id = query.value(idIndex).toInt();
Row *row = new Row(i, id, q);
rows.append(row);
rowsById.insert(id, row);
}
}
示例6: field
QSqlField QSqlRecordProto::field(int index) const
{
QSqlRecord *item = qscriptvalue_cast<QSqlRecord*>(thisObject());
if (item)
return item->field(index);
return QSqlField();
}
示例7: csvExport
void AddressBook::csvExport() {
QFileDialog dialog(this);
QStringList fileNames;
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilter(tr("Données CSV (*.csv)"));
if (dialog.exec()) fileNames = dialog.selectedFiles();
QFile file(fileNames[0]);
if (!file.open(QIODevice::WriteOnly)) QMessageBox::information(this, tr("Impossible d'ouvrir le fichier"),file.errorString());
QString data;
data = "Last Name,First Name,Birthday,Home Phone,Mobile Phone,Business Phone,Business Fax,E-mail Address,Web Page,Home Address,Home City,Home Postal Code,Business Address,Business City,Business Postal Code\n";
// /!\ CETTE (ces) LIGNE(s) (et les éventuelles lignes semblables) A (ont) ETE INSPIREE(s) PAR "LA MAILING LIST QT" (disponible à l'adresse "http://lists.trolltech.com/qt-interest/2008-03/thread00073-0.html"). LE CODE REPRIS N'EST PAS DISPONIBLE A LA (aux) LIGNE(s) SUIVANTE(s)
for (int row = 0; row < model->rowCount(); ++row) {
QSqlRecord record = model->record(row);
for (int field = 0; field < record.count(); ++field) {
if(field != 0 && field != 4) {
if (field > 1) data += ",";
data += record.field(field).value().toString(); //
}
}
data += "\n";
}
QTextStream *output;
output = new QTextStream(&file);
*output << data;
QMessageBox::information(this,"Exportation","L'exportation au format CSV est terminée");
}
示例8: QSqlField_snippets
void QSqlField_snippets()
{
#if 0
{
//! [2]
QSqlField field("age", QVariant::Int);
field.setValue(QPixmap()); // WRONG
//! [2]
}
#endif
{
//! [3]
QSqlField field("age", QVariant::Int);
field.setValue(QString("123")); // casts QString to int
//! [3]
}
{
//! [4]
QSqlQuery query;
//! [4] //! [5]
QSqlRecord record = query.record();
//! [5] //! [6]
QSqlField field = record.field("country");
//! [6]
}
}
示例9:
QDebug operator<<(QDebug dbg, const QSqlRecord &r)
{
dbg << "QSqlRecord(" << r.count() << ')';
for (int i = 0; i < r.count(); ++i)
dbg << '\n' << QString::fromLatin1("%1:").arg(i, 2) << r.field(i) << r.value(i).toString();
return dbg;
}
示例10: currentQuery
TSqlSchema::TSqlSchema(QObject *parent) : QObject(parent)
{
database = QSqlDatabase::addDatabase("QSQLITE");
database.setDatabaseName("imsit.sqlite");
if(!database.open())
{
currentErrorCode = database.lastError();
qDebug() << "Error code = " << currentErrorCode.text()
<< endl;
}
QString genre = "select * from genre";
QSqlQuery currentQuery(genre);
if(!currentQuery.exec())
{
currentErrorCode = currentQuery.lastError();
qDebug() << "Error code = " << currentErrorCode.text()
<< endl;
}
else
while(currentQuery.next())
{
const QSqlRecord currentRecord = currentQuery.record();
QSqlField genre = currentRecord.field("genre");
qDebug() << genre.value().toString();
}
}
示例11: NuevoCodigoCliente
QString Cliente::NuevoCodigoCliente()
{
Configuracion *oConfig = new Configuracion();
oConfig->CargarDatos();
QString cCodigo;
QString cNum;
int nCodigo;
QSqlQuery *qClientes = new QSqlQuery(QSqlDatabase::database("empresa"));
if(qClientes->exec("select cCodigoCliente from clientes order by cCodigoCliente desc limit 1")) {
if (qClientes->next()) {
QSqlRecord registro = qClientes->record();
cCodigo = registro.field("cCodigoCliente").value().toString();
nCodigo = cCodigo.toInt();
nCodigo ++;
cCodigo = QString::number(nCodigo);
}
}
if (nCodigo == 0 || nCodigo == 1) {
cNum = "1";
while (cNum.length()< (oConfig->nDigitosCuentasContables - oConfig->cCuentaClientes.length()) ) {
cNum.prepend("0");
}
cCodigo = oConfig->cCuentaClientes + cNum;
}
return cCodigo;
}
示例12: query
Column *TablePrivate::addColumn(const QString &name, const QString &sqlType, const QVariant &defaultValue)
{
Q_Q(Table);
if(q->columnNames().contains(name, Qt::CaseInsensitive)) {
qWarning() << "TablePrivate::addColumn: Duplicate column name" << name;
return columnsByName.value(name);
}
QSqlQuery query(database->sqlDatabase());
QString queryString = QLatin1String("ALTER TABLE ")+this->name+QLatin1String(" ADD ")+name+
QLatin1String(" ")+sqlType;
if(!defaultValue.toString().isEmpty()) {
queryString += QLatin1String(" DEFAULT ")+defaultValue.toString();
}
query.exec(queryString);
checkSqlError(query);
query.finish();
QSqlRecord record = database->sqlDatabase().record(this->name);
QSqlField columnField = record.field(record.indexOf(name));
q->beginInsertColumns(QModelIndex(),columns.count(), columns.count());
Column *column = new Column(columnField, q);
columns.append(column);
columnsByName.insert(name, column);
foreach(Row *row, rows) {
row->addColumn(name, defaultValue);
}
示例13: init
void TablePrivate::init()
{
Q_Q(Table);
QSqlRecord columnNames = database->sqlDatabase().record(name);
columns.reserve(columnNames.count());
for(int i = 0; i < columnNames.count(); ++i) {
Column *column = new Column(columnNames.field(i), q);
columns.append(column);
columnsByName.insert(column->name(), column);
}
QSqlQuery query(database->sqlDatabase());
query.exec(QLatin1String("SELECT * FROM ")+name);
rows.reserve(query.size());
rowsById.reserve(query.size());
int idIndex = query.record().indexOf(QLatin1String("id"));
Q_ASSERT_X(idIndex != -1, "TablePrivate::init", "The table has no field 'id'");
int id = 0;
while(query.next()) {
id = query.value(idIndex).toInt();
Row *row = new Row(query, q_ptr);
rows.append(row);
rowsById.insert(id, row);
}
checkSqlError(query);
query.finish();
}
示例14: QString
IlwisObject *InternalIlwisObjectFactory::createRepresentation(const Resource& resource, const IOOptions &options) const{
QString code = resource.code();
Representation *rpr = createFromResource<Representation>(resource, options);
if ( code != sUNDEF) {
InternalDatabaseConnection db;
QString query = QString("Select linkedtable from codes where code = '%1'").arg(code);
if (db.exec(query)) {
if ( db.next()){
QString table = db.value(0).toString();
if ( table == "representation"){
query = QString("Select * from representation where code='%1'").arg(code);
if (db.exec(query)) {
if ( db.next()){
QSqlRecord rec = db.record();
rpr->fromInternal(rec);
QString relateddomain = rec.field("relateddomain").value().toString();
QString rprType = rec.field("representationtype").value().toString();
QString definition = rec.field("definition").value().toString();
QString mode = rec.field("mode").value().toString();
if ( rprType == "continuouscolor"){
rpr->colors(new ContinuousColorLookup(definition, mode));
}else if ( rprType == "palettecolor"){
rpr->colors(new PaletteColorLookUp(definition));
}
if ( relateddomain == "value"){
rpr->domain(IDomain("value"));
}
rpr->readOnly(true);
}else
return 0;
}else
return 0;
}else
return 0;
}else
return 0;
}else
return 0;
}
return rpr;
}
示例15: if
IlwisObject *InternalIlwisObjectFactory::createProjection(const Resource& resource, const IOOptions &options) const {
QString query;
QString code = resource.code();
Projection *proj = 0;
if ( code == sUNDEF){ // meant for new projections which will be initialized later (e.g by the streaming connector)
proj = createFromResource<Projection>(resource, options);
}
else if ( code != "") {
InternalDatabaseConnection db;
query = QString("Select * from projection where code = '%1'").arg(code);
if ( db.exec(query)) {
if (db.next()) {
QSqlRecord rec = db.record();
const ProjectionFactory *factory = kernel()->factory<ProjectionFactory>("ProjectionFactory",resource);
if ( factory) {
ProjectionImplementation *projimpl = 0;
if ( options.contains("proj4"))
projimpl = static_cast<ProjectionImplementation *>(factory->create(resource.code(), options["proj4"].toString()));
else
projimpl = static_cast<ProjectionImplementation *>(factory->create(resource));
if (!projimpl) {
kernel()->issues()->log(TR(ERR_COULDNT_CREATE_OBJECT_FOR_2).arg("projection", resource.name()));
return 0;
}
proj = createFromResource<Projection>(resource, options);
proj->setImplementation(projimpl);
proj->fromInternal(rec);
proj->setAuthority(rec.field("authority").value().toString());
proj->setWkt(rec.field("wkt").value().toString());
} else {
kernel()->issues()->log(TR(ERR_COULDNT_CREATE_OBJECT_FOR_2).arg("ProjectionFactory",resource.name()));
}
} else {
kernel()->issues()->log(TR(ERR_FIND_SYSTEM_OBJECT_1).arg(code));
}
} else{
kernel()->issues()->logSql(db.lastError());
}
} else {
kernel()->issues()->log(TR(ERR_MISSING_CODE_FOR_SYSTEM_OBJECT));
}
return proj;
}