[FWTools] Connecting to PostgreSQL with fwtools

Flavio Perri - QMap srl flavio.perri at qmap.it
Tue Jul 7 11:37:14 EST 2009


2009/7/7 Frank Warmerdam <warmerdam at pobox.com>

> Flavio Perri - QMap srl wrote:
>
>> Hello Frank,
>> thanks for your answer.
>>
>> I tried looking at OGR documentation, and I found the method you wrote:
>>
>> OGRDataSource * OGRSFDriverRegistrar::Open   (   const char *     pszName,
>> int   bUpdate = FALSE, OGRSFDriver **   ppoDriver = NULL   ) .
>>
>> I don't understand the first parameter: is it the NAME of a PSQL istance
>> or an handle? And, in this case, should I connect using the psql library?
>> Please can you give me a simple example?
>>
>
> Flavio,
>
> The pszName value is just the "PG:dbname=... ..." string you would pass on
> the commandline to ogr2ogr.  You will want to pass bUpdate as TRUE and the
> last argument can be left NULL since it isn't important for you to discover
> what driver ended up being used.
>
> Don't hesitate to skim the ogr2ogr source code for guidance.


Hi Frank,
i tried that way, but it still doesn't work!!

This is my CodeSample:

--------------
string connectionSTR="";

    connectionSTR +="PG:";
    connectionSTR +="dbname='";
    connectionSTR += dbServerName;
    connectionSTR += "' ";
    connectionSTR +="host='";
    connectionSTR += dbHostAddress;
    connectionSTR += "' ";
    connectionSTR +="port='";
    connectionSTR += port;
    connectionSTR += "' ";
    connectionSTR +="user='";
    connectionSTR += userName;
    connectionSTR += "' ";
    connectionSTR +="passwd='";
    connectionSTR += password;
    connectionSTR += "'";

    dataSource =
OGRSFDriverRegistrar::Open(connectionSTR.c_str(),TRUE,NULL);

-----

dataSource is NULL, the generated connectionSTR is this:
PG:dbname='postgis' host='localhost' port='5432' user='postgres'
passwd='postgres'

where is my fault?

Best regards,
Flavio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/fwtools/attachments/20090707/9c728e9e/attachment.htm 


More information about the FWTools mailing list