[postgis-users] PostgreSQL 7.3 Support
carl anderson
candrsn at mindspring.com
Fri Dec 6 16:56:59 PST 2002
On 2002.12.06 11:37 Paul Ramsey wrote:
> Does mapserver not work for you now? Our hope was that only PostGIS
> would need to be changed to support PgSQL 7.3, not the mapserver
> connector. How is mapserver failing against 7.3?
>
Well....
EXPLAIN <plan> now returns a tupleset to return results instead of
using the NOTICES facility to push a single multiline message. So
mapserver has no idea about field types.
I am very much in favor of the new EXPLAIN <plan>, as it allows plan
results to be saved/printed much easier.
attached is a patch against mapserver 3.6.3
C.
ps
I submitted this to [postgis-users] a couple of weeks ago but
forgot not to use multipart-mime. There are other patches, mostly
doing what is already in CVS if you want them.
----------------------------------
Carl Anderson
candrsn at mindspring.com
New Hampshire tells us "common sense for all"
where can I get mine?
----------------------------------
-------------------------------------------------------------------
diff -ur mapserver-3.6.3.old/mappostgis.c mapserver-3.6.3/mappostgis.c
--- mapserver-3.6.3.old/mappostgis.c Tue Jun 25 20:52:38 2002
+++ mapserver-3.6.3/mappostgis.c Fri Nov 22 16:41:30 2002
@@ -35,8 +35,9 @@
{
char *str,*str2;
char *result;
-
- if (strstr(message,"QUERY DUMP"))
+
+fprintf(stderr,"NH %s \n",message);
+ if (strstr(message,"QUERY DUMP:"))
{
if ( ((msPOSTGISLayerInfo *) arg)->fields)
{
@@ -1141,13 +1142,15 @@
msPOSTGISLayerParseData(layer->data, geom_column_name,
table_name, urid_name, user_srid);
+ query_result = PQexec(layerinfo->conn, "set
explain_pretty_print = on");
+// in pre 7.3 databases this will fail so relax
+
// two cases here. One, its a table (use select * from table)
otherwise, just use the select clause
sprintf(sql,"EXPLAIN VERBOSE SELECT * FROM %s",table_name);
// this will call the postresql_NOTICE_HANDLER()
callback! layer->fields will be populated
query_result = PQexec(layerinfo->conn, sql );
-
- if (!(query_result) || PQresultStatus(query_result) !=
PGRES_COMMAND_OK)
+ if (!(query_result) || (PQresultStatus(query_result) !=
PGRES_COMMAND_OK && PQresultStatus(query_result) != PGRES_TUPLES_OK ))
{
char tmp[4000];
@@ -1159,6 +1162,44 @@
query_result = NULL;
return(MS_FAILURE);
}
+
+ if (PQresultStatus(query_result) == PGRES_TUPLES_OK )
+ {
+ //build layerinfo->fields from tuples passed back
+ int rows,row;
+ char *result;
+ char *tup;
+ char *str,*str2;
+
+ if ( layerinfo->fields )
+ {
+ free(layerinfo->fields); // free up space
+ }
+ result = malloc ( 6000) ;
+ layerinfo->fields = result;
+ result[0] = 0; //null terminate it
+
+ rows = PQntuples(query_result);
+ for ( row=0; row < rows; row++ )
+ {
+ tup = PQgetvalue(query_result,row,0);
+ str = strstr(tup,":resname ");
+ if ( str )
+ {
+ str += 9;
+ str2 = strstr(str," ");
+ if (strncmp(str, "<>", (str2-str)))
+ {
+ if ( strlen(result) > 0 )
+ {
+ strcat(result,",");
+ }
+ strncat(result,str,(str2-str));
+ }
+ }
+ }
+ }
+
//layerinfo->fields is a string with a list of all the columns
More information about the postgis-users
mailing list