GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
xdrindex.c
Go to the documentation of this file.
1 /*!
2  \file lib/db/dbmi_base/xdrindex.c
3 
4  \brief DBMI Library (base) - external data representation (index)
5 
6  (C) 1999-2009, 2011 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Joel Jones (CERL/UIUC), Radim Blazek, Brad Douglas, Markus Neteler
12  \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
13 */
14 
15 #include <grass/dbmi.h>
16 #include "macros.h"
17 
18 
19 /*!
20  \brief Send index
21 
22  \param index
23 
24  \return
25 */
26 int db__send_index(dbIndex * index)
27 {
28  int i;
29 
30  DB_SEND_STRING(&index->indexName);
31  DB_SEND_STRING(&index->tableName);
32  DB_SEND_CHAR(index->unique);
33 
34  DB_SEND_INT(index->numColumns);
35 
36  for (i = 0; i < index->numColumns; i++) {
37  DB_SEND_STRING(&index->columnNames[i]);
38  }
39 
40  return DB_OK;
41 }
42 
43 /*!
44  \brief Send index array
45 
46  \param list
47  \param count
48 
49  \return
50 */
52 {
53  int i;
54 
55  DB_SEND_INT(count);
56  for (i = 0; i < count; i++) {
57  DB_SEND_INDEX(&list[i]);
58  }
59  return DB_OK;
60 }
61 
62 /*!
63  \brief Receive index
64 
65  \param index
66 
67  \return
68 */
69 int db__recv_index(dbIndex * index)
70 {
71  int i, ncols;
72 
73  db_init_index(index);
74  DB_RECV_STRING(&index->indexName);
75  DB_RECV_STRING(&index->tableName);
76  DB_RECV_CHAR(&index->unique);
77 
78  DB_RECV_INT(&ncols);
79 
80  if (db_alloc_index_columns(index, ncols) != DB_OK)
81  return db_get_error_code();
82 
83  for (i = 0; i < ncols; i++) {
84  DB_RECV_STRING(&index->columnNames[i]);
85  }
86 
87  return DB_OK;
88 }
89 
90 /*!
91  \brief Receive index array
92 
93  \param list
94  \param count
95 */
97 {
98  int i;
99 
100  DB_RECV_INT(count);
101 
102  *list = db_alloc_index_array(*count);
103  if (*list == NULL)
104  return db_get_error_code();
105 
106  for (i = 0; i < *count; i++) {
107  DB_RECV_INDEX(&((*list)[i]));
108  }
109 
110  return DB_OK;
111 }
#define DB_SEND_CHAR(x)
Definition: macros.h:23
#define DB_SEND_INT(x)
Definition: macros.h:37
#define DB_RECV_INT(x)
Definition: macros.h:39
int count
int numColumns
Definition: dbmi.h:244
dbString indexName
Definition: dbmi.h:242
#define NULL
Definition: ccmath.h:32
dbIndex * db_alloc_index_array(int)
Allocate index array.
int db__recv_index_array(dbIndex **list, int *count)
Receive index array.
Definition: xdrindex.c:96
#define DB_SEND_INDEX(x)
Definition: macros.h:102
int db_alloc_index_columns(dbIndex *, int)
Allocate index columns.
int db__send_index_array(dbIndex *list, int count)
Send index array.
Definition: xdrindex.c:51
int db__send_index(dbIndex *index)
Send index.
Definition: xdrindex.c:26
#define DB_RECV_CHAR(x)
Definition: macros.h:25
int db_get_error_code(void)
Get error code.
char unique
Definition: dbmi.h:246
#define DB_SEND_STRING(x)
Definition: macros.h:12
dbString tableName
Definition: dbmi.h:243
#define DB_RECV_INDEX(x)
Definition: macros.h:106
void db_init_index(dbIndex *)
Initialize dbIndex.
Definition: manage.h:4
int db__recv_index(dbIndex *index)
Receive index.
Definition: xdrindex.c:69
#define DB_RECV_STRING(x)
Definition: macros.h:18
#define DB_OK
Definition: dbmi.h:71
dbString * columnNames
Definition: dbmi.h:245