* --- Conectar desde VFP a PostgreSQL. ---
lcConC = "DRIVER={PostgreSQL ODBC Driver(ANSI)};DATABASE=NombreBD;SERVER=localhost;PORT=5432;UID=postgres;PWD=postgres;"
cHandle = Sqlstringconnect(lcConC,.T.)
If cHandle > 0
Messagebox([Conexión exitosa.],64,[PostgreSQL])
Else
Messagebox([Error al conectarse.],64,[PostgreSQL])
cHandle = 0
Endif
Return* --- Leer Datos desde Postgres. ---
SQLExec(cHandle,[select * from "NomEsquema".Tabla],[csrTablacursor])
If Reccount()>0
Select csrTablacursor
Browse
Endif
SQLDisconnect(cHandle)
* --- Insertar datos en tabla Postgres. ---
SQLSetprop(cHandle,'Transactions',1)
SQLExec(cHandle,[Insert into "NomEsquema".Tabla (Campo1) values ('Dato a Cargar')])
If Sqlcommit(cHandle)>0
Messagebox('Datos Guardados exitosamente')
Else
If Aerror(laError)>0
Messagebox('Se produjo un error'+laError[2])
Endif
Endif
SQLDisconnect(cHandle)