[postgis-users] libpg

Marshall, Steve smarshall at wsi.com
Fri Nov 10 10:02:10 PST 2006


The second argument to the lo_creat call should be flags for read/write access mode.  1 is not a valid value.

Replace this will the symbolic constants INV_READ|INV_WRITE, which are specified in the postgresql header file libpq-fs.h.

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Ricardo
Sent: Friday, November 10, 2006 12:48 PM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] libpg

Hi all,

I'm trying to wirite a file from a odi field of my data base with the folwing source code:

-----------------------------------------------------------------------------
------------------------------------------------
1   const char *conninfo = "Driver=PostgreSQL Unicode; Server=10.0.0.62; 
Database=energia; user=postgres; password=postgres";
2   PGconn     *conn;
3   PGresult   *res;
4   Oid inv_oid;
5	int r = 1;
6	int lobj_fd;// = lo_open(conn, inv_oid, 1);
7	int         fd;
8    char        buf[300000];
9    int         nbytes,  tmp;
10	FILE* fp;
11	/* Make a connection to the database */
12    conn = PQconnectdb(conninfo);
13    inv_oid = lo_creat(conn, 1);
14    res = PQexec(conn, "SELECT imagem FROM raster");      /* ask for 
binary results */
15	lobj_fd = lo_open(conn, inv_oid, 1);
16	fp = fopen("test.tif", "wt");
17    while ((nbytes = lo_read(conn, lobj_fd, buf, 300000)) > 0)
18    {
19       tmp = fwrite(&buf, sizeof(buf), 1, fp);
20    }
21    (void) lo_close(conn, lobj_fd);
22    (void) fclose(fp);

-----------------------------------------------------------------------------
-------------------------------------------------

The query on the line 14 has been applied over the folwing table:
-----------------------------------------------------------------------------
-------------------------------------------------


CREATE TABLE raster
(
  name varchar(30),
  imagem oid,
  geometria geometry,
  CONSTRAINT enforce_dims_geometria CHECK (ndims(geometria) = 3),
  CONSTRAINT enforce_srid_geometria CHECK (srid(geometria) = -1)
)
WITH OIDS;

-----------------------------------------------------------------------------
-------------------------------------------------

So evry time on the line 15 the value -1 was returned to lobj_fd variable;

Forgot I something?
What is the problem with that code?
Where can I get references or samples to do that?

Thank you all.

Ricardo Luís.
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list