@@ -153,19 +153,35 @@ def defineCharacteristics(self):
153
153
self .addParameter (ParameterString (self .OPTIONS ,
154
154
self .tr ('Additional creation options' ), '' , optional = True ))
155
155
156
+ def getConnectionString (self ):
157
+ host = self .getParameterValue (self .HOST )
158
+ port = self .getParameterValue (self .PORT )
159
+ user = self .getParameterValue (self .USER )
160
+ dbname = self .getParameterValue (self .DBNAME )
161
+ password = self .getParameterValue (self .PASSWORD )
162
+ schema = self .getParameterValue (self .SCHEMA )
163
+ arguments = []
164
+ if host :
165
+ arguments .append ('host=' + host )
166
+ if port :
167
+ arguments .append ('port=' + str (port ))
168
+ if dbname :
169
+ arguments .append ('dbname=' + dbname )
170
+ if password :
171
+ arguments .append ('password=' + password )
172
+ if schema :
173
+ arguments .append ('active_schema=' + schema )
174
+ if user :
175
+ arguments .append ('user=' + user )
176
+ return GdalUtils .escapeAndJoin (arguments )
177
+
156
178
def getConsoleCommands (self ):
157
179
inLayer = self .getParameterValue (self .INPUT_LAYER )
158
180
ogrLayer = ogrConnectionString (inLayer )[1 :- 1 ]
159
181
shapeEncoding = self .getParameterValue (self .SHAPE_ENCODING )
160
182
ssrs = unicode (self .getParameterValue (self .S_SRS ))
161
183
tsrs = unicode (self .getParameterValue (self .T_SRS ))
162
184
asrs = unicode (self .getParameterValue (self .A_SRS ))
163
- host = unicode (self .getParameterValue (self .HOST ))
164
- port = unicode (self .getParameterValue (self .PORT ))
165
- user = unicode (self .getParameterValue (self .USER ))
166
- dbname = unicode (self .getParameterValue (self .DBNAME ))
167
- password = unicode (self .getParameterValue (self .PASSWORD ))
168
- schema = unicode (self .getParameterValue (self .SCHEMA ))
169
185
table = unicode (self .getParameterValue (self .TABLE ))
170
186
pk = unicode (self .getParameterValue (self .PK ))
171
187
pkstring = "-lco FID=" + pk
@@ -202,17 +218,9 @@ def getConsoleCommands(self):
202
218
arguments .append ('"' + shapeEncoding + '"' )
203
219
arguments .append ('-f' )
204
220
arguments .append ('PostgreSQL' )
205
- arguments .append ('PG:"host=' + host )
206
- arguments .append ('port=' + port )
207
- if len (dbname ) > 0 :
208
- arguments .append ('dbname=' + dbname )
209
- if len (password ) > 0 :
210
- arguments .append ('password=' + password )
211
- if len (schema ) > 0 :
212
- arguments .append ('active_schema=' + schema )
213
- else :
214
- arguments .append ('active_schema=public' )
215
- arguments .append ('user=' + user + '"' )
221
+ arguments .append ('PG:"' )
222
+ arguments .append (self .getConsoleCommands ())
223
+ arguments .append ('"' )
216
224
arguments .append (dimstring )
217
225
arguments .append (ogrLayer )
218
226
arguments .append (ogrLayerName (inLayer ))
0 commit comments