]> granicus.if.org Git - postgis/commitdiff
Explicitly set spatial index name as PostgreSQL 8.4 requires an index name. Associat...
authorBborie Park <bkpark at ucdavis.edu>
Tue, 31 Jan 2012 17:44:01 +0000 (17:44 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Tue, 31 Jan 2012 17:44:01 +0000 (17:44 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8975 b70326c6-7e19-0410-871a-916f4a2858ee

raster/loader/raster2pgsql.c
raster/rt_pg/rt_pg.c

index 3954b423ec79d7c9f7079c4b2beebe0916b6fddd..c2d067698a5b3b0e331c33316b773de09b43886a 100644 (file)
@@ -228,6 +228,7 @@ static char*
 trim(const char *input) {
        char *rtn;
        char *ptr;
+       uint32_t offset = 0;
 
        if (!input)
                return NULL;
@@ -240,15 +241,16 @@ trim(const char *input) {
 
        /* trim right */
        ptr = ((char *) input) + strlen(input);
-       while (isspace(*--ptr));
-       *(++ptr) = '\0';
+       while (isspace(*--ptr))
+               offset++;
 
-       rtn = rtalloc(sizeof(char) * (strlen(input) + 1));
+       rtn = rtalloc(sizeof(char) * (strlen(input) - offset + 1));
        if (NULL == rtn) {
                fprintf(stderr, _("Not enough memory\n"));
                return NULL;
        }
-       strcpy(rtn, input);
+       strncpy(rtn, input, strlen(input) - offset);
+       rtn[strlen(input) - offset] = '\0';
 
        return rtn;
 }
@@ -257,6 +259,7 @@ static char*
 chartrim(const char *input, char *remove) {
        char *rtn = NULL;
        char *ptr = NULL;
+       uint32_t offset = 0;
 
        if (!input)
                return NULL;
@@ -269,15 +272,16 @@ chartrim(const char *input, char *remove) {
 
        /* trim right */
        ptr = ((char *) input) + strlen(input);
-       while (strchr(remove, *--ptr) != NULL);
-       *(++ptr) = '\0';
+       while (strchr(remove, *--ptr) != NULL)
+               offset++;
 
-       rtn = rtalloc(sizeof(char) * (strlen(input) + 1));
+       rtn = rtalloc(sizeof(char) * (strlen(input) - offset + 1));
        if (NULL == rtn) {
                fprintf(stderr, _("Not enough memory\n"));
                return NULL;
        }
-       strcpy(rtn, input);
+       strncpy(rtn, input, strlen(input) - offset);
+       rtn[strlen(input) - offset] = '\0';
 
        return rtn;
 }
@@ -904,14 +908,21 @@ create_index(
 ) {
        char *sql = NULL;
        uint32_t len = 0;
+       char *_table = NULL;
+       char *_column = NULL;
 
        assert(table != NULL);
        assert(column != NULL);
 
+       _table = chartrim(table, "\"");
+       _column = chartrim(column, "\"");
+
        /* create index */
-       len = strlen("CREATE INDEX ON  USING gist (st_convexhull());") + 1;
+       len = strlen("CREATE INDEX \"__gist\" ON  USING gist (st_convexhull());") + 1;
        if (schema != NULL)
                len += strlen(schema);
+       len += strlen(_table);
+       len += strlen(_column);
        len += strlen(table);
        len += strlen(column);
        if (tablespace != NULL)
@@ -920,15 +931,21 @@ create_index(
        sql = rtalloc(sizeof(char) * len);
        if (sql == NULL) {
                fprintf(stderr, _("Could not allocate memory for CREATE INDEX statement\n"));
+               rtdealloc(_table);
+               rtdealloc(_column);
                return 0;
        }
-       sprintf(sql, "CREATE INDEX ON %s%s USING gist (st_convexhull(%s))%s%s;",
+       sprintf(sql, "CREATE INDEX \"%s_%s_gist\" ON %s%s USING gist (st_convexhull(%s))%s%s;",
+               _table,
+               _column,
                (schema != NULL ? schema : ""),
                table,
                column,
                (tablespace != NULL ? " TABLESPACE " : ""),
                (tablespace != NULL ? tablespace : "")
        );
+       rtdealloc(_table);
+       rtdealloc(_column);
 
        append_sql_to_buffer(buffer, sql);
        rtdealloc(sql);
index 6f7cb3ea3c04e93d4f45c7e6e91946e29ea297ee..fc22dc340a8ebdd97298e3cf041d6ad0e63e5c61 100644 (file)
@@ -334,6 +334,7 @@ static char*
 rtpg_chartrim(const char *input, char *remove) {
        char *rtn = NULL;
        char *ptr = NULL;
+       uint32_t offset = 0;
 
        if (!input)
                return NULL;
@@ -346,15 +347,16 @@ rtpg_chartrim(const char *input, char *remove) {
 
        /* trim right */
        ptr = ((char *) input) + strlen(input);
-       while (strchr(remove, *--ptr) != NULL);
-       *(++ptr) = '\0';
+       while (strchr(remove, *--ptr) != NULL)
+               offset++;
 
-       rtn = palloc(sizeof(char) * (strlen(input) + 1));
+       rtn = palloc(sizeof(char) * (strlen(input) - offset + 1));
        if (rtn == NULL) {
                fprintf(stderr, "Not enough memory\n");
                return NULL;
        }
-       strcpy(rtn, input);
+       strncpy(rtn, input, strlen(input) - offset);
+       rtn[strlen(input) - offset] = '\0';
 
        return rtn;
 }
@@ -448,6 +450,7 @@ static char*
 rtpg_trim(const char *input) {
        char *rtn;
        char *ptr;
+       uint32_t offset = 0;
 
        if (!input)
                return NULL;
@@ -460,15 +463,16 @@ rtpg_trim(const char *input) {
 
        /* trim right */
        ptr = ((char *) input) + strlen(input);
-       while (isspace(*--ptr));
-       *(++ptr) = '\0';
+       while (isspace(*--ptr))
+               offset++;
 
-       rtn = palloc(sizeof(char) * (strlen(input) + 1));
+       rtn = palloc(sizeof(char) * (strlen(input) - offset + 1));
        if (rtn == NULL) {
                fprintf(stderr, "Not enough memory\n");
                return NULL;
        }
-       strcpy(rtn, input);
+       strncpy(rtn, input, strlen(input) - offset);
+       rtn[strlen(input) - offset] = '\0';
 
        return rtn;
 }