GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
d_insert.c
Go to the documentation of this file.
1 /*!
2  * \file db/dbmi_driver/d_insert.c
3  *
4  * \brief DBMI Library (driver) - insert new record
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 <grass/dbmi.h>
16 #include "macros.h"
17 #include "dbstubs.h"
18 
19 /*!
20  \brief Insert new record into table
21 
22  \return DB_OK on success
23  \return DB_FAILED on failure
24  */
25 int db_d_insert(void)
26 {
27  dbToken token;
28  dbCursor *cursor;
29  int stat;
30 
31  /* get the arg(s) */
32  DB_RECV_TOKEN(&token);
33  cursor = (dbCursor *)db_find_token(token);
34  if (cursor == NULL || !db_test_cursor_type_insert(cursor)) {
35  db_error("** not an insert cursor **");
37  return DB_FAILED;
38  }
39  DB_RECV_TABLE_DATA(cursor->table);
40 
41  /* call the procedure */
42  stat = db_driver_insert(cursor);
43 
44  /* send the return code */
45  if (stat != DB_OK) {
47  return DB_OK;
48  }
50 
51  /* no results */
52  return DB_OK;
53 }
#define NULL
Definition: ccmath.h:32
int db_d_insert(void)
Insert new record into table.
Definition: d_insert.c:25
int dbToken
Definition: dbmi.h:145
#define DB_FAILED
Definition: dbmi.h:72
#define DB_OK
Definition: dbmi.h:71
int(* db_driver_insert)(dbCursor *)
int db_test_cursor_type_insert(dbCursor *)
Check if cursor type is 'insert'.
Definition: cursor.c:171
dbAddress db_find_token(dbToken)
Find token.
void db_error(const char *)
Report error message.
#define DB_RECV_TABLE_DATA(x)
Definition: macros.h:153
#define DB_SEND_SUCCESS()
Definition: macros.h:13
#define DB_RECV_TOKEN(x)
Definition: macros.h:219
#define DB_SEND_FAILURE()
Definition: macros.h:18
dbTable * table
Definition: dbmi.h:224