PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ ShpLoaderGetSQLFooter()

int ShpLoaderGetSQLFooter ( SHPLOADERSTATE state,
char **  strfooter 
)

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

References shp_loader_state::config, shp_loader_config::createindex, shp_loader_state::geo_col, 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, and shp_loader_config::usetransaction.

Referenced by main(), and pgui_action_import().

1823 {
1824  stringbuffer_t *sb;
1825  char *ret;
1826 
1827  /* Create the stringbuffer containing the header; we use this API as it's easier
1828  for handling string resizing during append */
1829  sb = stringbuffer_create();
1830  stringbuffer_clear(sb);
1831 
1832  /* Create gist index if specified and not in "prepare" mode */
1833  if (state->config->readshape && state->config->createindex)
1834  {
1835  stringbuffer_aprintf(sb, "CREATE INDEX ON ");
1836  /* Schema is optional, include if present. */
1837  if (state->config->schema)
1838  {
1839  stringbuffer_aprintf(sb, "\"%s\".",state->config->schema);
1840  }
1841  stringbuffer_aprintf(sb, "\"%s\" USING GIST (\"%s\")", state->config->table, state->geo_col);
1842  /* Tablespace is also optional. */
1843  if (state->config->idxtablespace != NULL)
1844  {
1845  stringbuffer_aprintf(sb, " TABLESPACE \"%s\"", state->config->idxtablespace);
1846  }
1847  stringbuffer_aprintf(sb, ";\n");
1848  }
1849 
1850  /* End the transaction if there is one. */
1851  if (state->config->usetransaction)
1852  {
1853  stringbuffer_aprintf(sb, "COMMIT;\n");
1854  }
1855 
1856  /* Always ANALYZE the resulting table, for better stats */
1857  stringbuffer_aprintf(sb, "ANALYZE ");
1858  if (state->config->schema)
1859  {
1860  stringbuffer_aprintf(sb, "\"%s\".", state->config->schema);
1861  }
1862  stringbuffer_aprintf(sb, "\"%s\";\n", state->config->table);
1863 
1864  /* Copy the string buffer into a new string, destroying the string buffer */
1865  ret = (char *)malloc(strlen((char *)stringbuffer_getstring(sb)) + 1);
1866  strcpy(ret, (char *)stringbuffer_getstring(sb));
1868 
1869  *strfooter = ret;
1870 
1871  return SHPLOADEROK;
1872 }
SHPLOADERCONFIG * config
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
Definition: stringbuffer.c:35
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:253
void stringbuffer_clear(stringbuffer_t *s)
Reset the stringbuffer_t.
Definition: stringbuffer.c:90
#define SHPLOADEROK
void stringbuffer_destroy(stringbuffer_t *s)
Free the stringbuffer_t and all memory managed within it.
Definition: stringbuffer.c:78
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
Definition: stringbuffer.c:149
void * malloc(YYSIZE_T)
Here is the call graph for this function:
Here is the caller graph for this function: