From 58909ffbe933dadde074842511be552d5bdafd06 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Tue, 31 Jan 2012 17:44:01 +0000 Subject: [PATCH] Explicitly set spatial index name as PostgreSQL 8.4 requires an index name. Associated ticket is #1513. Also fixed string trim functions to prevent modification of passed string. git-svn-id: http://svn.osgeo.org/postgis/trunk@8975 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/loader/raster2pgsql.c | 37 ++++++++++++++++++++++++++---------- raster/rt_pg/rt_pg.c | 20 +++++++++++-------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/raster/loader/raster2pgsql.c b/raster/loader/raster2pgsql.c index 3954b423e..c2d067698 100644 --- a/raster/loader/raster2pgsql.c +++ b/raster/loader/raster2pgsql.c @@ -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); diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 6f7cb3ea3..fc22dc340 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -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; } -- 2.40.0