grass  7.8.6
About: GRASS (Geographic Resources Analysis Support System) is a raster- and vector-based GIS, image processing system, graphics production system and spatial modeling system.
  Fossies Dox: grass-7.8.6.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

d_fetch.c
Go to the documentation of this file.
1/*!
2 * \file db/dbmi_driver/d_fetch.c
3 *
4 * \brief DBMI Library (driver) - fetch data
5 *
6 * (C) 1999-2008 by the GRASS Development Team
7 *
8 * This program is free software under the GNU General Public
9 * License (>=v2). Read the file COPYING that comes with GRASS
10 * for details.
11 *
12 * \author Joel Jones (CERL/UIUC), Radim Blazek
13 */
14
15#include <grass/dbmi.h>
16#include "macros.h"
17#include "dbstubs.h"
18
19
20static int valid_cursor(dbCursor * cursor, int position);
21
22/*!
23 \brief Fetch data
24
25 \return DB_OK on success
26 \return DB_FAILED on failure
27 */
28int db_d_fetch(void)
29{
30 dbToken token;
31 dbCursor *cursor;
32 int stat;
33 int more;
34 int position;
35
36 /* get the arg(s) */
37 DB_RECV_TOKEN(&token);
38 DB_RECV_INT(&position);
39 cursor = (dbCursor *) db_find_token(token);
40 if (!valid_cursor(cursor, position)) {
42 return DB_FAILED;
43 }
44
45 /* call the procedure */
46 stat = db_driver_fetch(cursor, position, &more);
47
48 /* send the return code */
49 if (stat != DB_OK) {
51 return DB_OK;
52 }
54
55 /* results */
57 if (more) {
59 }
60
61 return DB_OK;
62}
63
64
65static int valid_cursor(dbCursor * cursor, int position)
66{
67 if (cursor == NULL)
68 return 0;
69
70 if (!db_test_cursor_type_fetch(cursor)) {
71 db_error("not a fetchable cursor");
72 return 0;
73 }
74
75 if (position != DB_NEXT && !db_test_cursor_mode_scroll(cursor)) {
76 db_error("not a scrollable cursor");
77 return 0;
78 }
79
80 return 1;
81}
#define NULL
Definition: ccmath.h:32
int db_test_cursor_type_fetch(dbCursor *cursor)
Check cursor type.
Definition: cursor.c:144
int db_test_cursor_mode_scroll(dbCursor *cursor)
Check if cursor mode is 'scroll'.
Definition: cursor.c:250
static int valid_cursor(dbCursor *cursor, int position)
Definition: d_fetch.c:65
int db_d_fetch(void)
Fetch data.
Definition: d_fetch.c:28
void db_error(const char *s)
Report error message.
Definition: error.c:69
dbAddress db_find_token(dbToken token)
Find token.
Definition: token.c:30
int dbToken
Definition: dbmi.h:145
#define DB_FAILED
Definition: dbmi.h:72
#define DB_OK
Definition: dbmi.h:71
#define DB_NEXT
Definition: dbmi.h:114
int(* db_driver_fetch)(dbCursor *, int, int *)
#define DB_SEND_INT(x)
Definition: macros.h:37
#define DB_RECV_INT(x)
Definition: macros.h:39
#define DB_SEND_SUCCESS()
Definition: macros.h:7
#define DB_SEND_TABLE_DATA(x)
Definition: macros.h:67
#define DB_RECV_TOKEN(x)
Definition: macros.h:99
#define DB_SEND_FAILURE()
Definition: macros.h:9
static int more(const char **)
Definition: scan.c:477
dbTable * table
Definition: dbmi.h:234