6 changes: 6 additions & 0 deletions src/app/qgsfieldcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ void QgsFieldCalculator::accept()
break;
}
}

if ( ! exp.prepare( mVectorLayer->pendingFields() ) )
{
QMessageBox::critical( 0, tr( "Evaluation error" ), exp.evalErrorString() );
return;
}
}

if ( mAttributeId == -1 )
Expand Down
16 changes: 9 additions & 7 deletions src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ void QgsFieldsProperties::loadRows()

void QgsFieldsProperties::setRow( int row, int idx, const QgsField &field )
{
QTableWidgetItem* dataItem = new QTableWidgetItem( idx );
QTableWidgetItem* dataItem = new QTableWidgetItem();
dataItem->setData( Qt::DisplayRole, idx );
DesignerTreeItemData itemData( DesignerTreeItemData::Field, field.name() );
dataItem->setData( DesignerTreeRole, itemData.asQVariant() );
mFieldsList->setItem( row, attrIdCol, dataItem );
Expand Down Expand Up @@ -498,19 +499,20 @@ void QgsFieldsProperties::attributeTypeDialog()
void QgsFieldsProperties::attributeAdded( int idx )
{
bool sorted = mFieldsList->isSortingEnabled();
mFieldsList->setSortingEnabled( false );
if ( sorted )
mFieldsList->setSortingEnabled( false );

const QgsFields &fields = mLayer->pendingFields();
int row = mFieldsList->rowCount();
mFieldsList->insertRow( row );
setRow( row, idx, fields[idx] );
mFieldsList->setCurrentCell( row, idx );

for ( int i = idx; i < mIndexedWidgets.count(); i++ )
{
for ( int i = idx + 1; i < mIndexedWidgets.count(); i++ )
mIndexedWidgets[i]->setData( Qt::DisplayRole, i );
}

mFieldsList->setCurrentCell( row, idx );
mFieldsList->setSortingEnabled( sorted );
if ( sorted )
mFieldsList->setSortingEnabled( true );
}


Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsvectorlayerundocommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ QgsVectorLayerUndoCommandAddAttribute::QgsVectorLayerUndoCommandAddAttribute( Qg
: QgsVectorLayerUndoCommand( buffer )
, mField( field )
{
mFieldIndex = layer()->pendingFields().count();
const QgsFields &fields = layer()->pendingFields();
int i;
for ( i = 0; i < fields.count() && fields.fieldOrigin( i ) != QgsFields::OriginJoin; i++ )
;
mFieldIndex = i;
}

void QgsVectorLayerUndoCommandAddAttribute::undo()
Expand Down
53 changes: 41 additions & 12 deletions src/providers/oracle/qgsoracleconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <QSettings>
#include <QSqlError>
#include <QDateTime>

QMap<QString, QgsOracleConn *> QgsOracleConn::sConnections;
int QgsOracleConn::snConnections = 0;
Expand Down Expand Up @@ -257,25 +258,53 @@ QString QgsOracleConn::quotedIdentifier( QString ident )
return ident;
}

QString QgsOracleConn::quotedValue( QVariant value )
QString QgsOracleConn::quotedValue( const QVariant &value, QVariant::Type type )
{
if ( value.isNull() )
return "NULL";

switch ( value.type() )
if ( type == QVariant::Invalid )
type = value.type();

if ( value.canConvert( type ) )
{
case QVariant::Int:
case QVariant::LongLong:
case QVariant::Double:
return value.toString();
switch ( type )
{
case QVariant::Int:
case QVariant::LongLong:
case QVariant::Double:
return value.toString();

case QVariant::DateTime:
{
QDateTime datetime( value.toDateTime() );
if ( datetime.isValid() )
return QString( "TO_DATE('%1','YYYY-MM-DD HH24:MI:SS')" ).arg( datetime.toString( "yyyy-MM-dd hh:mm:ss" ) );
break;
}

case QVariant::Date:
{
QDate date( value.toDate() );
if ( date.isValid() )
return QString( "TO_DATE('%1','YYYY-MM-DD')" ).arg( date.toString( "yyyy-MM-dd" ) );
break;
}

default:
case QVariant::String:
QString v = value.toString();
v.replace( "'", "''" );
v.replace( "\\\"", "\\\\\"" );
return v.prepend( "'" ).append( "'" );
case QVariant::Time:
{
QDateTime datetime( value.toDateTime() );
if ( datetime.isValid() )
return QString( "TO_DATE('%1','HH24:MI:SS')" ).arg( datetime.toString( "hh:mm:ss" ) );
break;
}
}
}

QString v = value.toString();
v.replace( "'", "''" );
v.replace( "\\\"", "\\\\\"" );
return v.prepend( "'" ).append( "'" );
}

QString QgsOracleConn::fieldExpression( const QgsField &fld )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/oracle/qgsoracleconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class QgsOracleConn : public QThread

/** Quote a value for placement in a SQL string.
*/
static QString quotedValue( QVariant value );
static QString quotedValue( const QVariant &value, QVariant::Type type = QVariant::Invalid );

//! Get the list of supported layers
bool supportedLayers( QVector<QgsOracleLayerProperty> &layers,
Expand Down
8 changes: 6 additions & 2 deletions src/providers/oracle/qgsoraclefeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
{
const QgsField &fld = P->field( idx );

QVariant v = P->convertValue( fld.type(), mQry.value( col ).toString() );
QVariant v = mQry.value( col );
if ( v.type() != fld.type() )
v = P->convertValue( fld.type(), v.toString() );
primaryKeyVals << v;

if ( mAttributeList.contains( idx ) )
Expand Down Expand Up @@ -219,7 +221,9 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )

const QgsField &fld = P->field( idx );

QVariant v = P->convertValue( fld.type(), mQry.value( col ).toString() );
QVariant v = mQry.value( col );
if ( v.type() != fld.type() )
v = P->convertValue( fld.type(), v.toString() );
feature.setAttribute( idx, v );

col++;
Expand Down
17 changes: 8 additions & 9 deletions src/providers/oracle/qgsoracleprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ QString QgsOracleProvider::whereClause( QgsFeatureId featureId ) const
int idx = mPrimaryKeyAttrs[i];
const QgsField &fld = field( idx );

whereClause += delim + QString( "%1=%2" ).arg( mConnection->fieldExpression( fld ) ).arg( quotedValue( pkVals[i].toString() ) );
whereClause += delim + QString( "%1=%2" ).arg( mConnection->fieldExpression( fld ) ).arg( quotedValue( pkVals[i], fld.type() ) );
delim = " AND ";
}
}
Expand Down Expand Up @@ -1222,12 +1222,11 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
if ( fieldId.contains( idx ) )
continue;

