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;
}
TableSchema::TableSchema(const QString &table, const QString &env)
    : tablename(table)
{
    if (!dbSettings) {
        QString path = QLatin1String("config") + QDir::separator() + "database.ini";
        if (!QFile::exists(path)) {
            qCritical("not found, %s", qPrintable(path));
        }
        dbSettings = new QSettings(path, QSettings::IniFormat);
    }

    if (openDatabase(env)) {
        if (!tablename.isEmpty()) {
            QSqlTableModel model;
            model.setTable(tablename);
            tableFields = model.record();

            if (model.database().driverName().toUpper() == "QPSQL") {
                // QPSQLResult doesn't call QSqlField::setAutoValue(), fix it
                for (int i = 0; i < tableFields.count(); ++i) {
                    QSqlField f = tableFields.field(i);
                    if (f.defaultValue().toString().startsWith(QLatin1String("nextval"))) {
                        f.setAutoValue(true);
                        tableFields.replace(i, f);
                    }
                }
            }
        } else {
            qCritical("Empty table name");
        }
    }
}
static PyObject *meth_QSqlField_setValue(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        const QVariant * a0;
        int a0State = 0;
        QSqlField *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QSqlField, &sipCpp, sipType_QVariant,&a0, &a0State))
        {
            Py_BEGIN_ALLOW_THREADS
            sipCpp->setValue(*a0);
            Py_END_ALLOW_THREADS
            sipReleaseType(const_cast<QVariant *>(a0),sipType_QVariant,a0State);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QSqlField, sipName_setValue, NULL);

    return NULL;
}
Example #4
0
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();
        }
}
int TableSchema::autoValueIndex() const
{
    for (int i = 0; i < tableFields.count(); ++i) {
        QSqlField f = tableFields.field(i);
        if (f.isAutoValue())
            return i;
    }
    return -1;
}
QString TableSchema::autoValueFieldName() const
{
    for (int i = 0; i < tableFields.count(); ++i) {
        QSqlField f = tableFields.field(i);
        if (f.isAutoValue())
            return f.name();
    }
    return QString();
}
QList<QPair<QString, QVariant::Type>> TableSchema::getFieldTypeList() const
{
    QList<QPair<QString, QVariant::Type>> fieldList;
    for (int i = 0; i < tableFields.count(); ++i) {
        QSqlField f = tableFields.field(i);
        fieldList << QPair<QString, QVariant::Type>(f.name(), f.type());
    }
    return fieldList;
}
Example #8
0
int QSqlCursor::insert( bool invalidate )
{
    if ( ( d->md & Insert ) != Insert || !driver() )
	return FALSE;
    int k = d->editBuffer.count();
    if ( k == 0 )
	return 0;
    
    QString fList;
    QString vList;
    bool comma = FALSE;
    // use a prepared query if the driver supports it
    if ( driver()->hasFeature( QSqlDriver::PreparedQueries ) ) {
	int cnt = 0;
	bool oraStyle = driver()->hasFeature( QSqlDriver::NamedPlaceholders );
	for( int j = 0; j < k; ++j ) {
	    QSqlField* f = d->editBuffer.field( j );
	    if ( d->editBuffer.isGenerated( j ) ) {
		if ( comma ) {
		    fList += ",";
		    vList += ",";
		}
		fList += f->name();
		vList += (oraStyle == TRUE) ? ":f" + QString::number(cnt) : QString("?");
		cnt++;
		comma = TRUE;
	    }
	}
	if ( !comma ) {
	    return 0;
	}
	QString str;
	str.append( "insert into " ).append( name() ).append( "(" ).append( fList ).append( ") values (" ).append( vList ). append ( ")" );
	return applyPrepared( str, invalidate );
    } else {
	for( int j = 0; j < k; ++j ) {
	    QSqlField* f = d->editBuffer.field( j );
	    if ( d->editBuffer.isGenerated( j ) ) {
		if ( comma ) {
		    fList += ",";
		    vList += ",";
		}
		fList += f->name();
		vList += driver()->formatValue( f );
		comma = TRUE;
	    }
	}

	if ( !comma ) {
	    // no valid fields found
	    return 0;
	}
	QString str;
	str.append( "insert into " ).append( name() ).append( "(" ).append( fList ).append( ") values (" ).append( vList ). append ( ")" );
	return apply( str, invalidate );
    }
}
Example #9
0
/*!
    Clears the values in all the widgets, and the fields they are
    mapped to, in the form, and sets them to NULL.
*/
void Q3SqlForm::clearValues()
{
    QMap< QWidget *, QSqlField * >::Iterator it;
    for(it = d->map.begin(); it != d->map.end(); ++it){
        QSqlField* f = (*it);
        if (f)
            f->clear();
    }
    readFields();
}
QPair<QString, QVariant::Type> TableSchema::getPrimaryKeyFieldType() const
{
    QPair<QString, QVariant::Type> pair;
    int index = primaryKeyIndex();
    if (index >= 0) {
        QSqlField f = tableFields.field(index);
        pair = QPair<QString, QVariant::Type>(f.name(), f.type());
    }
    return pair;
}
Example #11
0
/*!
    Updates the widget \a widget with the value from the SQL field it
    is mapped to. Nothing happens if no SQL field is mapped to the \a
    widget.
*/
void Q3SqlForm::readField(QWidget * widget)
{
    sync();
    QSqlField * field = 0;
    Q3SqlPropertyMap * pmap = (d->propertyMap == 0) ?
                             Q3SqlPropertyMap::defaultMap() : d->propertyMap;
    field = widgetToField(widget);
    if(field)
        pmap->setProperty(widget, field->value());
}
int TableSchema::lockRevisionIndex() const
{
    for (int i = 0; i < tableFields.count(); ++i) {
        QSqlField f = tableFields.field(i);
        if (fieldNameToVariableName(f.name()) == "lockRevision") {
            return i;
        }
    }
    return -1;
}
Example #13
0
/*!
    Updates the SQL field with the value from the \a widget it is
    mapped to. Nothing happens if no SQL field is mapped to the \a
    widget.
*/
void Q3SqlForm::writeField(QWidget * widget)
{
    sync();
    QSqlField * field = 0;
    Q3SqlPropertyMap * pmap = (d->propertyMap == 0) ?
                             Q3SqlPropertyMap::defaultMap() : d->propertyMap;
    field = widgetToField(widget);
    if(field)
        field->setValue(pmap->property(widget));
}
QString Browser::StructureMYSQLTable( QSqlRecord now )
{
    QSqlRecord rec = now;
    QString createtable;
    QString sqltipename, mkey;
    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());
                  name.toUpper();
                  if (name == "id") {
                  name = "ID";
                  }
                  QString typeoffield = QString(QVariant::typeToName(fld.type()));
                  int sizefe = fld.length();
                  if (sizefe > 255) {
                  sizefe = 255;
                  }
                  if (sizefe < 1) {
                  sizefe = 255;
                  }
                  /* fld.isAutoValue()  never true from auto_increment mysql ??? */
                  if (fld.requiredStatus() and i < 2 and typeoffield == "int") {
                   sqltipename = QString("  `%1` INT(%2) NOT NULL auto_increment").arg(name).arg(sizefe);
                   mkey = QString("   KEY `%1` (`%1`)").arg(name);
                  } else if ( typeoffield == "int" ) {
                   sqltipename = QString("  `%1` int(%2) default NULL").arg(name).arg(sizefe); 
                  } else if (  typeoffield == "double") {
                   sqltipename = QString("  `%1` int(%2) default NULL").arg(name).arg(sizefe);    
                  } else if (  typeoffield == "QByteArray") {
                   sqltipename = QString("  `%1` LONGBLOB default NULL").arg(name);    
                  } else {
                   sqltipename = QString("  `%1` VARCHAR(%2) default NULL").arg(name).arg(sizefe);   
                  }
                  CreateTable.append(sqltipename);
                  
                  ////////qDebug() << "### fieldname "  << name;
                  ///////////qDebug() << "### typeoffield "  << typeoffield;
              }
                  if (mkey.size() > 0) {
                  CreateTable.append(mkey);
                  }
                  
        QString midlecreate = CreateTable.join(",\n");
                midlecreate.prepend(QString("### mysql version 5 or > ###\nDROP TABLE IF EXISTS `%1`;\nCREATE TABLE `%1` (\n").arg(runningtable));
                midlecreate.append("\n) TYPE=MyISAM;");
        createtable = midlecreate;
   }
