GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
d_fetch.c
Go to the documentation of this file.
1 
15 #include <grass/dbmi.h>
16 #include "macros.h"
17 #include "dbstubs.h"
18 
19 
20 static int valid_cursor(dbCursor * cursor, int position);
21 
28 int 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 */
56  DB_SEND_INT(more);
57  if (more) {
58  DB_SEND_TABLE_DATA(cursor->table);
59  }
60 
61  return DB_OK;
62 }
63 
64 
65 static 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 }
int db_test_cursor_mode_scroll(dbCursor *cursor)
Definition: cursor.c:231
dbAddress db_find_token(dbToken token)
#define DB_SEND_TABLE_DATA(x)
Definition: macros.h:67
#define DB_SEND_INT(x)
Definition: macros.h:37
#define DB_RECV_INT(x)
Definition: macros.h:39
#define DB_RECV_TOKEN(x)
Definition: macros.h:99
int(* db_driver_fetch)()
void db_error(const char *s)
int stat
Definition: g3dcolor.c:369
#define DB_SEND_FAILURE()
Definition: macros.h:9
return NULL
Definition: dbfopen.c:1394
int db_test_cursor_type_fetch(dbCursor *cursor)
Definition: cursor.c:132
#define DB_SEND_SUCCESS()
Definition: macros.h:7
int db_d_fetch(void)
Fetch data.
Definition: d_fetch.c:28