2009-01-19 21:33:14 +00:00
|
|
|
/**********************************************************************
|
2009-02-04 00:28:37 +00:00
|
|
|
* $Id$
|
2009-01-19 21:33:14 +00:00
|
|
|
*
|
|
|
|
* PostGIS - Spatial Types for PostgreSQL
|
2010-12-28 18:22:37 +00:00
|
|
|
* http://www.postgis.org
|
2009-01-19 21:33:14 +00:00
|
|
|
* Copyright 2008 OpenGeo.org
|
2009-12-13 20:31:54 +00:00
|
|
|
* Copyright 2009 Mark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
|
2009-01-19 21:33:14 +00:00
|
|
|
*
|
|
|
|
* This is free software; you can redistribute and/or modify it under
|
|
|
|
* the terms of the GNU General Public Licence. See the COPYING file.
|
|
|
|
*
|
|
|
|
* Maintainer: Paul Ramsey <pramsey@opengeo.org>
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#include "shp2pgsql-core.h"
|
2011-08-09 09:51:52 +00:00
|
|
|
#include "../liblwgeom/liblwgeom.h" /* for SRID_UNKNOWN */
|
2009-01-19 21:33:14 +00:00
|
|
|
|
|
|
|
static void
|
2009-12-13 20:31:54 +00:00
|
|
|
usage()
|
2009-01-19 21:33:14 +00:00
|
|
|
{
|
2010-12-02 03:43:23 +00:00
|
|
|
printf(_( "RELEASE: %s (r%s)\n" ), POSTGIS_VERSION, RCSID);
|
2011-03-18 16:54:18 +00:00
|
|
|
printf(_( "USAGE: shp2pgsql [<options>] <shapefile> [[<schema>.]<table>]\n"
|
2010-12-02 03:43:23 +00:00
|
|
|
"OPTIONS:\n" ));
|
2011-12-19 19:06:31 +00:00
|
|
|
printf(_( " -s [<from>:]<srid> Set the SRID field. Defaults to %d.\n"
|
|
|
|
" Optionally reprojects from given SRID (cannot be used with -D).\n"),
|
|
|
|
SRID_UNKNOWN);
|
2011-03-18 15:40:31 +00:00
|
|
|
printf(_( " (-d|a|c|p) These are mutually exclusive options:\n"
|
2010-12-02 03:43:23 +00:00
|
|
|
" -d Drops the table, then recreates it and populates\n"
|
|
|
|
" it with current shape file data.\n"
|
|
|
|
" -a Appends shape file into current table, must be\n"
|
|
|
|
" exactly the same table schema.\n"
|
|
|
|
" -c Creates a new table and populates it, this is the\n"
|
|
|
|
" default if you do not specify any options.\n"
|
|
|
|
" -p Prepare mode, only creates the table.\n" ));
|
|
|
|
printf(_( " -g <geocolumn> Specify the name of the geometry/geography column\n"
|
|
|
|
" (mostly useful in append mode).\n" ));
|
2011-12-19 19:06:31 +00:00
|
|
|
printf(_( " -D Use postgresql dump format (defaults to SQL insert statements).\n" ));
|
2011-03-16 17:16:47 +00:00
|
|
|
printf(_( " -e Execute each statement individually, do not use a transaction.\n"
|
|
|
|
" Not compatible with -D.\n" ));
|
2011-03-18 15:40:31 +00:00
|
|
|
printf(_( " -G Use geography type (requires lon/lat data or -r to reproject).\n" ));
|
2010-12-02 03:43:23 +00:00
|
|
|
printf(_( " -k Keep postgresql identifiers case.\n" ));
|
|
|
|
printf(_( " -i Use int4 type for all integer dbf fields.\n" ));
|
|
|
|
printf(_( " -I Create a spatial index on the geocolumn.\n" ));
|
|
|
|
printf(_( " -S Generate simple geometries instead of MULTI geometries.\n" ));
|
2011-03-18 15:40:31 +00:00
|
|
|
printf(_( " -w Output WKT instead of WKB. Note that this can result in\n"
|
|
|
|
" coordinate drift.\n" ));
|
2010-12-02 03:43:23 +00:00
|
|
|
printf(_( " -W <encoding> Specify the character encoding of Shape's\n"
|
|
|
|
" attribute column. (default: \"UTF-8\")\n" ));
|
2010-12-14 05:01:51 +00:00
|
|
|
printf(_( " -N <policy> NULL geometries handling policy (insert*,skip,abort).\n" ));
|
2010-12-02 03:43:23 +00:00
|
|
|
printf(_( " -n Only import DBF file.\n" ));
|
2011-03-16 13:02:43 +00:00
|
|
|
printf(_( " -T <tablespace> Specify the tablespace for the new table.\n"
|
2011-03-16 17:16:47 +00:00
|
|
|
" Note that indexes will still use the default tablespace unless the\n"
|
|
|
|
" -X flag is also used.\n"));
|
2011-03-16 13:02:43 +00:00
|
|
|
printf(_( " -X <tablespace> Specify the tablespace for the table's indexes.\n"
|
2011-03-16 17:16:47 +00:00
|
|
|
" This applies to the primary key, and the spatial index if\n"
|
|
|
|
" the -I flag is used.\n" ));
|
2010-12-02 03:43:23 +00:00
|
|
|
printf(_( " -? Display this help screen.\n" ));
|
2009-01-19 21:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
2009-01-19 21:33:14 +00:00
|
|
|
{
|
2009-12-13 20:31:54 +00:00
|
|
|
SHPLOADERCONFIG *config;
|
|
|
|
SHPLOADERSTATE *state;
|
|
|
|
char *header, *footer, *record;
|
2011-03-18 19:43:25 +00:00
|
|
|
int c;
|
2009-12-13 20:31:54 +00:00
|
|
|
int ret, i;
|
|
|
|
|
2010-12-02 00:44:24 +00:00
|
|
|
#ifdef USE_NLS
|
2010-12-02 03:43:23 +00:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2010-12-02 00:44:24 +00:00
|
|
|
#endif
|
2009-12-13 20:31:54 +00:00
|
|
|
|
|
|
|
/* If no options are specified, display usage */
|
2010-02-01 17:35:55 +00:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
2009-12-13 20:31:54 +00:00
|
|
|
usage();
|
|
|
|
exit(0);
|
2009-01-19 21:33:14 +00:00
|
|
|
}
|
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* Parse command line options and set configuration */
|
|
|
|
config = malloc(sizeof(SHPLOADERCONFIG));
|
2011-07-02 13:43:35 +00:00
|
|
|
set_loader_config_defaults(config);
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2011-03-16 17:16:47 +00:00
|
|
|
/* Keep the flag list alphabetic so it's easy to see what's left. */
|
2011-12-19 19:06:31 +00:00
|
|
|
while ((c = pgis_getopt(argc, argv, "acdeg:iknps:wDGIN:ST:W:X:")) != EOF)
|
2009-12-13 20:31:54 +00:00
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'c':
|
|
|
|
case 'd':
|
|
|
|
case 'a':
|
|
|
|
case 'p':
|
2010-02-02 00:15:14 +00:00
|
|
|
config->opt = c;
|
2010-02-01 17:35:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
config->dump_format = 1;
|
2011-03-16 17:16:47 +00:00
|
|
|
if (!config->usetransaction)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot use both -D and -e.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-03-18 15:40:31 +00:00
|
|
|
if (config->shp_sr_id != SRID_UNKNOWN)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot use both -D and -r.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-02-01 17:35:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'G':
|
|
|
|
config->geography = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
config->simple_geometries = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
2010-03-22 19:38:14 +00:00
|
|
|
if (pgis_optarg)
|
2010-02-01 17:35:55 +00:00
|
|
|
{
|
2011-12-19 19:06:31 +00:00
|
|
|
char *ptr = strchr(pgis_optarg, ':');
|
|
|
|
if ( ptr )
|
|
|
|
{
|
|
|
|
if (config->dump_format)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot use both -D and -r.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
*ptr++ = '\0';
|
|
|
|
sscanf(pgis_optarg, "%d", &(config->shp_sr_id));
|
|
|
|
if ( ! *ptr ) { printf("No ptr?\n"); usage(); exit(1); }
|
|
|
|
sscanf(ptr, "%d", &(config->sr_id));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sscanf(pgis_optarg, "%d", &(config->sr_id));
|
|
|
|
}
|
2010-02-01 17:35:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-19 19:06:31 +00:00
|
|
|
/* With -s, user must specify SRID or FROM_SRID:TO_SRID */
|
2010-02-01 17:35:55 +00:00
|
|
|
usage();
|
2011-03-18 15:40:31 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'g':
|
2011-03-18 15:40:31 +00:00
|
|
|
config->geo_col = pgis_optarg;
|
2010-02-01 17:35:55 +00:00
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'k':
|
|
|
|
config->quoteidentifiers = 1;
|
|
|
|
break;
|
2009-12-21 23:22:21 +00:00
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'i':
|
|
|
|
config->forceint4 = 1;
|
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'I':
|
|
|
|
config->createindex = 1;
|
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'w':
|
2011-03-18 15:40:31 +00:00
|
|
|
config->use_wkt = 1;
|
2010-02-01 17:35:55 +00:00
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'n':
|
|
|
|
config->readshape = 0;
|
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'W':
|
2010-03-22 19:38:14 +00:00
|
|
|
config->encoding = pgis_optarg;
|
2010-02-01 17:35:55 +00:00
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'N':
|
2010-03-22 19:38:14 +00:00
|
|
|
switch (pgis_optarg[0])
|
2010-02-01 17:35:55 +00:00
|
|
|
{
|
|
|
|
case 'a':
|
|
|
|
config->null_policy = POLICY_NULL_ABORT;
|
2009-01-19 21:33:14 +00:00
|
|
|
break;
|
2010-02-01 17:35:55 +00:00
|
|
|
case 'i':
|
|
|
|
config->null_policy = POLICY_NULL_INSERT;
|
2009-01-19 21:33:14 +00:00
|
|
|
break;
|
2010-02-01 17:35:55 +00:00
|
|
|
case 's':
|
|
|
|
config->null_policy = POLICY_NULL_SKIP;
|
2009-01-19 21:33:14 +00:00
|
|
|
break;
|
2010-02-01 17:35:55 +00:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unsupported NULL geometry handling policy.\nValid policies: insert, skip, abort\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2011-03-16 13:02:43 +00:00
|
|
|
case 'T':
|
|
|
|
config->tablespace = pgis_optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
config->idxtablespace = pgis_optarg;
|
|
|
|
break;
|
|
|
|
|
2011-03-16 17:16:47 +00:00
|
|
|
case 'e':
|
|
|
|
config->usetransaction = 0;
|
|
|
|
if (config->dump_format)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot use both -D and -e.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
exit(0);
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
exit(0);
|
2009-01-19 21:33:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-02 02:41:36 +00:00
|
|
|
/* Determine the shapefile name from the next argument, if no shape file, exit. */
|
2010-03-22 19:38:14 +00:00
|
|
|
if (pgis_optind < argc)
|
2009-12-13 20:31:54 +00:00
|
|
|
{
|
2010-03-22 19:38:14 +00:00
|
|
|
config->shp_file = argv[pgis_optind];
|
|
|
|
pgis_optind++;
|
2010-02-01 17:35:55 +00:00
|
|
|
}
|
2010-02-02 02:41:36 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
}
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* Determine the table and schema names from the next argument */
|
2010-03-22 19:38:14 +00:00
|
|
|
if (pgis_optind < argc)
|
2009-12-13 20:31:54 +00:00
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
2010-03-22 19:38:14 +00:00
|
|
|
ptr = strchr(argv[pgis_optind], '.');
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* Schema qualified table name */
|
|
|
|
if (ptr)
|
|
|
|
{
|
2010-03-22 19:38:14 +00:00
|
|
|
config->schema = malloc(strlen(argv[pgis_optind]) + 1);
|
|
|
|
snprintf(config->schema, ptr - argv[pgis_optind] + 1, "%s", argv[pgis_optind]);
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2010-03-22 19:38:14 +00:00
|
|
|
config->table = malloc(strlen(argv[pgis_optind]));
|
|
|
|
snprintf(config->table, strlen(argv[pgis_optind]) - strlen(config->schema), "%s", ptr + 1);
|
2009-12-13 20:31:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-22 19:38:14 +00:00
|
|
|
config->table = malloc(strlen(argv[pgis_optind]) + 1);
|
|
|
|
strcpy(config->table, argv[pgis_optind]);
|
2009-01-19 21:33:14 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-02 04:14:29 +00:00
|
|
|
|
2010-02-02 02:41:36 +00:00
|
|
|
/* If the table parameter is not provided, use the shape file name as a proxy value.
|
|
|
|
Strip out the .shp and the leading path information first. */
|
2010-02-02 04:14:29 +00:00
|
|
|
if ( config->shp_file && config->table == NULL)
|
2010-02-02 02:41:36 +00:00
|
|
|
{
|
|
|
|
char *shp_file = strdup(config->shp_file);
|
|
|
|
char *ptr;
|
2010-02-03 21:42:20 +00:00
|
|
|
for ( ptr = shp_file + strlen(shp_file); ptr > shp_file; ptr-- )
|
2010-02-02 02:41:36 +00:00
|
|
|
{
|
2010-02-02 04:14:29 +00:00
|
|
|
if ( *ptr == '.' )
|
2010-02-02 02:41:36 +00:00
|
|
|
{
|
|
|
|
*ptr = '\0';
|
|
|
|
}
|
2010-02-02 04:14:29 +00:00
|
|
|
if ( *ptr == '/' || *ptr == '\\' )
|
2010-02-02 02:41:36 +00:00
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
config->table = strdup(ptr);
|
|
|
|
free(shp_file);
|
|
|
|
}
|
|
|
|
|
2010-02-01 17:35:55 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* Transform table name to lower case if no quoting specified */
|
|
|
|
if (!config->quoteidentifiers)
|
|
|
|
{
|
2010-02-02 04:14:29 +00:00
|
|
|
if ( config->table )
|
2010-02-02 02:41:36 +00:00
|
|
|
strtolower(config->table);
|
|
|
|
if ( config->schema )
|
2009-12-13 20:31:54 +00:00
|
|
|
strtolower(config->schema);
|
2009-01-19 21:33:14 +00:00
|
|
|
}
|
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* Create the shapefile state object */
|
|
|
|
state = ShpLoaderCreate(config);
|
|
|
|
|
|
|
|
/* Open the shapefile */
|
|
|
|
ret = ShpLoaderOpenShape(state);
|
|
|
|
if (ret != SHPLOADEROK)
|
2009-01-19 21:33:14 +00:00
|
|
|
{
|
2009-12-13 20:31:54 +00:00
|
|
|
fprintf(stderr, "%s\n", state->message);
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
if (ret == SHPLOADERERR)
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* If reading the whole shapefile, display its type */
|
|
|
|
if (state->config->readshape)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Shapefile type: %s\n", SHPTypeName(state->shpfiletype));
|
|
|
|
fprintf(stderr, "Postgis type: %s[%d]\n", state->pgtype, state->pgdims);
|
|
|
|
}
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* Print the header to stdout */
|
|
|
|
ret = ShpLoaderGetSQLHeader(state, &header);
|
|
|
|
if (ret != SHPLOADEROK)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", state->message);
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
if (ret == SHPLOADERERR)
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
printf("%s", header);
|
|
|
|
free(header);
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
/* If we are not in "prepare" mode, go ahead and write out the data. */
|
2010-02-02 04:14:29 +00:00
|
|
|
if ( state->config->opt != 'p' )
|
2009-12-13 20:31:54 +00:00
|
|
|
{
|
2010-02-01 17:35:55 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
/* If in COPY mode, output the COPY statement */
|
|
|
|
if (state->config->dump_format)
|
|
|
|
{
|
|
|
|
ret = ShpLoaderGetSQLCopyStatement(state, &header);
|
|
|
|
if (ret != SHPLOADEROK)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", state->message);
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
if (ret == SHPLOADERERR)
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
printf("%s", header);
|
|
|
|
free(header);
|
|
|
|
}
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
/* Main loop: iterate through all of the records and send them to stdout */
|
|
|
|
for (i = 0; i < ShpLoaderGetRecordCount(state); i++)
|
2009-12-13 20:31:54 +00:00
|
|
|
{
|
2010-02-02 00:15:14 +00:00
|
|
|
ret = ShpLoaderGenerateSQLRowStatement(state, i, &record);
|
2010-02-01 17:35:55 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
switch (ret)
|
|
|
|
{
|
|
|
|
case SHPLOADEROK:
|
|
|
|
/* Simply display the geometry */
|
|
|
|
printf("%s\n", record);
|
|
|
|
free(record);
|
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
case SHPLOADERERR:
|
|
|
|
/* Display the error message then stop */
|
|
|
|
fprintf(stderr, "%s\n", state->message);
|
|
|
|
exit(1);
|
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
case SHPLOADERWARN:
|
|
|
|
/* Display the warning, but continue */
|
|
|
|
fprintf(stderr, "%s\n", state->message);
|
|
|
|
printf("%s\n", record);
|
|
|
|
free(record);
|
|
|
|
break;
|
2009-12-13 20:31:54 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
case SHPLOADERRECDELETED:
|
|
|
|
/* Record is marked as deleted - ignore */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHPLOADERRECISNULL:
|
|
|
|
/* Record is NULL and should be ignored according to NULL policy */
|
|
|
|
break;
|
|
|
|
}
|
2009-12-13 20:31:54 +00:00
|
|
|
}
|
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
/* If in COPY mode, terminate the COPY statement */
|
|
|
|
if (state->config->dump_format)
|
|
|
|
printf("\\.\n");
|
2009-12-14 01:23:14 +00:00
|
|
|
|
2010-02-02 00:15:14 +00:00
|
|
|
}
|
2010-02-02 04:14:29 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* Print the footer to stdout */
|
|
|
|
ret = ShpLoaderGetSQLFooter(state, &footer);
|
|
|
|
if (ret != SHPLOADEROK)
|
2009-01-19 21:33:14 +00:00
|
|
|
{
|
2009-12-13 20:31:54 +00:00
|
|
|
fprintf(stderr, "%s\n", state->message);
|
|
|
|
|
|
|
|
if (ret == SHPLOADERERR)
|
|
|
|
exit(1);
|
2009-01-19 21:33:14 +00:00
|
|
|
}
|
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
printf("%s", footer);
|
|
|
|
free(footer);
|
2009-01-19 21:33:14 +00:00
|
|
|
|
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* Free the state object */
|
|
|
|
ShpLoaderDestroy(state);
|
2009-01-19 21:33:14 +00:00
|
|
|
|
2009-12-13 20:31:54 +00:00
|
|
|
/* Free configuration variables */
|
|
|
|
if (config->schema)
|
|
|
|
free(config->schema);
|
2010-02-02 02:41:36 +00:00
|
|
|
if (config->table)
|
|
|
|
free(config->table);
|
2009-12-13 20:31:54 +00:00
|
|
|
free(config);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|