GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-3a95b7a4e6
c_finddb.c
Go to the documentation of this file.
1 /*!
2  * \file db/dbmi_client/c_finddb.c
3  *
4  * \brief DBMI Library (client) - find database
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 
19 /*!
20  \brief Find database
21 
22  \param driver db driver
23  \param handle handle info
24  \param[out] found if non-zero database found
25 
26  \return DB_OK on success
27  \return DB_FAILED on failure
28  */
29 int db_find_database(dbDriver *driver, dbHandle *handle, int *found)
30 {
31  int ret_code;
32  int stat;
33  dbHandle temp;
34 
35  /* start the procedure call */
36  db__set_protocol_fds(driver->send, driver->recv);
38 
39  /* send the arguments to the procedure */
40  DB_SEND_HANDLE(handle);
41 
42  /* get the return code for the procedure call */
43  DB_RECV_RETURN_CODE(&ret_code);
44 
45  if (ret_code != DB_OK)
46  return ret_code; /* ret_code SHOULD == DB_FAILED */
47 
48  /* get results */
49  DB_RECV_INT(found);
50 
51  stat = DB_OK;
52  if (*found) {
53  DB_RECV_HANDLE(&temp);
54  stat = db_set_handle(handle, db_get_handle_dbname(&temp),
55  db_get_handle_dbschema(&temp));
56  db_free_handle(&temp);
57  }
58  return stat;
59 }
int db_find_database(dbDriver *driver, dbHandle *handle, int *found)
Find database.
Definition: c_finddb.c:29
#define DB_OK
Definition: dbmi.h:71
#define DB_PROC_FIND_DATABASE
Definition: dbmi.h:32
const char * db_get_handle_dbname(dbHandle *)
Get handle database name.
Definition: handle.c:57
int db_set_handle(dbHandle *, const char *, const char *)
Set handle (database and schema name)
Definition: handle.c:39
const char * db_get_handle_dbschema(dbHandle *)
Get handle schema name.
Definition: handle.c:69
void db__set_protocol_fds(FILE *, FILE *)
?
void db_free_handle(dbHandle *)
Free dbHandle structure.
Definition: handle.c:79
#define DB_RECV_INT(x)
Definition: macros.h:87
#define DB_SEND_HANDLE(x)
Definition: macros.h:126
#define DB_START_PROCEDURE_CALL(x)
Definition: macros.h:2
#define DB_RECV_HANDLE(x)
Definition: macros.h:131
#define DB_RECV_RETURN_CODE(x)
Definition: macros.h:7
Definition: driver.h:21