Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with Postgres ODBC driver
Message
From
10/08/2010 09:49:54
Calvin Smith
Wayne Reaves Computer Systems
Macon, Georgia, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Third party products
Title:
Problem with Postgres ODBC driver
Miscellaneous
Thread ID:
01475953
Message ID:
01475953
Views:
254
I am attempting to move a backend from SQLServer to Postgres. I am able to use remove views for both SQLServer and Postgres to move data to Postgres. I am using the PostgresSQL30 ODBC driver with this connection string :

DSN=PostgreSQL30;DATABASE=aNewData;SERVER=192.168.1.230;PORT=5432;UID=postgres;PWD=cvbnm;CA=r;A6=;A7=100;A8=4096;B0=255;B1=8190;BI=0;C2=dd_;CX=1b502bb;A1=7.4-1

Here is the code I am using : (In reality I am doing this for many more tables)
dimension ctables(5,2)
ctables(1,1)='sqlCompany'
ctables(1,2)='pgCompany'
ctables(2,1)='sqlvehiclebody'
ctables(2,2)='pgVehiclebody'
ctables(3,1)="sqlchartofaccounts"
ctables(3,2)="pgchartofaccounts"
ctables(4,1)="sqlchartofaccounttypes"
ctables(4,2)="pgchartofaccounttypes"
ctables(5,1)="sqlcountycodes"
ctables(5,2)="pgcountycodes"
SET STATUS BAR ON
nInserts=0
FOR mycounter = 1 TO ALEN(ctables,1)
	fieldStr=""
	totalInserts=0
	USE ctables(mycounter,1) alias sqlt IN 0 
	USE ctables(mycounter,2) IN 0 alias pgt
	SELECT sqlt
	* ?RECCOUNT()
	WAIT 'Working on '+ctables(mycounter,2) WINDOW nowait 			
	DELETE FROM pgt
	=TABLEUPDATE(.t.,.t.,'pgt') && zap the table in postgres
	SELECT sqlt	
	SCAN
		SCATTER MEMVAR memo
		FOR i =1 TO FCOUNT()
			DO case
				case VARTYPE(EVALUATE(FIELD(i)))="L"
					fieldName='m.'+FIELD(i)
					IF EVALUATE(fieldname)=.f.
						&fieldname='0'
					ELSE
						&fieldname='1'
					ENDIF
				CASE VARTYPE(EVALUATE(FIELD(i)))="C"	
					ftoPad='m.'+FIELD(i)
					&ftoPad=ALLTRIM(&ftoPad)
			ENDCASE											
		NEXT			
		m.updatedat=DATETIME()
		nInserts=nInserts+1
		totalInserts=totalInserts+1
		INSERT INTO pgt FROM memvar
		IF MOD(nInserts,100)=0		
			WAIT 'Have Inserted '+LTRIM(STR(totalInserts))+' into table '+ctables(mycounter,2) WINDOW nowait
			nInserts=0
			res =TABLEUPDATE(.t.,.t.,'pgt')
		ENDIF
		SELECT sqlt
	ENDSCAN
	nInserts=0
	SELECT pgt
	=TABLEUPDATE(.t.)
	CLOSE TABLES all	
NEXT
Everything works fine except - All of the character fields (varchars in SQLServer and character varying in Postgres) end up padded with spaces to the maximum length of the fields. If a field has the value 'BOO' and it is put in a character varying field set to 10 then the data would actually transfer as 'BOO '. This won't work and I know that there must be some setting in the connection string that would keep this from happening but I can't find any documentation on it. Any help greatly appreciated!
A problem is a problem only as long as it has a possible solution. Lacking that, it becomes a FACT!
Next
Reply
Map
View

Click here to load this message in the networking platform