[GRASS-CVS] markus: grass6/db/drivers/postgres Makefile, 1.18.4.2,
1.18.4.3 README, 1.4, 1.4.4.1 db.c, 1.22, 1.22.4.1 describe.c,
1.16, 1.16.4.1 execute.c, 1.9, 1.9.4.1 globals.h, 1.14,
1.14.4.1 grass-pg.html, 1.1.2.2, 1.1.2.3 listtab.c, 1.6, 1.6.4.1
grass at intevation.de
grass at intevation.de
Sat Nov 24 08:19:03 EST 2007
- Previous message: [GRASS-CVS] markus: grass6/db/drivers/sqlite create_table.c, 1.2,
1.2.4.1 db.c, 1.3, 1.3.4.1 describe.c, 1.4.4.2,
1.4.4.3 execute.c, 1.4.4.1, 1.4.4.2 fetch.c, 1.3.4.3,
1.3.4.4 grass-sqlite.html, 1.1.2.3, 1.1.2.4 index.c, 1.2,
1.2.4.1 listtab.c, 1.3.4.1, 1.3.4.2 proto.h, 1.1,
1.1.4.1 select.c, 1.5.4.1, 1.5.4.2
- Next message: [GRASS-CVS] markus: grass6/vector/v.in.ogr main.c, 1.68.4.3,
1.68.4.4
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: markus
Update of /grassrepository/grass6/db/drivers/postgres
In directory doto:/tmp/cvs-serv17498
Modified Files:
Tag: releasebranch_6_2
Makefile README db.c describe.c execute.c globals.h
grass-pg.html listtab.c
Log Message:
PG_TYPE_POSTGIS_GEOM and views backported
Index: Makefile
===================================================================
RCS file: /grassrepository/grass6/db/drivers/postgres/Makefile,v
retrieving revision 1.18.4.2
retrieving revision 1.18.4.3
diff -u -d -r1.18.4.2 -r1.18.4.3
--- Makefile 4 Jul 2007 15:00:32 -0000 1.18.4.2
+++ Makefile 24 Nov 2007 13:19:00 -0000 1.18.4.3
@@ -6,16 +6,16 @@
include $(MODULE_TOPDIR)/include/Make/Grass.make
include $(MODULE_TOPDIR)/include/Make/Rules.make
-DRIVER=$(DBDRIVERDIR)/pg$(EXE_SUFFIX)
+DRIVER=$(DBDRIVERDIR)/pg$(EXE)
LIBES = $(DBMIDRIVERLIB) $(DBMIBASELIB) $(DBMIEXTRALIB) $(SQLPLIB) $(DBSTUBSLIB) \
$(GISLIB) $(DATETIMELIB) $(PQLIB)
EXTRA_CFLAGS = $(PQINCPATH)
-EXTRA_INC = -I$(GRASS_LIBDIR)/db/dbmi_driver
+EXTRA_INC = -I$(MODULE_TOPDIR)/lib/db/dbmi_driver
OBJS = $(subst .c,.o,$(wildcard *.c))
-
+
ARCH_OBJS := $(foreach obj,$(OBJS),$(OBJDIR)/$(obj))
DRVDOC=$(GISBASE)/docs/html/grass-pg.html
@@ -27,4 +27,4 @@
$(MATHLIB) $(XDRLIB)
$(DRVDOC): grass-pg.html
- $(INSTALL) -m 644 grass-pg.html $(DRVDOC)
+ $(INSTALL_DATA) grass-pg.html $(DRVDOC)
Index: README
===================================================================
RCS file: /grassrepository/grass6/db/drivers/postgres/README,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -d -r1.4 -r1.4.4.1
--- README 16 Jun 2006 11:50:28 -0000 1.4
+++ README 24 Nov 2007 13:19:00 -0000 1.4.4.1
@@ -14,7 +14,12 @@
Because of this, type codes must be read from server when database is opened.
-Supported types:
+Check also for PostgreSQL data types for defining them in GRASS:
+ /usr/include/pgsql/server/catalog/pg_type.h
+
+
+Supported types in ./globals.h:
+(http://www.postgresql.org/docs/8.2/interactive/datatype.html)
DB_C_TYPE_INT:
bit, int2, smallint, int4, int, integer, int8, bigint, serial, oid
Index: db.c
===================================================================
RCS file: /grassrepository/grass6/db/drivers/postgres/db.c,v
retrieving revision 1.22
retrieving revision 1.22.4.1
diff -u -d -r1.22 -r1.22.4.1
--- db.c 16 Jun 2006 11:50:28 -0000 1.22
+++ db.c 24 Nov 2007 13:19:00 -0000 1.22.4.1
@@ -81,7 +81,7 @@
"'float4', 'float8', 'numeric', "
"'char', 'bpchar', 'varchar', 'text', "
"'time', 'date', 'timestamp', "
- "'bool' ) order by oid" );
+ "'bool', 'geometry' ) order by oid" );
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) {
append_error ( "Cannot select data types" );
@@ -98,12 +98,12 @@
pgtype = atoi ( PQgetvalue(res, row, 0) );
- pg_types[row][0] = pgtype;
+ pg_types[row][0] = pgtype;
if ( strcmp( PQgetvalue(res, row, 1), "bit" ) == 0 )
type = PG_TYPE_BIT;
else if ( strcmp( PQgetvalue(res, row, 1), "int2" ) == 0 )
- type = PG_TYPE_INT2;
+ type = PG_TYPE_INT2;
else if ( strcmp( PQgetvalue(res, row, 1), "int4" ) == 0 )
type = PG_TYPE_INT4;
else if ( strcmp( PQgetvalue(res, row, 1), "int8" ) == 0 )
@@ -134,6 +134,8 @@
type = PG_TYPE_TIMESTAMP;
else if ( strcmp( PQgetvalue(res, row, 1), "bool" ) == 0 )
type = PG_TYPE_BOOL;
+ else if ( strcmp( PQgetvalue(res, row, 1), "geometry" ) == 0 )
+ type = PG_TYPE_POSTGIS_GEOM;
else
type = PG_TYPE_UNKNOWN;
Index: describe.c
===================================================================
RCS file: /grassrepository/grass6/db/drivers/postgres/describe.c,v
retrieving revision 1.16
retrieving revision 1.16.4.1
diff -u -d -r1.16 -r1.16.4.1
--- describe.c 16 Jun 2006 11:50:28 -0000 1.16
+++ describe.c 24 Nov 2007 13:19:00 -0000 1.16.4.1
@@ -97,9 +97,14 @@
/* PG types defined in globals.h (and pg_type.h) */
if ( sqltype == DB_SQL_TYPE_UNKNOWN ) {
- /* Warn, ignore and continue */
- G_warning ( _("pg driver: column '%s', type %d is not supported"), fname, pgtype);
- continue;
+ if (gpgtype == PG_TYPE_POSTGIS_GEOM) {
+ G_warning ( _("pg driver: PostGIS column '%s', type 'geometry' will not be converted"), fname);
+ continue;
+ } else {
+ /* Warn, ignore and continue */
+ G_warning ( _("pg driver: column '%s', type %d is not supported"), fname, pgtype);
+ continue;
+ }
}
if ( gpgtype == PG_TYPE_INT8 )
Index: execute.c
===================================================================
RCS file: /grassrepository/grass6/db/drivers/postgres/execute.c,v
retrieving revision 1.9
retrieving revision 1.9.4.1
diff -u -d -r1.9 -r1.9.4.1
--- execute.c 9 Feb 2006 03:08:49 -0000 1.9
+++ execute.c 24 Nov 2007 13:19:00 -0000 1.9.4.1
@@ -1,3 +1,16 @@
+/****************************************************************************
+ *
+ * MODULE: execute
+ * AUTHOR(S): Alex Shevlakov <sixote yahoo.com> (original contributor)
+ * Huidae Cho <grass4u gmail.com>, Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>, Radim Blazek <radim.blazek gmail.com>
+ * PURPOSE: PostgreSQL driver
+ * COPYRIGHT: (C) 2002-2006 by the GRASS Development Team
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
#include <stdlib.h>
#include <grass/dbmi.h>
#include <grass/gis.h>
Index: globals.h
===================================================================
RCS file: /grassrepository/grass6/db/drivers/postgres/globals.h,v
retrieving revision 1.14
retrieving revision 1.14.4.1
diff -u -d -r1.14 -r1.14.4.1
--- globals.h 16 Jun 2006 11:50:28 -0000 1.14
+++ globals.h 24 Nov 2007 13:19:00 -0000 1.14.4.1
@@ -15,7 +15,11 @@
char *host, *port, *options, *tty, *dbname, *user, *password, *schema;
} PGCONN;
-/* Postgres data types defined in GRASS, see pg_type.h */
+/* PostgreSQL data types defined in GRASS
+ (see also: /usr/include/pgsql/server/catalog/pg_type.h)
+ PostGIS types are encoded as 17xxx.
+ Types/OIDs are fetched in db.c from server.
+ */
typedef enum { /* name in pg_type, aliases */
PG_TYPE_UNKNOWN, /* all types not supported by GRASS */
@@ -39,7 +43,9 @@
PG_TYPE_TIME, /* time */
PG_TYPE_TIMESTAMP, /* timestamp */
- PG_TYPE_BOOL /* bool, boolean */
+ PG_TYPE_BOOL, /* bool, boolean */
+
+ PG_TYPE_POSTGIS_GEOM /* Geometry column of PostGIS, GRASS internal type */
} PG_TYPES;
Index: grass-pg.html
===================================================================
RCS file: /grassrepository/grass6/db/drivers/postgres/grass-pg.html,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
--- grass-pg.html 24 Nov 2007 12:41:10 -0000 1.1.2.2
+++ grass-pg.html 24 Nov 2007 13:19:00 -0000 1.1.2.3
@@ -8,7 +8,7 @@
<body bgcolor="white">
-<img src="grass.smlogo.gif" alt="GRASS logo"><hr align=center size=6 noshade>
+<img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
<h1>PostgreSQL driver in GRASS</h1>
@@ -91,7 +91,7 @@
VALUES ('Name',geometryFromText('POLYGON((600000 200000,650000
200000,650000 250000,600000 250000,600000 200000))',-1));
-# register the table with geometry
+# register geometry column
select AddGeometryColumn ('postgis', 'test', 'geometry', -1, 'GEOMETRY', 2);
</pre></div>
@@ -123,6 +123,7 @@
<H2>SEE ALSO</H2>
<em>
+<a HREF="db.connect.html">db.connect</a>,
<a HREF="db.execute.html">db.execute</a>,<BR>
<a HREF="databaseintro.html">Database management in GRASS GIS</a>,<BR>
<a HREF="database.html">Help pages for database modules</a>,<BR>
Index: listtab.c
===================================================================
RCS file: /grassrepository/grass6/db/drivers/postgres/listtab.c,v
retrieving revision 1.6
retrieving revision 1.6.4.1
diff -u -d -r1.6 -r1.6.4.1
--- listtab.c 9 Feb 2006 03:08:49 -0000 1.6
+++ listtab.c 24 Nov 2007 13:19:00 -0000 1.6.4.1
@@ -7,37 +7,66 @@
int db__driver_list_tables (dbString **tlist, int *tcount, int system)
{
- int i, nrows, ncols, tablecol, schemacol;
+ int i, nrows, trows, vrows, ncols, tablecol, tschemacol, viewcol, vschemacol;
dbString *list;
- PGresult *res;
+ PGresult *rest, *resv;
char buf[1000];
init_error();
*tlist = NULL;
*tcount = 0;
- res = PQexec(pg_conn, "select * from pg_tables where tablename !~ 'pg_*' order by tablename");
+
+ /* Get table names */
+ rest = PQexec(pg_conn, "select * from pg_tables where tablename !~ 'pg_*' order by tablename");
- if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) {
+ if (!rest || PQresultStatus(rest) != PGRES_TUPLES_OK) {
append_error ( "Cannot select table names\n" );
append_error ( PQerrorMessage(pg_conn) );
report_error();
- PQclear(res);
+ PQclear(rest);
return DB_FAILED;
}
/* Find table and schema col */
- ncols = PQnfields(res);
- schemacol = -1;
+ ncols = PQnfields(rest);
+ tschemacol = -1;
for (i = 0; i < ncols; i++) {
- if ( strcmp(PQfname(res, i),"tablename") == 0 )
+ if ( strcmp(PQfname(rest, i),"tablename") == 0 )
tablecol = i;
- if ( strcmp(PQfname(res, i),"schemaname") == 0 )
- schemacol = i;
+ if ( strcmp(PQfname(rest, i),"schemaname") == 0 )
+ tschemacol = i;
}
- nrows = PQntuples(res);
+
+ /* Get view names */
+ resv = PQexec(pg_conn, "SELECT * FROM pg_views WHERE schemaname NOT IN ('pg_catalog','information_schema') AND viewname !~ '^pg_'");
+
+ if (!resv || PQresultStatus(resv) != PGRES_TUPLES_OK) {
+ append_error ( "Cannot select view names\n" );
+ append_error ( PQerrorMessage(pg_conn) );
+ report_error();
+ PQclear(resv);
+ return DB_FAILED;
+ }
+
+ /* Find viewname and schema col */
+ ncols = PQnfields(resv);
+ vschemacol = -1;
+ for (i = 0; i < ncols; i++) {
+ if ( strcmp(PQfname(resv, i),"viewname") == 0 )
+ viewcol = i;
+
+ if ( strcmp(PQfname(resv, i),"schemaname") == 0 )
+ vschemacol = i;
+ }
+
+
+
+ trows = PQntuples(rest);
+ vrows = PQntuples(resv);
+ nrows = trows + vrows;
list = db_alloc_string_array(nrows);
@@ -47,17 +76,31 @@
return DB_FAILED;
}
- for (i = 0; i < nrows; i++) {
- if ( schemacol >= 0 ) {
- sprintf ( buf, "%s.%s", (char *) PQgetvalue(res, i, schemacol),
- (char *) PQgetvalue(res, i, tablecol) );
+ for (i = 0; i < trows; i++) {
+ if ( tschemacol >= 0 ) {
+ sprintf ( buf, "%s.%s", (char *) PQgetvalue(rest, i, tschemacol),
+ (char *) PQgetvalue(rest, i, tablecol) );
} else {
- sprintf ( buf, "%s", (char *) PQgetvalue(res, i, tablecol) );
+ sprintf ( buf, "%s", (char *) PQgetvalue(rest, i, tablecol) );
}
db_set_string(&list[i], buf );
}
- PQclear(res);
+ PQclear(rest);
+
+
+ for (i = 0; i < vrows; i++) {
+ if ( vschemacol >= 0 ) {
+ sprintf ( buf, "%s.%s", (char *) PQgetvalue(resv, i, vschemacol),
+ (char *) PQgetvalue(resv, i, viewcol) );
+ } else {
+ sprintf ( buf, "%s", (char *) PQgetvalue(resv, i, viewcol) );
+ }
+ db_set_string(&list[i], buf );
+ }
+
+ PQclear(resv);
+
*tlist = list;
*tcount = nrows;
- Previous message: [GRASS-CVS] markus: grass6/db/drivers/sqlite create_table.c, 1.2,
1.2.4.1 db.c, 1.3, 1.3.4.1 describe.c, 1.4.4.2,
1.4.4.3 execute.c, 1.4.4.1, 1.4.4.2 fetch.c, 1.3.4.3,
1.3.4.4 grass-sqlite.html, 1.1.2.3, 1.1.2.4 index.c, 1.2,
1.2.4.1 listtab.c, 1.3.4.1, 1.3.4.2 proto.h, 1.1,
1.1.4.1 select.c, 1.5.4.1, 1.5.4.2
- Next message: [GRASS-CVS] markus: grass6/vector/v.in.ogr main.c, 1.68.4.3,
1.68.4.4
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the grass-commit
mailing list