PostGIS  2.1.10dev-r@@SVN_REVISION@@
int ShpLoaderGetSQLFooter ( SHPLOADERSTATE state,
char **  strfooter 
)

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

References shp_loader_state::config, shp_loader_config::createindex, shp_loader_state::geo_col, shp_loader_config::idxtablespace, 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().

1800 {
1801  stringbuffer_t *sb;
1802  char *ret;
1803 
1804  /* Create the stringbuffer containing the header; we use this API as it's easier
1805  for handling string resizing during append */
1806  sb = stringbuffer_create();
1807  stringbuffer_clear(sb);
1808 
1809  /* Create gist index if specified and not in "prepare" mode */
1810  if (state->config->createindex)
1811  {
1812  stringbuffer_aprintf(sb, "CREATE INDEX ON ");
1813  /* Schema is optional, include if present. */
1814  if (state->config->schema)
1815  {
1816  stringbuffer_aprintf(sb, "\"%s\".",state->config->schema);
1817  }
1818  stringbuffer_aprintf(sb, "\"%s\" USING GIST (\"%s\")", state->config->table, state->geo_col);
1819  /* Tablespace is also optional. */
1820  if (state->config->idxtablespace != NULL)
1821  {
1822  stringbuffer_aprintf(sb, " TABLESPACE \"%s\"", state->config->idxtablespace);
1823  }
1824  stringbuffer_aprintf(sb, ";\n");
1825  }
1826 
1827  /* End the transaction if there is one. */
1828  if (state->config->usetransaction)
1829  {
1830  stringbuffer_aprintf(sb, "COMMIT;\n");
1831  }
1832 
1833  /* Copy the string buffer into a new string, destroying the string buffer */
1834  ret = (char *)malloc(strlen((char *)stringbuffer_getstring(sb)) + 1);
1835  strcpy(ret, (char *)stringbuffer_getstring(sb));
1837 
1838  *strfooter = ret;
1839 
1840  return SHPLOADEROK;
1841 }
SHPLOADERCONFIG * config
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
Definition: stringbuffer.c:47
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
void stringbuffer_clear(stringbuffer_t *s)
Reset the stringbuffer_t.
Definition: stringbuffer.c:84
#define SHPLOADEROK
void stringbuffer_destroy(stringbuffer_t *s)
Free the stringbuffer_t and all memory managed within it.
Definition: stringbuffer.c:72
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
Definition: stringbuffer.c:143

Here is the call graph for this function:

Here is the caller graph for this function: