GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-535c39c9fc
c_openselect.c
Go to the documentation of this file.
1 /*!
2  \file db/dbmi_client/c_openselect.c
3 
4  \brief DBMI Library (client) - open select cursor
5 
6  (C) 1999-2008, 2012 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)
13  \author Radim Blazek
14  */
15 
16 #include <grass/dbmi.h>
17 #include "macros.h"
18 
19 /*!
20  \brief Open select cursor
21 
22  Open modes:
23  - DB_SEQUENTIAL
24 
25  Data can be fetched by db_fetch().
26 
27  Cursor should be closed by db_close_cursor().
28 
29  \param driver pointer to dbDriver
30  \param select SQL select statement (pointer to dbString)
31  \param cursor pointer to dbCursor to be opened
32  \param mode open mode
33 
34  \return DB_OK on success
35  \return DB_FAILED on failure
36  */
38  int mode)
39 {
40  int ret_code;
41 
42  db_init_cursor(cursor);
43  cursor->driver = driver;
44 
45  /* start the procedure call */
46  db__set_protocol_fds(driver->send, driver->recv);
48 
49  /* send the argument(s) to the procedure */
50  DB_SEND_STRING(select);
51  DB_SEND_INT(mode);
52 
53  /* get the return code for the procedure call */
54  DB_RECV_RETURN_CODE(&ret_code);
55 
56  if (ret_code != DB_OK)
57  return ret_code; /* ret_code SHOULD == DB_FAILED */
58 
59  /* get the results */
60  DB_RECV_TOKEN(&cursor->token);
61  DB_RECV_INT(&cursor->type);
62  DB_RECV_INT(&cursor->mode);
64  return DB_OK;
65 }
int db_open_select_cursor(dbDriver *driver, dbString *select, dbCursor *cursor, int mode)
Open select cursor.
Definition: c_openselect.c:37
#define DB_PROC_OPEN_SELECT_CURSOR
Definition: dbmi.h:42
#define DB_OK
Definition: dbmi.h:71
void db_init_cursor(dbCursor *)
Initialize dbCursor.
Definition: cursor.c:23
void db__set_protocol_fds(FILE *, FILE *)
?
const struct driver * driver
Definition: driver/init.c:25
#define DB_SEND_STRING(x)
Definition: macros.h:24
#define DB_SEND_INT(x)
Definition: macros.h:82
#define DB_RECV_TABLE_DEFINITION(x)
Definition: macros.h:142
#define DB_RECV_INT(x)
Definition: macros.h:87
#define DB_RECV_TOKEN(x)
Definition: macros.h:219
#define DB_START_PROCEDURE_CALL(x)
Definition: macros.h:2
#define DB_RECV_RETURN_CODE(x)
Definition: macros.h:7
dbDriver * driver
Definition: dbmi.h:223
int mode
Definition: dbmi.h:227
dbTable * table
Definition: dbmi.h:224
int type
Definition: dbmi.h:226
dbToken token
Definition: dbmi.h:222
Definition: driver.h:21