GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
rewind_pg.c
Go to the documentation of this file.
1 /*!
2  \file lib/vector/Vlib/rewind_pg.c
3 
4  \brief Vector library - rewind data (PostGIS layers)
5 
6  Higher level functions for reading/writing/manipulating vectors.
7 
8  (C) 2011-2012 by the GRASS Development Team
9 
10  This program is free software under the GNU General Public License
11  (>=v2). Read the file COPYING that comes with GRASS for details.
12 
13  \author Martin Landa <landa.martin gmail.com>
14  */
15 
16 #include <grass/vector.h>
17 #include <grass/glocale.h>
18 
19 #include "local_proto.h"
20 
21 #ifdef HAVE_POSTGRES
22 #include "pg_local_proto.h"
23 #endif
24 
25 /*!
26  \brief Rewind vector map (PostGIS layer) to cause reads to start
27  at beginning (level 1)
28 
29  \param Map pointer to Map_info structure
30 
31  \return 0 on success
32  \return -1 on error
33  */
34 int V1_rewind_pg(struct Map_info *Map)
35 {
36  G_debug(2, "V1_rewind_pg(): name = %s", Map->name);
37 
38 #ifdef HAVE_POSTGRES
39  struct Format_info_pg *pg_info;
40 
41  pg_info = &(Map->fInfo.pg);
42 
43  /* reset reading */
44  pg_info->next_line = 0;
45 
46  /* reset cache */
47  if (pg_info->cache.ctype != CACHE_MAP) {
48  pg_info->cache.lines_num = 0;
49  pg_info->cache.fid = -1;
50  }
51  pg_info->cache.lines_next = 0;
52 
53  /* close DB cursor if necessary */
54  return Vect__close_cursor_pg(pg_info);
55 #else
56  G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
57  return -1;
58 #endif
59 }
60 
61 /*!
62  \brief Rewind vector map (PostGIS layer) to cause reads to start
63  at beginning on topological level (level 2)
64 
65  \param Map pointer to Map_info structure
66 
67  \return 0 on success
68  \return -1 on error
69  */
70 int V2_rewind_pg(struct Map_info *Map)
71 {
72  G_debug(2, "V2_rewind_pg(): name = %s", Map->name);
73 #ifdef HAVE_POSTGRES
74  /* reset reading */
75  Map->next_line = 1;
76 
77  V1_rewind_pg(Map);
78 
79  return 0;
80 #else
81  G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
82  return -1;
83 #endif
84 }
char * name
Map name (for 4.0)
Definition: dig_structs.h:1332
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int V1_rewind_pg(struct Map_info *Map)
Rewind vector map (PostGIS layer) to cause reads to start at beginning (level 1)
Definition: rewind_pg.c:34
long fid
Feature id.
Definition: dig_structs.h:497
struct Format_info fInfo
Format info for non-native formats.
Definition: dig_structs.h:1415
int lines_num
Number of lines which forms current feature.
Definition: dig_structs.h:489
plus_t next_line
Feature id for sequential access.
Definition: dig_structs.h:1353
int ctype
Cache type.
Definition: dig_structs.h:507
Non-native format info (PostGIS)
Definition: dig_structs.h:602
struct Format_info_cache cache
Lines cache for reading feature.
Definition: dig_structs.h:683
int Vect__close_cursor_pg(struct Format_info_pg *pg_info)
Close select cursor.
Definition: read_pg.c:1408
struct Format_info_pg pg
PostGIS info.
Definition: dig_structs.h:726
int next_line
Next line to be read.
Definition: dig_structs.h:678
int V2_rewind_pg(struct Map_info *Map)
Rewind vector map (PostGIS layer) to cause reads to start at beginning on topological level (level 2)...
Definition: rewind_pg.c:70
Vector map info.
Definition: dig_structs.h:1259
int lines_next
Next line to be read from cache.
Definition: dig_structs.h:493
#define _(str)
Definition: glocale.h:10
int G_debug(int, const char *,...) __attribute__((format(printf