@@ -229,20 +229,31 @@ def gdalHelpPath():
229
229
230
230
@staticmethod
231
231
def ogrConnectionString (uri , context ):
232
- """Generates OGR connection sting from layer source
232
+ """Generates OGR connection string from layer source
233
+ """
234
+ return GdalUtils .ogrConnectionStringAndFormat (uri , context )[0 ]
235
+
236
+ @staticmethod
237
+ def ogrConnectionStringAndFormat (uri , context ):
238
+ """Generates OGR connection string and format string from layer source
239
+ Returned values are a tuple of the connection string and format string
233
240
"""
234
241
ogrstr = None
242
+ format = None
235
243
236
244
layer = QgsProcessingUtils .mapLayerFromString (uri , context , False )
237
245
if layer is None :
238
- return '"' + uri + '"'
246
+ path , ext = os .path .splitext (uri )
247
+ format = QgsVectorFileWriter .driverForExtension (ext )
248
+ return '"' + uri + '"' , format
239
249
240
250
provider = layer .dataProvider ().name ()
241
251
if provider == 'spatialite' :
242
252
# dbname='/geodata/osm_ch.sqlite' table="places" (Geometry) sql=
243
253
regex = re .compile ("dbname='(.+)'" )
244
254
r = regex .search (str (layer .source ()))
245
255
ogrstr = r .groups ()[0 ]
256
+ format = 'SQLite'
246
257
elif provider == 'postgres' :
247
258
# dbname='ktryjh_iuuqef' host=spacialdb.com port=9999
248
259
# user='ktryjh_iuuqef' password='xyqwer' sslmode=disable
@@ -270,6 +281,7 @@ def ogrConnectionString(uri, context):
270
281
QgsCredentials .instance ().put (conninfo , user , passwd )
271
282
272
283
ogrstr = "PG:%s" % dsUri .connectionInfo ()
284
+ format = 'PostgreSQL'
273
285
elif provider == "oracle" :
274
286
# OCI:user/password@host:port/service:table
275
287
dsUri = QgsDataSourceUri (layer .dataProvider ().dataSourceUri ())
@@ -299,10 +311,13 @@ def ogrConnectionString(uri, context):
299
311
ogrstr += dsUri .schema () + "."
300
312
301
313
ogrstr += dsUri .table ()
314
+ format = 'OCI'
302
315
else :
303
316
ogrstr = str (layer .source ()).split ("|" )[0 ]
317
+ path , ext = os .path .splitext (ogrstr )
318
+ format = QgsVectorFileWriter .driverForExtension (ext )
304
319
305
- return '"' + ogrstr + '"'
320
+ return '"' + ogrstr + '"' , format
306
321
307
322
@staticmethod
308
323
def ogrLayerName (uri ):
0 commit comments