return createtable;
}
Example #15
0
void DataViewer::onDatabaseItemActivated(const DatabaseItem &item)
{
    if ((DatabaseItem::Table != item.m_type) &&
            (DatabaseItem::View != item.m_type))
    {
        return;
    }

    d_ptr->database = item.m_database;

    // for table tableShema
    QSqlRecord record = item.m_database.record(item.m_value);

    d_ptr->m_shemaModel->removeRows(0, d_ptr->m_shemaModel->rowCount());
    d_ptr->m_shemaModel->insertRows(0, record.count());

    for (int i = 0; i < record.count(); ++i)
    {
        QSqlField field = record.field(i);

        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 0), field.name());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 1),
                              field.type() == QVariant::Invalid ? "???" : QString(QVariant::typeToName(field.type())));
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 2),
                              (field.length() < 0) ? QVariant("???") : field.length());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 3),
                              (field.precision() < 0) ? QVariant("???") : field.precision());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 4),
                              field.requiredStatus() == QSqlField::Unknown ? "???" : QVariant(bool(field.requiredStatus())));
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 5), field.isAutoValue());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 6), field.defaultValue());
    }

    d_ptr->m_tableShema->setModel(d_ptr->m_shemaModel.data());
    d_ptr->m_tableShema->setEditTriggers(QAbstractItemView::NoEditTriggers);
    d_ptr->m_tableShema->resizeColumnsToContents();

    d_ptr->m_tab->setTabText(::Scheme, tr(::c_schemeTable).arg(item.m_value));

    // for table tableData
    QSqlTableModel *modelData = new QSqlTableModel(0, item.m_database);
    modelData->setEditStrategy(QSqlTableModel::OnRowChange);
    modelData->setTable(item.m_value);
    modelData->select();

    d_ptr->m_tableData->setModel(modelData);
    d_ptr->m_tableData->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
    d_ptr->m_tableData->resizeColumnsToContents();

    d_ptr->m_tab->setTabText(::Data, tr(::c_dataTable).arg(item.m_value));

    d_ptr->m_sqlDataModel.reset(modelData);
}
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());
}
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();
}
Example #18
0
	QString repr(QSqlRecord record) {
		QString record_str;
		QSqlField field;
		for(int i=0; i<record.count(); i++) {
			field = record.field(i);
			if (field.isNull())
				record_str.append(QString("%1 = NULL, ").arg(field.name()));
			else
				record_str.append(QString("%1 = %2, ").arg(field.name(), field.value().toString()));
		}
		return record_str;
	}