QString fieldname = mAttributeFields[idx].name();
QString fieldTypeName = mAttributeFields[idx].typeName();
const QgsField &fld = mAttributeFields[idx];

QgsDebugMsg( "Checking field against: " + fieldname );
QgsDebugMsg( "Checking field against: " + fld.name() );

if ( fieldname.isEmpty() || fieldname == mGeometryColumn )
if ( fld.name().isEmpty() || fld.name() == mGeometryColumn )
continue;

int i;
Expand All @@ -1243,7 +1242,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
break;
}

insert += delim + quotedIdentifier( fieldname );
insert += delim + quotedIdentifier( fld.name() );

QString defVal = defaultValue( idx ).toString();

Expand All @@ -1260,13 +1259,13 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
values += delim + defVal;
}
}
else if ( fieldTypeName == "MDSYS.SDO_GEOMETRY" )
else if ( fld.typeName() == "MDSYS.SDO_GEOMETRY" )
{
values += delim + "?";
}
else
{
values += delim + quotedValue( v.toString() );
values += delim + quotedValue( v, mAttributeFields[idx].type() );
}
}
else
Expand Down Expand Up @@ -1620,7 +1619,7 @@ bool QgsOracleProvider::changeAttributeValues( const QgsChangedAttributesMap & a
}
else
{
sql += quotedValue( siter->toString() );
sql += quotedValue( *siter, fld.type() );
}
}
catch ( OracleFieldNotFound )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/oracle/qgsoracleprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class QgsOracleProvider : public QgsVectorDataProvider
void disconnectDb();

static QString quotedIdentifier( QString ident ) { return QgsOracleConn::quotedIdentifier( ident ); }
static QString quotedValue( QVariant value ) { return QgsOracleConn::quotedValue( value ); }
static QString quotedValue( const QVariant &value, QVariant::Type type = QVariant::Invalid ) { return QgsOracleConn::quotedValue( value, type ); }

QgsFeatureId lookupFid( const QVariant &v ); //! lookup existing mapping or add a new one

Expand Down