@@ -1169,7 +1169,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
1169
1169
1170
1170
try
1171
1171
{
1172
- QSqlQuery qry ( db );
1172
+ QSqlQuery ins ( db ), getfid ( db );
1173
1173
1174
1174
if ( !db.transaction () )
1175
1175
{
@@ -1193,14 +1193,24 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
1193
1193
1194
1194
if ( mPrimaryKeyType == pktInt || mPrimaryKeyType == pktFidMap )
1195
1195
{
1196
+ QString keys, kdelim = " " ;
1197
+
1196
1198
foreach ( int idx, mPrimaryKeyAttrs )
1197
1199
{
1198
- insert += delim + quotedIdentifier ( field ( idx ).name () );
1200
+ const QgsField &fld = field ( idx );
1201
+ insert += delim + quotedIdentifier ( fld.name () );
1202
+ keys += kdelim + quotedIdentifier ( fld.name () );
1199
1203
values += delim + " ?" ;
1200
1204
delim = " ," ;
1205
+ kdelim = " ," ;
1201
1206
fieldId << idx;
1202
1207
defaultValues << defaultValue ( idx ).toString ();
1203
1208
}
1209
+
1210
+ if ( !getfid.prepare ( QString ( " SELECT %1 FROM %2 WHERE ROWID=?" ).arg ( keys ).arg ( mQuery ) ) )
1211
+ {
1212
+ throw OracleException ( tr ( " Could not prepare get feature id statement" ), getfid );
1213
+ }
1204
1214
}
1205
1215
1206
1216
QgsAttributes attributevec = flist[0 ].attributes ();
@@ -1276,9 +1286,9 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
1276
1286
insert += values + " )" ;
1277
1287
1278
1288
QgsDebugMsgLevel ( QString ( " SQL prepare: %1" ).arg ( insert ), 4 );
1279
- if ( !qry .prepare ( insert ) )
1289
+ if ( !ins .prepare ( insert ) )
1280
1290
{
1281
- throw OracleException ( tr ( " Could not prepare insert statement" ), qry );
1291
+ throw OracleException ( tr ( " Could not prepare insert statement" ), ins );
1282
1292
}
1283
1293
1284
1294
for ( QgsFeatureList::iterator features = flist.begin (); features != flist.end (); ++features )
@@ -1289,7 +1299,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
1289
1299
1290
1300
if ( !mGeometryColumn .isNull () )
1291
1301
{
1292
- appendGeomParam ( features->geometry (), qry );
1302
+ appendGeomParam ( features->geometry (), ins );
1293
1303
}
1294
1304
1295
1305
for ( int i = 0 ; i < fieldId.size (); i++ )
@@ -1315,20 +1325,37 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
1315
1325
}
1316
1326
1317
1327
QgsDebugMsgLevel ( QString ( " addBindValue: %1" ).arg ( v ), 4 );
1318
- qry .addBindValue ( v );
1328
+ ins .addBindValue ( v );
1319
1329
}
1320
1330
1321
- if ( !qry .exec () )
1322
- throw OracleException ( tr ( " Could not insert feature %1" ).arg ( features->id () ), qry );
1331
+ if ( !ins .exec () )
1332
+ throw OracleException ( tr ( " Could not insert feature %1" ).arg ( features->id () ), ins );
1323
1333
1324
1334
if ( mPrimaryKeyType == pktRowId )
1325
1335
{
1326
- features->setFeatureId ( mShared ->lookupFid ( QList<QVariant>() << QVariant ( qry .lastInsertId () ) ) );
1336
+ features->setFeatureId ( mShared ->lookupFid ( QList<QVariant>() << QVariant ( ins .lastInsertId () ) ) );
1327
1337
QgsDebugMsgLevel ( QString ( " new fid=%1" ).arg ( features->id () ), 4 );
1328
1338
}
1339
+ else if ( mPrimaryKeyType == pktInt || mPrimaryKeyType == pktFidMap )
1340
+ {
1341
+ getfid.addBindValue ( QVariant ( ins.lastInsertId () ) );
1342
+ if ( !getfid.exec () || !getfid.next () )
1343
+ throw OracleException ( tr ( " Could not retrieve feature id %1" ).arg ( features->id () ), getfid );
1344
+
1345
+ int col = 0 ;
1346
+ foreach ( int idx, mPrimaryKeyAttrs )
1347
+ {
1348
+ const QgsField &fld = field ( idx );
1349
+
1350
+ QVariant v = getfid.value ( col++ );
1351
+ if ( v.type () != fld.type () )
1352
+ v = QgsVectorDataProvider::convertValue ( fld.type (), v.toString () );
1353
+ features->setAttribute ( idx, v );
1354
+ }
1355
+ }
1329
1356
}
1330
1357
1331
- qry .finish ();
1358
+ ins .finish ();
1332
1359
1333
1360
if ( !db.commit () )
1334
1361
{
0 commit comments