GRASS 8 Programmer's Manual 8.6.0dev(2026)-c83afef6d3
Loading...
Searching...
No Matches
handle.c
Go to the documentation of this file.
1/*!
2 \file lib/db/dbmi_base/handle.c
3
4 \brief DBMI Library (base) - handle management
5
6 SPDX-FileCopyrightText: 1999-2009 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
15/*!
16 \brief Initialize handle (i.e database/schema)
17
18 \param handle pointer to dbHandle to be initialized
19 */
21{
22 db_init_string(&handle->dbName);
23 db_init_string(&handle->dbSchema);
24}
25
26/*!
27 \brief Set handle (database and schema name)
28
29 \param handle pointer to dbHandle
30 \param dbName database name
31 \param dbSchema schema name
32
33 \return DB_OK on success
34 \return DB_FAILED on failure
35 */
36int db_set_handle(dbHandle *handle, const char *dbName, const char *dbSchema)
37{
38 int stat;
39
40 stat = db_set_string(&handle->dbName, dbName);
41 if (stat != DB_OK)
42 return stat;
43 stat = db_set_string(&handle->dbSchema, dbSchema);
44 return stat;
45}
46
47/*!
48 \brief Get handle database name
49
50 \param handle pointer to dbHandle
51
52 \return pointer to string with database name
53 */
54const char *db_get_handle_dbname(dbHandle *handle)
55{
56 return db_get_string(&handle->dbName);
57}
58
59/*!
60 \brief Get handle schema name
61
62 \param handle pointer to dbHandle
63
64 \return pointer to string with schema name
65 */
66const char *db_get_handle_dbschema(dbHandle *handle)
67{
68 return db_get_string(&handle->dbSchema);
69}
70
71/*!
72 \brief Free dbHandle structure
73
74 \param handle pointer to dbHandle
75 */
77{
78 db_free_string(&handle->dbName);
79 db_free_string(&handle->dbSchema);
80}
81
82/*!
83 \brief Free array of handles
84
85 \param handle pointer to first dbHandle in the array
86 \param count number of handles in the array
87 */
88void db_free_handle_array(dbHandle *handle, int count)
89{
90 int i;
91
92 if (handle) {
93 for (i = 0; i < count; i++)
94 db_free_handle(&handle[i]);
95 db_free((void *)handle);
96 }
97}
98
99/*!
100 \brief Allocate array of handles
101
102 \param count number of handles in the array
103
104 \return pointer to first dbHandle in the array
105 */
107{
108 int i;
109 dbHandle *handle;
110
111 handle = (dbHandle *)db_calloc(count, sizeof(dbHandle));
112 if (handle)
113 for (i = 0; i < count; i++)
114 db_init_handle(&handle[i]);
115 return handle;
116}
Main header of GRASS DataBase Management Interface.
#define DB_OK
Definition dbmi.h:69
void db_free_string(dbString *)
Free allocated space for dbString.
Definition string.c:148
void * db_calloc(int, int)
Allocate memory.
char * db_get_string(const dbString *)
Get string.
Definition string.c:138
int db_set_string(dbString *, const char *)
Inserts string to dbString (enlarge string)
Definition string.c:39
void db_free(void *)
Free allocated memory.
void db_init_string(dbString *)
Initialize dbString.
Definition string.c:23
const char * db_get_handle_dbschema(dbHandle *handle)
Get handle schema name.
Definition handle.c:66
const char * db_get_handle_dbname(dbHandle *handle)
Get handle database name.
Definition handle.c:54
dbHandle * db_alloc_handle_array(int count)
Allocate array of handles.
Definition handle.c:106
void db_free_handle_array(dbHandle *handle, int count)
Free array of handles.
Definition handle.c:88
void db_init_handle(dbHandle *handle)
Initialize handle (i.e database/schema)
Definition handle.c:20
void db_free_handle(dbHandle *handle)
Free dbHandle structure.
Definition handle.c:76
int db_set_handle(dbHandle *handle, const char *dbName, const char *dbSchema)
Set handle (database and schema name)
Definition handle.c:36
int count
dbString dbSchema
Definition dbmi.h:172
dbString dbName
Definition dbmi.h:170