Example #19
0
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;
}
Example #20
0
QSqlRecord Query::record() const
{
	QSqlRecord ret = Super::record();
	for(int i=0; i<ret.count(); i++) {
		QSqlField fld = ret.field(i);
		QString n = QueryBuilder::unmangleLongFieldName(fld.name());
		if(n != fld.name()) {
			fld.setName(n);
			ret.replace(i, fld);
		}
	}
	return ret;
}
Example #21
0
int qtDatabase::populateTable(PARAM *p, int id)
{
  int x,y,xmax,ymax;
  
  if(db == NULL)
  {
    pvStatusMessage(p,255,0,0,"ERROR: qtDatabase::populateTable() db==NULL");
    return -1;
  }  

  // set table dimension
  xmax = result->record().count();
  //ymax = result->size();
  ymax = result->numRowsAffected();
  pvSetNumRows(p,id,ymax);
  pvSetNumCols(p,id,xmax);

  // populate table
  QSqlRecord record = result->record();
  if(record.isEmpty())
  {
    pvStatusMessage(p,255,0,0,"ERROR: qtDatabase::populateTable() record is empty");
    return -1;
  }

  for(x=0; x<xmax; x++)
  { // write name of fields
    pvSetTableText(p, id, x, -1, (const char *) record.fieldName(x).toUtf8());
  }
  result->next();
  for(y=0; y<ymax; y++)
  { // write fields
    QSqlRecord record = result->record();
    for(x=0; x<xmax; x++)
    {
      QSqlField f = record.field(x);
      if(f.isValid())
      {
        QVariant v = f.value();
        pvSetTableText(p, id, x, y, (const char *) v.toString().toUtf8());
      }
      else
      {
        pvSetTableText(p, id, x, y, "ERROR:");
      }
    }
    result->next();
  }

  return 0;
}
Example #22
0
/*!
    Updates the widgets in the form with current values from the SQL
    fields they are mapped to.
*/
void Q3SqlForm::readFields()
{
    sync();
    QSqlField * f;
    QMap< QWidget *, QSqlField * >::Iterator it;
    Q3SqlPropertyMap * pmap = (d->propertyMap == 0) ?
                             Q3SqlPropertyMap::defaultMap() : d->propertyMap;
    for(it = d->map.begin() ; it != d->map.end(); ++it){
        f = widgetToField(it.key());
        if(!f)
            continue;
        pmap->setProperty(it.key(), f->value());
    }
}
Example #23
0
/*!
    Returns an SQL \c{ORDER BY} clause based on the currently set
    sort order.

    \sa setSort(), selectStatement()
*/
QString QSqlTableModel::orderByClause() const
{
    Q_D(const QSqlTableModel);
    QSqlField f = d->rec.field(d->sortColumn);
    if (!f.isValid())
        return QString();

    //we can safely escape the field because it would have been obtained from the database
    //and have the correct case
    QString field = d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName);
    field.prepend(QLatin1Char('.')).prepend(d->tableName);
    field = d->sortOrder == Qt::AscendingOrder ? Sql::asc(field) : Sql::desc(field);
    return Sql::orderBy(field);
}
Example #24
0
/*!
    Returns an SQL \c{ORDER BY} clause based on the currently set
    sort order.

    \sa setSort(), selectStatement()
*/
QString QSqlTableModel::orderByClause() const
{
    Q_D(const QSqlTableModel);
    QString s;
    QSqlField f = d->rec.field(d->sortColumn);
    if (!f.isValid())
        return s;
        
    QString table = d->db.driver()->escapeIdentifier(d->tableName, QSqlDriver::TableName);
    QString field = d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName);
    s.append(QLatin1String("ORDER BY ")).append(table).append(QLatin1Char('.')).append(field);
    s += d->sortOrder == Qt::AscendingOrder ? QLatin1String(" ASC") : QLatin1String(" DESC");

    return s;
}
Example #25
0
QSqlRecord Query::record() const
{
	if(m_demangledRecord.isEmpty()) {
		m_demangledRecord = Super::record();
		for(int i=0; i<m_demangledRecord.count(); i++) {
			QSqlField fld = m_demangledRecord.field(i);
			QString n = QueryBuilder::unmangleLongFieldName(fld.name());
			if(n != fld.name()) {
				fld.setName(n);
				m_demangledRecord.replace(i, fld);
			}
		}
	}
	return m_demangledRecord;
}
QVariant SchemaModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid ()) {
        return QVariant ();
    }

    if (role == Qt::DisplayRole) {
        if (index.row () >= record.count ()) {
            return QVariant ();
        }

        QSqlField field = record.field(index.row());

        switch (index.column ()) {
        case 0:
            return field.name ();

        case 1:
            return QLatin1String (QVariant::typeToName(field.type()));

        case 2:
            return field.length ();

        case 3: {
            QStringList mods;

            if (pindex.indexOf (field.name ()) >= 0) {
                mods << tr("PRIMARY KEY");
            }

            if (field.requiredStatus () == QSqlField::Required) {
                mods << tr("NOT NULL");
            }
            else if (field.requiredStatus () == QSqlField::Optional) {
                mods << tr ("NULL");
            }

            if (field.isAutoValue ()) {
                mods << tr ("AUTO_INCREMENT");
            }

            return mods.join(", ");
        }

        case 4:
            return field.defaultValue ();
        }
    }
    else if (role == Qt::DecorationRole) {
    }

    return QVariant ();
}
Example #27
0
bool DatabaseDialog::tablesDoNext()
{
  m_databaseStatus->setText( i18n("Retrieving meta data of tables...") );
  QStringList tables;

  {
    Q3ListViewItem * item = (Q3CheckListItem *) m_tableView->firstChild();
    for (; item; item = item->nextSibling())
    {
      if (((Q3CheckListItem * ) item)->isOn())
      {
        tables.append(((Q3CheckListItem * ) item)->text());
      }
    }
  }

  if (tables.empty())
  {
    KMessageBox::error( this, i18n("You have to select at least one table.") );
    return false;
  }

  m_columnView->clear();
  QSqlRecord info;
  for (int i = 0; i < (int) tables.size(); ++i)
  {
    info = m_dbConnection.record( tables[i] );
    for (int j = 0; j < (int) info.count(); ++j)
    {
      QString name = info.fieldName(j);
      Q3CheckListItem * checkItem = new Q3CheckListItem( m_columnView, name,
                                 Q3CheckListItem::CheckBox );
      checkItem->setOn(false);
      m_columnView->insertItem( checkItem );
      checkItem->setText( 1, tables[i] );
      QSqlField field = info.field(name);
      checkItem->setText( 2, QVariant::typeToName(field.type()) );
    }
  }
  m_columnView->setSorting(1, true);
  m_columnView->sort();
  m_columnView->setSorting( -1 );

  setValid(m_columns, true);

  return true;
}
Example #28
0
/*!
    Returns an SQL \c{ORDER BY} clause based on the currently set
    sort order.

    \sa setSort(), selectStatement()
*/
QString QSqlTableModel::orderByClause() const
{
    Q_D(const QSqlTableModel);
    QString s;
    QSqlField f = d->rec.field(d->sortColumn);
    if (!f.isValid())
        return s;
        
    QString table = d->tableName;
    //we can safely escape the field because it would have been obtained from the database
    //and have the correct case
    QString field = d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName);
    s.append(QLatin1String("ORDER BY ")).append(table).append(QLatin1Char('.')).append(field);
    s += d->sortOrder == Qt::AscendingOrder ? QLatin1String(" ASC") : QLatin1String(" DESC");

    return s;
}
bool KalkatiParser::endElement(const QString &uri,const QString &local,const QString &name) {
	signed int i;

	if(name=="Synonym") {
		isSynonym=false;
	} else if(name=="Service") {
		if(servValid<0) return(true);

		QSqlQuery query(db);
		QSqlField nameField;
		QString sql,data,validOld,validNew;
		QTextStream str(&sql);
		nameField.setValue(servName);
		validNew=valid.value(servValid);
		data=servData.join(" ");

//qDebug() << servValid << valid.value(servValid) << valid.value(2);

		str << "SELECT servid,valid FROM servicedata WHERE first=" << servFirst;
		str << " AND long='" << servLong << "' AND data='" << data << "' AND compid=" << servComp;
		str << " AND name='" << driver->formatValue(nameField,true) << "';";

		query.exec(sql);
		query.first();
		if(query.isValid()) {
			QSqlRecord record=query.record();
			servId=record.value(0).toInt();
			validOld=record.value(1).toString();
			for(i=0;i<dayCount;i++) {
				if(validOld[i]=='1') validNew[i]='1';
			}
			sql="";
			str << "UPDATE servicedata SET valid='" << validNew << "' WHERE servid=" << servId << ";";
			query.exec(sql);
		} else {
			sql="";
			str << "INSERT INTO servicedata (servid,mode,first,compid,long,short,name,valid,data) VALUES (" << servId << "," << servMode << "," << servFirst << "," << servComp;
			str << ",'" << servLong << "','" << servShort << "','";
			str << driver->formatValue(nameField,true) << "','" << validNew << "','" << data << "');";
			query.exec(sql);
		}
	}

	return(true);
}
Example #30
0
QSqlRecord QPSQLResult::record() const
{
    QSqlRecord info;
    if (!isActive() || !isSelect())
        return info;

    int count = PQnfields(d->result);
    for (int i = 0; i < count; ++i) {
        QSqlField f;
        if (d->driver->isUtf8)
            f.setName(QString::fromUtf8(PQfname(d->result, i)));
        else
            f.setName(QString::fromLocal8Bit(PQfname(d->result, i)));
        f.setType(qDecodePSQLType(PQftype(d->result, i)));
        int len = PQfsize(d->result, i);
        int precision = PQfmod(d->result, i);
        // swap length and precision if length == -1
        if (len == -1 && precision > -1) {
            len = precision - 4;
            precision = -1;
        }
        f.setLength(len);
        f.setPrecision(precision);
        f.setSqlType(PQftype(d->result, i));
        info.append(f);
    }
    return info;
}