PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ShpLoaderGetSQLFooter()

int ShpLoaderGetSQLFooter ( SHPLOADERSTATE state,
char **  strfooter 
)

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

1840 {
1841  stringbuffer_t *sb;
1842  char *ret;
1843 
1844  /* Create the stringbuffer containing the header; we use this API as it's easier
1845  for handling string resizing during append */
1846  sb = stringbuffer_create();
1847  stringbuffer_clear(sb);
1848 
1849  /* Create gist index if specified and not in "prepare" mode */
1850  if (state->config->readshape && state->config->createindex)
1851  {
1852  stringbuffer_aprintf(sb, "CREATE INDEX ON ");
1853  /* Schema is optional, include if present. */
1854  if (state->config->schema)
1855  {
1856  stringbuffer_aprintf(sb, "\"%s\".",state->config->schema);
1857  }
1858  stringbuffer_aprintf(sb, "\"%s\" USING GIST (\"%s\")", state->config->table, state->geo_col);
1859  /* Tablespace is also optional. */
1860  if (state->config->idxtablespace != NULL)
1861  {
1862  stringbuffer_aprintf(sb, " TABLESPACE \"%s\"", state->config->idxtablespace);
1863  }
1864  stringbuffer_aprintf(sb, ";\n");
1865  }
1866 
1867  /* End the transaction if there is one. */
1868  if (state->config->usetransaction)
1869  {
1870  stringbuffer_aprintf(sb, "COMMIT;\n");
1871  }
1872 
1873  /* Always ANALYZE the resulting table, for better stats */
1874  stringbuffer_aprintf(sb, "ANALYZE ");
1875  if (state->config->schema)
1876  {
1877  stringbuffer_aprintf(sb, "\"%s\".", state->config->schema);
1878  }
1879  stringbuffer_aprintf(sb, "\"%s\";\n", state->config->table);
1880 
1881  /* Copy the string buffer into a new string, destroying the string buffer */
1882  ret = (char *)malloc(strlen((char *)stringbuffer_getstring(sb)) + 1);
1883  strcpy(ret, (char *)stringbuffer_getstring(sb));
1885 
1886  *strfooter = ret;
1887 
1888  return SHPLOADEROK;
1889 }
void * malloc(YYSIZE_T)
#define SHPLOADEROK
void stringbuffer_clear(stringbuffer_t *s)
Reset the stringbuffer_t.
Definition: stringbuffer.c:90
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
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
Definition: stringbuffer.c:35
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
SHPLOADERCONFIG * config

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 pgui_action_import().

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