PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ShpLoaderGetSQLFooter()

int ShpLoaderGetSQLFooter ( SHPLOADERSTATE state,
char **  strfooter 
)

We need to copy from the temp table to the real table, transforming to to_srid

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

1875 {
1876  stringbuffer_t *sb;
1877  char *ret;
1878 
1879  /* Create the stringbuffer containing the header; we use this API as it's easier
1880  for handling string resizing during append */
1881  sb = stringbuffer_create();
1882  stringbuffer_clear(sb);
1883 
1884  if ( state->config->dump_format && state->to_srid != state->from_srid){
1886  stringbuffer_aprintf(sb, "ALTER TABLE \"pgis_tmp_%s\" ALTER COLUMN \"%s\" TYPE ", state->config->table, state->geo_col);
1887  if (state->config->geography){
1888  stringbuffer_aprintf(sb, "geography USING (ST_Transform(\"%s\", %d)::geography );\n", state->geo_col, state->to_srid);
1889  }
1890  else {
1891  stringbuffer_aprintf(sb, "geometry USING (ST_Transform(\"%s\", %d)::geometry );\n", state->geo_col, state->to_srid);
1892  }
1893  stringbuffer_aprintf(sb, "INSERT INTO ");
1894  // /* Schema is optional, include if present. */
1895  if (state->config->schema)
1896  {
1897  stringbuffer_aprintf(sb, "\"%s\".", state->config->schema);
1898  }
1899  stringbuffer_aprintf(sb, "\"%s\" (%s) ", state->config->table, state->col_names);
1900  stringbuffer_aprintf(sb, "SELECT %s FROM \"pgis_tmp_%s\";\n", state->col_names, state->config->table);
1901  }
1902 
1903  /* Create gist index if specified and not in "prepare" mode */
1904  if (state->config->readshape && state->config->createindex)
1905  {
1906  stringbuffer_aprintf(sb, "CREATE INDEX ON ");
1907  /* Schema is optional, include if present. */
1908  if (state->config->schema)
1909  {
1910  stringbuffer_aprintf(sb, "\"%s\".",state->config->schema);
1911  }
1912  stringbuffer_aprintf(sb, "\"%s\" USING GIST (\"%s\")", state->config->table, state->geo_col);
1913  /* Tablespace is also optional. */
1914  if (state->config->idxtablespace != NULL)
1915  {
1916  stringbuffer_aprintf(sb, " TABLESPACE \"%s\"", state->config->idxtablespace);
1917  }
1918  stringbuffer_aprintf(sb, ";\n");
1919  }
1920 
1921  /* End the transaction if there is one. */
1922  if (state->config->usetransaction)
1923  {
1924  stringbuffer_aprintf(sb, "COMMIT;\n");
1925  }
1926 
1927 
1928  if(state->config->analyze)
1929  {
1930  /* Always ANALYZE the resulting table, for better stats */
1931  stringbuffer_aprintf(sb, "ANALYZE ");
1932  if (state->config->schema)
1933  {
1934  stringbuffer_aprintf(sb, "\"%s\".", state->config->schema);
1935  }
1936  stringbuffer_aprintf(sb, "\"%s\";\n", state->config->table);
1937  }
1938 
1939  /* Copy the string buffer into a new string, destroying the string buffer */
1940  ret = (char *)malloc(strlen((char *)stringbuffer_getstring(sb)) + 1);
1941  strcpy(ret, (char *)stringbuffer_getstring(sb));
1943 
1944  *strfooter = ret;
1945 
1946  return SHPLOADEROK;
1947 }
void * malloc(YYSIZE_T)
#define SHPLOADEROK
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
SHPLOADERCONFIG * config

References shp_loader_config::analyze, shp_loader_state::col_names, shp_loader_state::config, shp_loader_config::createindex, shp_loader_config::dump_format, shp_loader_state::from_srid, shp_loader_state::geo_col, shp_loader_config::geography, shp_loader_config::idxtablespace, malloc(), shp_loader_config::readshape, shp_loader_config::schema, SHPLOADEROK, stringbuffer_aprintf(), stringbuffer_clear(), stringbuffer_create(), stringbuffer_destroy(), stringbuffer_getstring(), shp_loader_config::table, shp_loader_state::to_srid, and shp_loader_config::usetransaction.

Referenced by pgui_action_import().

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