GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
d_openselect.c
Go to the documentation of this file.
1 /*!
2  * \file db/dbmi_driver/d_openselect.c
3  *
4  * \brief DBMI Library (driver) - open select cursor
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 <stdlib.h>
16 #include <grass/dbmi.h>
17 #include "macros.h"
18 #include "dbstubs.h"
19 
20 /*!
21  \brief Open select cursor
22 
23  \return DB_OK on success
24  \return DB_FAILED on failure
25  */
27 {
28  dbCursor *cursor;
29  int stat;
30  dbToken token;
31  dbString select;
32  int mode;
33 
34  /* get the arg(s) */
35  db_init_string(&select);
36  DB_RECV_STRING(&select);
37  DB_RECV_INT(&mode);
38 
39  /* create a cursor */
40  cursor = (dbCursor *) db_malloc(sizeof(dbCursor));
41  if (cursor == NULL)
42  return db_get_error_code();
43  token = db_new_token((dbAddress) cursor);
44  if (token < 0)
45  return db_get_error_code();
46  db_init_cursor(cursor);
47 
48  /* call the procedure */
49  stat = db_driver_open_select_cursor(&select, cursor, mode);
50  db_free_string(&select);
51 
52  /* send the return code */
53  if (stat != DB_OK) {
55  return DB_OK;
56  }
58 
59  /* mark this as a readonly cursor */
61 
62  /* add this cursor to the cursors managed by the driver state */
64 
65  /* results */
66  DB_SEND_TOKEN(&token);
67  DB_SEND_INT(cursor->type);
68  DB_SEND_INT(cursor->mode);
69  DB_SEND_TABLE_DEFINITION(cursor->table);
70  return DB_OK;
71 }
#define DB_SEND_INT(x)
Definition: macros.h:37
void db_init_string(dbString *)
Initialize dbString.
Definition: string.c:25
#define DB_RECV_INT(x)
Definition: macros.h:39
int(* db_driver_open_select_cursor)(dbString *, dbCursor *, int)
int dbToken
Definition: dbmi.h:145
#define NULL
Definition: ccmath.h:32
dbToken db_new_token(dbAddress)
Add new token.
void db__add_cursor_to_driver_state(dbCursor *)
Add cursor do driver state.
Definition: driver_state.c:79
void * dbAddress
Definition: dbmi.h:144
int db_get_error_code(void)
Get error code.
#define DB_SEND_FAILURE()
Definition: macros.h:9
void db_init_cursor(dbCursor *)
Initialize dbCursor.
Definition: cursor.c:23
#define DB_SEND_TABLE_DEFINITION(x)
Definition: macros.h:62
void db_set_cursor_type_readonly(dbCursor *)
Set cursor to be read-only (select)
Definition: cursor.c:111
#define DB_SEND_TOKEN(x)
Definition: macros.h:97
void * db_malloc(int)
Allocate memory.
#define DB_SEND_SUCCESS()
Definition: macros.h:7
int db_d_open_select_cursor(void)
Open select cursor.
Definition: d_openselect.c:26
void db_free_string(dbString *)
Free allocated space for dbString.
Definition: string.c:150
#define DB_RECV_STRING(x)
Definition: macros.h:18
#define DB_OK
Definition: dbmi.h:71