From 3d34af5c23d2025e50d880aa568f63b38d9266f0 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 30 Dec 2003 12:37:46 +0000 Subject: [PATCH] Fixed segfault bug reported by Randy George, removed explicit sequence drop git-svn-id: http://svn.osgeo.org/postgis/trunk@417 b70326c6-7e19-0410-871a-916f4a2858ee --- loader/shp2pgsql.c | 90 +++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 50 deletions(-) diff --git a/loader/shp2pgsql.c b/loader/shp2pgsql.c index ab64662d1..3f2a4d630 100644 --- a/loader/shp2pgsql.c +++ b/loader/shp2pgsql.c @@ -12,6 +12,9 @@ * ********************************************************************** * $Log$ + * Revision 1.43 2003/12/30 12:37:46 strk + * Fixed segfault bug reported by Randy George, removed explicit sequence drop + * * Revision 1.42 2003/12/01 14:27:58 strk * added simple malloc wrapper * @@ -574,7 +577,7 @@ int main (int ARGC, char **ARGV){ char name[32]; char *sr_id,*shp_file,*table, *database; char **names; - DBFFieldType type; + DBFFieldType type = -1; extern char *optarg; extern int optind; opt = ' '; @@ -671,24 +674,25 @@ int main (int ARGC, char **ARGV){ exit(-1); } - if(opt == 'd'){ + if(opt == 'd') + { //-------------------------Drop the table-------------------------------- - //drop the table given - printf("delete from geometry_columns where f_table_name = '%s';\n",table); + printf("select DropGeometryColumn('','%s','the_geom');", table); if ( quoteidentifiers ){ printf("\ndrop table \"%s\";\n",table); - printf("\ndrop sequence \"%s_%s_seq\";\n",database,table); }else{ printf("\ndrop table %s;\n",table); - printf("\ndrop sequence %s_%s_seq;\n",database,table); } } - //-------------------------Get the col names to fully specify them in inserts------------------------------- + /* + * Get col names and types to fully specify them in inserts + */ num_fields = DBFGetFieldCount( hDBFHandle ); num_records = DBFGetRecordCount(hDBFHandle); names = malloc((num_fields + 1)*sizeof(char*)); + types = (DBFFieldType *)malloc((num_fields + 1)*sizeof(char*)); col_names = malloc(num_fields * sizeof(char) * 32); if(opt != 'a'){ strcpy(col_names, "(gid," ); @@ -699,6 +703,7 @@ int main (int ARGC, char **ARGV){ for(j=0;jpachFieldType[j] == 'D' ){ + for(j=0;jpachFieldType[j] == 'D' ) /* Date field */ + { printf ("varchar(8)");//date data-type is not supported in API so check for it explicity before the api call. - }else{ + } + + else + { if(type == FTString){ printf ("varchar"); @@ -799,20 +790,19 @@ int main (int ARGC, char **ARGV){ } printf (");\n"); //finished creating the table - } SHPGetInfo( hSHPHandle, &num_entities, &phnshapetype, &padminbound[0], &padmaxbound[0]); - j=num_entities; - while(obj == NULL && j--) - { + j=num_entities; + while(obj == NULL && j--) + { obj = SHPReadObject(hSHPHandle,j); - } - if ( obj == NULL) - { - fprintf(stderr, "Shapefile contains %d NULL object(s)\n", num_entities); + } + if ( obj == NULL) + { + fprintf(stderr, "Shapefile contains %d NULL object(s)\n", num_entities); exit(-1); } -- 2.40.0