[postgis-commits] svn - r2726 - in trunk: loader lwgeom

postgis-commits at postgis.refractions.net postgis-commits at postgis.refractions.net
Fri Jan 11 07:04:06 PST 2008


Author: mcayland
Date: 2008-01-11 07:04:05 -0800 (Fri, 11 Jan 2008)
New Revision: 2726

Modified:
   trunk/loader/pgsql2shp.c
   trunk/lwgeom/Makefile
Log:
Rewrite the pgsql2shp connection string code so that it uses a connection string, rather than setting environment variables. MingW-compiled and MSVC-compiled apps seem to have great problems passing the variables to each other, causing regression to fail. With this fix (and a Makefile tweak), it is now possible to run a MingW-compiled PostGIS against an MSVC compiled PostgreSQL and pass all regression tests.

Modified: trunk/loader/pgsql2shp.c
===================================================================
--- trunk/loader/pgsql2shp.c	2007-12-03 23:10:50 UTC (rev 2725)
+++ trunk/loader/pgsql2shp.c	2008-01-11 15:04:05 UTC (rev 2726)
@@ -71,6 +71,7 @@
 
 /* Global data */
 PGconn *conn;
+char conn_string[2048];
 int rowbuflen;
 char temptablename[256];
 char *geo_col_name, *table, *shp_file, *schema, *usrquery;
@@ -188,6 +189,7 @@
 	unescapedattrs=0;
 	binary = 0;
 	keep_fieldname_case = 0;
+	conn_string[0] = '\0';
 #ifdef DEBUG
 	FILE *debug;
 #endif
@@ -212,7 +214,7 @@
         if(shp_file == NULL) shp_file = table;
 
 	/* Make a connection to the specified database, and exit on failure */
-	conn = PQconnectdb("");
+	conn = PQconnectdb(conn_string);
 	if (PQstatus(conn) == CONNECTION_BAD) {
 		printf( "%s", PQerrorMessage(conn));
 		exit_nicely(conn, 1);
@@ -2334,15 +2336,14 @@
 parse_commandline(int ARGC, char **ARGV)
 {
 	int c, curindex;
-	char buf[1024];
+	char buf[2048];
         
         if ( ARGC == 1 ) {
                 usage(ARGV[0], 0, stdout);
         }
 
+	memset(buf, 0, 2048); /* just in case... */
 
-	buf[1023] = '\0'; /* just in case... */
-
 	/* Parse command line */
         while ((c = getopt(ARGC, ARGV, "bf:h:du:p:P:g:rk")) != EOF){
 		switch (c) {
@@ -2353,9 +2354,7 @@
 				shp_file = optarg;
 				break;
 			case 'h':
-				/*setenv("PGHOST", optarg, 1); */
-				snprintf(buf, 255, "PGHOST=%s", optarg);
-				putenv(strdup(buf));
+				snprintf(buf + strlen(buf), 255, "host=%s ", optarg);	
 				break;
 			case 'd':
 				dswitchprovided = 1;
@@ -2366,19 +2365,13 @@
 				unescapedattrs = 1;
 				break;		  
 			case 'u':
-				/*setenv("PGUSER", optarg, 1); */
-				snprintf(buf, 255, "PGUSER=%s", optarg);
-				putenv(strdup(buf));
+				snprintf(buf + strlen(buf), 255, "user=%s ", optarg);
 				break;
 			case 'p':
-				/*setenv("PGPORT", optarg, 1); */
-				snprintf(buf, 255, "PGPORT=%s", optarg);
-				putenv(strdup(buf));
+				snprintf(buf + strlen(buf), 255, "port=%s ", optarg);	
 				break;
 			case 'P':
-				/*setenv("PGPASSWORD", optarg, 1); */
-				snprintf(buf, 255, "PGPASSWORD=%s", optarg);
-				putenv(strdup(buf));
+				snprintf(buf + strlen(buf), 255, "password=%s ", optarg);
 				break;
 			case 'g':
 				geo_col_name = optarg;
@@ -2396,9 +2389,7 @@
         curindex=0;
         for (; optind<ARGC; optind++){
                 if (curindex == 0) {
-			/*setenv("PGDATABASE", ARGV[optind], 1); */
-		    	snprintf(buf, 255, "PGDATABASE=%s", ARGV[optind]);
-		    	putenv(strdup(buf));
+		    	snprintf(buf + strlen(buf), 255, "dbname=%s", ARGV[optind]);
                 }else if(curindex == 1){
 			parse_table(ARGV[optind]);
 
@@ -2406,6 +2397,10 @@
                 curindex++;
         }
         if (curindex < 2) return 0;
+	
+	/* Copy the buffer result to the connection string */
+	strncpy(conn_string, buf, 2048);	
+	
 	return 1;
 }
 

Modified: trunk/lwgeom/Makefile
===================================================================
--- trunk/lwgeom/Makefile	2007-12-03 23:10:50 UTC (rev 2725)
+++ trunk/lwgeom/Makefile	2008-01-11 15:04:05 UTC (rev 2726)
@@ -120,7 +120,7 @@
 	cpp -P -traditional-cpp -DUSE_VERSION=$(USE_VERSION) $< | sed -e 's:@MODULE_FILENAME@:$(MODULE_FILENAME):g;s:@POSTGIS_VERSION@:$(POSTGIS_VERSION):g;s:@POSTGIS_SCRIPTS_VERSION@:$(SCRIPTS_VERSION):g;s/@POSTGIS_BUILD_DATE@/$(POSTGIS_BUILD_DATE)/g' | grep -v '^#' > $@
 
 ../regress/lwpostgis.sql: lwpostgis.sql.in long_xact.sql.in sqlmm.sql.in sqldefines.h
-	cpp -P -traditional-cpp -DUSE_VERSION=$(USE_VERSION) $< | sed -e 's#@MODULE_FILENAME@#$(REGRESS_MODULE_FILENAME)#g;s#@POSTGIS_VERSION@#$(POSTGIS_VERSION)#g;s#@POSTGIS_SCRIPTS_VERSION@#$(SCRIPTS_VERSION)#g;s/@POSTGIS_BUILD_DATE@/$(POSTGIS_BUILD_DATE)/g' | grep -v '^#' > $@
+	cpp -P -traditional-cpp -DUSE_VERSION=$(USE_VERSION) $< | sed -e 's#@MODULE_FILENAME@#$(MODULE_FILENAME)#g;s#@POSTGIS_VERSION@#$(POSTGIS_VERSION)#g;s#@POSTGIS_SCRIPTS_VERSION@#$(SCRIPTS_VERSION)#g;s/@POSTGIS_BUILD_DATE@/$(POSTGIS_BUILD_DATE)/g' | grep -v '^#' > $@
 
 install: all install-lib-shared install-lwgeom-scripts
 



More information about the postgis-commits mailing list