]> granicus.if.org Git - postgis/commitdiff
Minor cleanups in loader
authorSandro Santilli <strk@keybit.net>
Wed, 27 Jul 2005 02:34:29 +0000 (02:34 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 27 Jul 2005 02:34:29 +0000 (02:34 +0000)
git-svn-id: http://svn.osgeo.org/postgis/branches/pgis_1_0@1835 b70326c6-7e19-0410-871a-916f4a2858ee

CHANGES
loader/shp2pgsql.c

diff --git a/CHANGES b/CHANGES
index b2a18ffabdccf33a7dd6ed47efbd31661a561405..b0f5766f536aac80df0ed58e46754515dbe933f2 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,7 @@ PostGIS 1.0.3
        - Bugfix in dumper handling of user-defined queries 
        - Bugfix in create_undef.pl script
        - Small performance improvement in canonical input function
+       - Minor cleanups in loader
        - Severe bugfix in lwgeom's 2d bounding box computation
 
 PostGIS 1.0.2
index 94aef14565c22cffc0d3a00db545c070315cd056..b583e1d18b54b495a1016af572499111719f400f 100644 (file)
@@ -1511,10 +1511,15 @@ DropTable(char *schema, char *table, char *geom)
 void
 GetFieldsSpec(void)
 {
+/*
+ * Shapefile (dbf) field name are at most 10chars + 1 NULL.
+ * Postgresql field names are at most 63 bytes + 1 NULL.
+ */
+#define MAXFIELDNAMELEN 64
        int field_precision, field_width;
        int j, z;
-       char  name[64];
-       char  name2[64];
+       char  name[MAXFIELDNAMELEN];
+       char  name2[MAXFIELDNAMELEN];
        DBFFieldType type = -1;
 
        num_fields = DBFGetFieldCount( hDBFHandle );
@@ -1523,7 +1528,7 @@ GetFieldsSpec(void)
        types = (DBFFieldType *)malloc(num_fields*sizeof(int));
        widths = malloc(num_fields*sizeof(int));
        precisions = malloc(num_fields*sizeof(int));
-       col_names = malloc((num_fields+2) * sizeof(char) * 32);
+       col_names = malloc((num_fields+2) * sizeof(char) * MAXFIELDNAMELEN);
        strcpy(col_names, "(" );
 
        //fprintf(stderr, "Number of fields from DBF: %d\n", num_fields);
@@ -1540,28 +1545,14 @@ GetFieldsSpec(void)
                 * Make field names lowercase unless asked to
                 * keep identifiers case.
                 */
-               if ( ! quoteidentifiers ) {
-                       for(z=0; z<strlen(name) ;z++)
-                               name[z] = tolower(name[z]);
-               }
+               if ( ! quoteidentifiers ) LowerCase(name);
 
                /*
                 * Escape names starting with the
-                * escape char (_)
+                * escape char (_), those named 'gid'
+                * or after pgsql reserved attribute names
                 */
-               if( name[0]=='_' )
-               {
-                       strcpy(name2+2, name);
-                       name2[0] = '_';
-                       name2[1] = '_';
-                       strcpy(name, name2);
-               }
-
-               /*
-                * Escape attributes named 'gid'
-                * and pgsql reserved attribute names
-                */
-               else if(
+               if( name[0]=='_' ||
                        ! strcmp(name,"gid") ||
                        ! strcmp(name, "tableoid") ||
                        ! strcmp(name, "cmax") ||
@@ -1569,8 +1560,8 @@ GetFieldsSpec(void)
                        ! strcmp(name, "cmin") ||
                        ! strcmp(name, "primary") ||
                        ! strcmp(name, "oid") ||
-                       ! strcmp(name, "ctid")
-               {
+                       ! strcmp(name, "ctid") )
+               {
                        strcpy(name2+2, name);
                        name2[0] = '_';
                        name2[1] = '_';
@@ -1586,7 +1577,6 @@ GetFieldsSpec(void)
                        }
                }       
 
-
                field_names[j] = malloc ( strlen(name)+3 );
                strcpy(field_names[j], name);
 
@@ -1643,6 +1633,9 @@ utf8 (const char *fromcode, char *inputbuf)
 
 /**********************************************************************
  * $Log$
+ * Revision 1.88.2.4  2005/07/27 02:34:29  strk
+ * Minor cleanups in loader
+ *
  * Revision 1.88.2.3  2005/07/27 02:05:20  strk
  * Fixed handling of POINT types as WKT (-w) in loader
  *