11
11
#include "ogr_fdw_gdal.h"
12
12
#include "ogr_fdw_common.h"
13
13
#include "stringbuffer.h"
14
+ #include "pg_config_manual.h"
14
15
15
16
/* Prototype for function that must be defined in PostgreSQL (it is) */
16
17
/* and in ogr_fdw_info (it is) */
52
53
ogrStringLaunder (char * str )
53
54
{
54
55
int i , j = 0 ;
55
- char tmp [STR_MAX_LEN ];
56
- memset (tmp , 0 , STR_MAX_LEN );
56
+ char tmp [NAMEDATALEN ];
57
+ memset (tmp , 0 , NAMEDATALEN );
57
58
58
59
for (i = 0 ; str [i ]; i ++ )
59
60
{
@@ -79,10 +80,10 @@ ogrStringLaunder(char *str)
79
80
tmp [j ++ ] = c ;
80
81
81
82
/* Avoid mucking with data beyond the end of our stack-allocated strings */
82
- if ( j >= STR_MAX_LEN )
83
- j = STR_MAX_LEN - 1 ;
83
+ if ( j >= NAMEDATALEN - 1 )
84
+ break ;
84
85
}
85
- strncpy (str , tmp , STR_MAX_LEN );
86
+ strncpy (str , tmp , NAMEDATALEN );
86
87
87
88
}
88
89
@@ -220,10 +221,11 @@ ogrGeomTypeToPgGeomType(stringbuffer_t *buf, OGRwkbGeometryType gtype)
220
221
static OGRErr
221
222
ogrColumnNameToSQL (const char * ogrcolname , const char * pgtype , int launder_column_names , stringbuffer_t * buf )
222
223
{
223
- char pgcolname [STR_MAX_LEN ];
224
- strncpy (pgcolname , ogrcolname , STR_MAX_LEN );
224
+ char pgcolname [NAMEDATALEN ];
225
+ strncpy (pgcolname , ogrcolname , NAMEDATALEN );
225
226
ogrStringLaunder (pgcolname );
226
227
228
+
227
229
if ( launder_column_names )
228
230
{
229
231
stringbuffer_aprintf (buf , ",\n %s %s" , quote_identifier (pgcolname ), pgtype );
@@ -250,10 +252,11 @@ ogrColumnNameToSQL (const char *ogrcolname, const char *pgtype, int launder_colu
250
252
OGRErr
251
253
ogrLayerToSQL (const OGRLayerH ogr_lyr , const char * fdw_server ,
252
254
int launder_table_names , int launder_column_names ,
255
+ const char * fdw_table_name ,
253
256
int use_postgis_geometry , stringbuffer_t * buf )
254
257
{
255
258
int geom_field_count , i ;
256
- char table_name [STR_MAX_LEN ];
259
+ char table_name [NAMEDATALEN ];
257
260
OGRFeatureDefnH ogr_fd = OGR_L_GetLayerDefn (ogr_lyr );
258
261
stringbuffer_t gbuf ;
259
262
@@ -272,9 +275,15 @@ ogrLayerToSQL (const OGRLayerH ogr_lyr, const char *fdw_server,
272
275
#endif
273
276
274
277
/* Process table name */
275
- strncpy (table_name , OGR_L_GetName (ogr_lyr ), STR_MAX_LEN );
276
- if (launder_table_names )
277
- ogrStringLaunder (table_name );
278
+ if (fdw_table_name == NULL ) {
279
+ strncpy (table_name , OGR_L_GetName (ogr_lyr ), NAMEDATALEN );
280
+
281
+ if (launder_table_names )
282
+ ogrStringLaunder (table_name );
283
+ }
284
+ else {
285
+ strncpy (table_name , fdw_table_name , NAMEDATALEN );
286
+ }
278
287
279
288
/* Create table */
280
289
stringbuffer_aprintf (buf , "CREATE FOREIGN TABLE %s (\n" , quote_identifier (table_name ));
@@ -361,17 +370,17 @@ ogrLayerToSQL (const OGRLayerH ogr_lyr, const char *fdw_server,
361
370
/* Write out attribute fields */
362
371
for ( i = 0 ; i < OGR_FD_GetFieldCount (ogr_fd ); i ++ )
363
372
{
364
- char pgtype [128 ];
373
+ char pgtype [NAMEDATALEN ];
365
374
OGRFieldDefnH ogr_fld = OGR_FD_GetFieldDefn (ogr_fd , i );
366
- ogrTypeToPgType (ogr_fld , pgtype , 128 );
375
+ ogrTypeToPgType (ogr_fld , pgtype , sizeof ( pgtype ) );
367
376
ogrColumnNameToSQL (OGR_Fld_GetNameRef (ogr_fld ), pgtype , launder_column_names , buf );
368
377
}
369
378
370
379
/*
371
380
* Add server name and layer-level options. We specify remote
372
381
* layer name as option
373
382
*/
374
- stringbuffer_aprintf (buf , "\n) SERVER %s \nOPTIONS (" , quote_identifier (fdw_server ));
383
+ stringbuffer_aprintf (buf , "\n) SERVER %s\nOPTIONS (" , quote_identifier (fdw_server ));
375
384
stringbuffer_append (buf , "layer " );
376
385
ogrDeparseStringLiteral (buf , OGR_L_GetName (ogr_lyr ));
377
386
stringbuffer_append (buf , ");\n" );
0 commit comments