GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
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 * SPDX-FileCopyrightText: 1999-2008 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author Joel Jones (CERL/UIUC), Radim Blazek
10 */
11
12#include <grass/dbmi.h>
13#include "macros.h"
14#include "dbstubs.h"
15
16static int valid_cursor(dbCursor *cursor, int position);
17
18/*!
19 \brief Fetch data
20
21 \return DB_OK on success
22 \return DB_FAILED on failure
23 */
24int db_d_fetch(void)
25{
26 dbToken token;
28 int stat;
29 int more;
30 int position;
31
32 /* get the arg(s) */
33 DB_RECV_TOKEN(&token);
34 DB_RECV_INT(&position);
35 cursor = (dbCursor *)db_find_token(token);
36 if (!valid_cursor(cursor, position)) {
38 return DB_FAILED;
39 }
40
41 /* call the procedure */
42 stat = db_driver_fetch(cursor, position, &more);
43
44 /* send the return code */
45 if (stat != DB_OK) {
47 return DB_OK;
48 }
50
51 /* results */
52 DB_SEND_INT(more);
53 if (more) {
55 }
56
57 return DB_OK;
58}
59
60static int valid_cursor(dbCursor *cursor, int position)
61{
62 if (cursor == NULL)
63 return 0;
64
66 db_error("not a fetchable cursor");
67 return 0;
68 }
69
70 if (position != DB_NEXT && !db_test_cursor_mode_scroll(cursor)) {
71 db_error("not a scrollable cursor");
72 return 0;
73 }
74
75 return 1;
76}
#define NULL
Definition ccmath.h:32
int db_d_fetch(void)
Fetch data.
Definition d_fetch.c:24
Main header of GRASS DataBase Management Interface.
int dbToken
Definition dbmi.h:143
#define DB_FAILED
Definition dbmi.h:70
#define DB_OK
Definition dbmi.h:69
#define DB_NEXT
Definition dbmi.h:112
int(* db_driver_fetch)(dbCursor *, int, int *)
int db_test_cursor_type_fetch(dbCursor *)
Check cursor type.
Definition cursor.c:141
dbAddress db_find_token(dbToken)
Find token.
void db_error(const char *)
Report error message.
int db_test_cursor_mode_scroll(dbCursor *)
Check if cursor mode is 'scroll'.
Definition cursor.c:246
#define DB_SEND_INT(x)
Definition macros.h:82
#define DB_RECV_INT(x)
Definition macros.h:87
#define DB_SEND_SUCCESS()
Definition macros.h:13
#define DB_SEND_TABLE_DATA(x)
Definition macros.h:148
#define DB_RECV_TOKEN(x)
Definition macros.h:219
#define DB_SEND_FAILURE()
Definition macros.h:18