globals.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <libpq-fe.h>
  2. /* cursors */
  3. typedef struct _cursor
  4. {
  5. PGresult *res;
  6. int nrows; /* number of rows in query result */
  7. int row; /* current row */
  8. dbToken token;
  9. int type; /* type of cursor: SELECT, UPDATE, INSERT */
  10. int *cols; /* indexes of known (type) columns */
  11. int ncols; /* number of known columns */
  12. } cursor;
  13. typedef struct
  14. {
  15. char *host, *port, *options, *tty, *dbname, *user, *password, *schema;
  16. } PGCONN;
  17. /* PostgreSQL data types defined in GRASS
  18. (see also: /usr/include/pgsql/server/catalog/pg_type.h)
  19. PostGIS types are encoded as 17xxx.
  20. Types/OIDs are fetched in db.c from server.
  21. */
  22. typedef enum
  23. { /* name in pg_type, aliases */
  24. PG_TYPE_UNKNOWN, /* all types not supported by GRASS */
  25. PG_TYPE_BIT, /* bit */
  26. PG_TYPE_INT2, /* int2, smallint */
  27. PG_TYPE_INT4, /* int4, integer, int */
  28. PG_TYPE_INT8, /* int8, bigint */
  29. PG_TYPE_SERIAL, /* serial */
  30. PG_TYPE_OID, /* oid */
  31. PG_TYPE_FLOAT4, /* float4, real */
  32. PG_TYPE_FLOAT8, /* float8, double precision */
  33. PG_TYPE_NUMERIC, /* numeric, decimal */
  34. PG_TYPE_CHAR, /* char, character */
  35. PG_TYPE_BPCHAR, /* ??? blank padded character, oid of this type is returned for char fields */
  36. PG_TYPE_VARCHAR, /* varchar, character varying */
  37. PG_TYPE_TEXT, /* text */
  38. PG_TYPE_DATE, /* date */
  39. PG_TYPE_TIME, /* time */
  40. PG_TYPE_TIMESTAMP, /* timestamp */
  41. PG_TYPE_BOOL, /* bool, boolean */
  42. PG_TYPE_POSTGIS_GEOM /* Geometry column of PostGIS, GRASS internal type */
  43. } PG_TYPES;
  44. #ifdef MAIN
  45. PGconn *pg_conn; /* Database connection */
  46. int (*pg_types)[2] = NULL; /* array of types, first is internal code, second PG_TYPE_* */
  47. int pg_ntypes = 0;
  48. dbString *errMsg = NULL; /* error message */
  49. #else
  50. extern PGconn *pg_conn;
  51. extern dbString *errMsg;
  52. extern int (*pg_types)[2];
  53. extern int pg_ntypes;
  54. #endif