GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
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 * 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 <stdlib.h>
13#include <grass/dbmi.h>
14#include "macros.h"
15#include "dbstubs.h"
16
17/*!
18 \brief Open update cursor
19
20 \return DB_OK on success
21 \return DB_FAILED on failure
22 */
24{
26 int stat;
27 dbToken token;
28 dbString select;
29 dbString table_name;
30 int mode;
31
32 /* get the arg(s) */
33 db_init_string(&table_name);
34 db_init_string(&select);
35 DB_RECV_STRING(&table_name);
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();
44 if (token < 0)
45 return db_get_error_code();
47
48 /* call the procedure */
49 stat = db_driver_open_update_cursor(&table_name, &select, cursor, mode);
50 db_free_string(&table_name);
51 db_free_string(&select);
52
53 /* send the return code */
54 if (stat != DB_OK) {
56 return DB_OK;
57 }
59
60 /* mark this as an update cursor */
62
63 /* add this cursor to the cursors managed by the driver state */
65
66 /* results */
67 DB_SEND_TOKEN(&token);
68 DB_SEND_INT(cursor->type);
69 DB_SEND_INT(cursor->mode);
71 return DB_OK;
72}
#define NULL
Definition ccmath.h:32
int db_d_open_update_cursor(void)
Open update cursor.
Main header of GRASS DataBase Management Interface.
int dbToken
Definition dbmi.h:143
#define DB_OK
Definition dbmi.h:69
void * dbAddress
Definition dbmi.h:142
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:20
void db_free_string(dbString *)
Free allocated space for dbString.
Definition string.c:148
void db_set_cursor_type_update(dbCursor *)
Set cursor to be writable (update)
Definition cursor.c:118
int db_get_error_code(void)
Get error code.
void db_init_string(dbString *)
Initialize dbString.
Definition string.c:23
void db__add_cursor_to_driver_state(dbCursor *)
Add cursor do driver state.
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