[FWTools] Connecting to PostgreSQL with fwtools

Flavio Perri - QMap srl flavio.perri at qmap.it
Tue Jul 7 04:52:13 EST 2009


Hello everyone,
I used FWTools in my program to manipulate shapefiles and it worked fine.
Now I'd like to use a DB(Postgres/PostGis) to read and write GIS data
tables.
i'm developing with the last release (2.4.2) and unfortunately I cannot find
a right solution to connect to PGSQL.

First, I got the driver "PostgreSQL", then I tried to connect to the
DBserver using the function CreateDataSource().

[...]

    char options[5][256];


    sprintf(options[0],"dbname='%s'",dbServerName);
    sprintf(options[1],"host='%s'",dbHostAddress);
    sprintf(options[2],"port='%s'",port);
    sprintf(options[3],"user='%s'",userName);
    sprintf(options[4],"passwd='%s'",password);

dataSource = poDriver->CreateDataSource("layerName",(char**)options );

[...]

I always get a NULL dataSource, and I'm stuck.

I'm sure that OGR is capable to connect to PGSQL, because I tried the tool
"ogr2ogr" and it connects to PG and manipulate GIS data with a simple
connection string like: PG:"dbname='databasename' host='addr' port='5432'
user='x' passwd='y'".


Any hint?

Thanks in advance,
Flavio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/fwtools/attachments/20090707/021a15c8/attachment.htm 


More information about the FWTools mailing list