def get_ogr_db_string():
 db = connections.databases['default']
 drivers = {'django.contrib.gis.db.backends.postgis': ('PostgreSQL', "PG:dbname='%(db_name)s'", ' '), 'django.contrib.gis.db.backends.mysql': ('MySQL', 'MYSQL:"%(db_name)s"', ','), 'django.contrib.gis.db.backends.spatialite': ('SQLite', '%(db_name)s', '')}
 (drv_name, db_str, param_sep) = drivers[db['ENGINE']]
 try:
  Driver(drv_name)
 except:
  return None
 if (db['NAME'] == ':memory:'):
  return None
 params = [(db_str % {'db_name': db['NAME']})]
 def add(key, template):
  value = db.get(key, None)
  if value:
   params.append((template % value))
 add('HOST', "host='%s'")
 add('PORT', "port='%s'")
 add('USER', "user='%s'")
 add('PASSWORD', "password='%s'")
 return param_sep.join(params)

def get_ogr_db_string ( ) : db = connections . databases [ 'default' ] drivers = { 'django.contrib.gis.db.backends.postgis' : ( 'PostgreSQL' , "PG:dbname='%(db_name)s'" , ' ' ) , 'django.contrib.gis.db.backends.mysql' : ( 'MySQL' , 'MYSQL:"%(db_name)s"' , ',' ) , 'django.contrib.gis.db.backends.spatialite' : ( 'SQLite' , '%(db_name)s' , '' ) } ( drv_name , db_str , param_sep ) = drivers [ db [ 'ENGINE' ] ] try : Driver ( drv_name ) except : return None if ( db [ 'NAME' ] == ':memory:' ) : return None params = [ ( db_str % { 'db_name' : db [ 'NAME' ] } ) ] def add ( key , template ) : value = db . get ( key , None ) if value : params . append ( ( template % value ) ) add ( 'HOST' , "host='%s'" ) add ( 'PORT' , "port='%s'" ) add ( 'USER' , "user='%s'" ) add ( 'PASSWORD' , "password='%s'" ) return param_sep . join ( params )
construct the db string that gdal will use to inspect the database .