PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ShpLoaderGetSQLCopyStatement()

int ShpLoaderGetSQLCopyStatement ( SHPLOADERSTATE state,
char **  strheader 
)

if we need to transform we copy into temp table instead of main table first

Definition at line 1488 of file shp2pgsql-core.c.

1489 {
1490  //char *copystr;
1491  stringbuffer_t *sb;
1492  char *ret;
1493  sb = stringbuffer_create();
1494  stringbuffer_clear(sb);
1495 
1496 
1497  /* Allocate the string for the COPY statement */
1498  if (state->config->dump_format)
1499  {
1500  stringbuffer_aprintf(sb, "COPY ");
1501 
1502  if (state->to_srid != state->from_srid){
1504  stringbuffer_aprintf(sb, " \"pgis_tmp_%s\" (%s) FROM stdin;\n", state->config->table, state->col_names);
1505  }
1506  else {
1507  if (state->config->schema)
1508  {
1509  stringbuffer_aprintf(sb, " \"%s\".", state->config->schema);
1510  }
1511 
1512  stringbuffer_aprintf(sb, "\"%s\" (%s) FROM stdin;\n", state->config->table, state->col_names);
1513  }
1514 
1515  /* Copy the string buffer into a new string, destroying the string buffer */
1516  ret = (char *)malloc(strlen((char *)stringbuffer_getstring(sb)) + 1);
1517  strcpy(ret, (char *)stringbuffer_getstring(sb));
1519 
1520  *strheader = ret;
1521  return SHPLOADEROK;
1522  }
1523  else
1524  {
1525  /* Flag an error as something has gone horribly wrong */
1526  snprintf(state->message, SHPLOADERMSGLEN, _("Internal error: attempt to generate a COPY statement for data that hasn't been requested in COPY format"));
1527 
1528  return SHPLOADERERR;
1529  }
1530 }
void * malloc(YYSIZE_T)
#define SHPLOADERMSGLEN
#define SHPLOADERERR
#define SHPLOADEROK
#define _(String)
Definition: shpcommon.h:24
void stringbuffer_clear(stringbuffer_t *s)
Reset the stringbuffer_t.
Definition: stringbuffer.c:97
int stringbuffer_aprintf(stringbuffer_t *s, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided.
Definition: stringbuffer.c:247
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
Definition: stringbuffer.c:33
void stringbuffer_destroy(stringbuffer_t *s)
Free the stringbuffer_t and all memory managed within it.
Definition: stringbuffer.c:85
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
Definition: stringbuffer.c:122
char message[SHPLOADERMSGLEN]
SHPLOADERCONFIG * config

References _, shp_loader_state::col_names, shp_loader_state::config, shp_loader_config::dump_format, shp_loader_state::from_srid, malloc(), shp_loader_state::message, shp_loader_config::schema, SHPLOADERERR, SHPLOADERMSGLEN, SHPLOADEROK, stringbuffer_aprintf(), stringbuffer_clear(), stringbuffer_create(), stringbuffer_destroy(), stringbuffer_getstring(), shp_loader_config::table, and shp_loader_state::to_srid.

Referenced by pgui_action_import().

Here is the call graph for this function:
Here is the caller graph for this function: