GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
d_openupdate.c
Go to the documentation of this file.
1 /*!
2  * \file db/dbmi_driver/d_openupdate.c
3  *
4  * \brief DBMI Library (driver) - open update 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 update 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  dbString table_name;
33  int mode;
34 
35  /* get the arg(s) */
36  db_init_string(&table_name);
37  db_init_string(&select);
38  DB_RECV_STRING(&table_name);
39  DB_RECV_STRING(&select);
40  DB_RECV_INT(&mode);
41 
42  /* create a cursor */
43  cursor = (dbCursor *)db_malloc(sizeof(dbCursor));
44  if (cursor == NULL)
45  return db_get_error_code();
46  token = db_new_token((dbAddress)cursor);
47  if (token < 0)
48  return db_get_error_code();
49  db_init_cursor(cursor);
50 
51  /* call the procedure */
52  stat = db_driver_open_update_cursor(&table_name, &select, cursor, mode);
53  db_free_string(&table_name);
54  db_free_string(&select);
55 
56  /* send the return code */
57  if (stat != DB_OK) {
59  return DB_OK;
60  }
62 
63  /* mark this as an update cursor */
65 
66  /* add this cursor to the cursors managed by the driver state */
68 
69  /* results */
70  DB_SEND_TOKEN(&token);
71  DB_SEND_INT(cursor->type);
72  DB_SEND_INT(cursor->mode);
74  return DB_OK;
75 }
#define NULL
Definition: ccmath.h:32
int db_d_open_update_cursor(void)
Open update cursor.
Definition: d_openupdate.c:26
int dbToken
Definition: dbmi.h:145
#define DB_OK
Definition: dbmi.h:71
void * dbAddress
Definition: dbmi.h:144
int(* db_driver_open_update_cursor)(dbString *, dbString *, dbCursor *, int)
dbToken db_new_token(dbAddress)
Add new token.
void db_init_cursor(dbCursor *)
Initialize dbCursor.
Definition: cursor.c:23
void db_free_string(dbString *)
Free allocated space for dbString.
Definition: string.c:150
void db_set_cursor_type_update(dbCursor *)
Set cursor to be writable (update)
Definition: cursor.c:121
int db_get_error_code(void)
Get error code.
void db_init_string(dbString *)
Initialize dbString.
Definition: string.c:25
void db__add_cursor_to_driver_state(dbCursor *)
Add cursor do driver state.
Definition: driver_state.c:78
void * db_malloc(int)
Allocate memory.
#define DB_SEND_TABLE_DEFINITION(x)
Definition: macros.h:137
#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_RECV_STRING(x)
Definition: macros.h:39
#define DB_SEND_TOKEN(x)
Definition: macros.h:214
#define DB_SEND_FAILURE()
Definition: macros.h:18
int mode
Definition: dbmi.h:227
dbTable * table
Definition: dbmi.h:224
int type
Definition: dbmi.h:226