GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
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  \brief Send index
20 
21  \param index
22 
23  \return
24  */
26 {
27  int i;
28 
29  DB_SEND_STRING(&index->indexName);
30  DB_SEND_STRING(&index->tableName);
31  DB_SEND_CHAR(index->unique);
32 
33  DB_SEND_INT(index->numColumns);
34 
35  for (i = 0; i < index->numColumns; i++) {
36  DB_SEND_STRING(&index->columnNames[i]);
37  }
38 
39  return DB_OK;
40 }
41 
42 /*!
43  \brief Send index array
44 
45  \param list
46  \param count
47 
48  \return
49  */
51 {
52  int i;
53 
55  for (i = 0; i < count; i++) {
56  DB_SEND_INDEX(&list[i]);
57  }
58  return DB_OK;
59 }
60 
61 /*!
62  \brief Receive index
63 
64  \param index
65 
66  \return
67  */
69 {
70  int i, ncols;
71 
72  db_init_index(index);
73  DB_RECV_STRING(&index->indexName);
74  DB_RECV_STRING(&index->tableName);
75  DB_RECV_CHAR(&index->unique);
76 
77  DB_RECV_INT(&ncols);
78 
79  if (db_alloc_index_columns(index, ncols) != DB_OK)
80  return db_get_error_code();
81 
82  for (i = 0; i < ncols; i++) {
83  DB_RECV_STRING(&index->columnNames[i]);
84  }
85 
86  return DB_OK;
87 }
88 
89 /*!
90  \brief Receive index array
91 
92  \param list
93  \param count
94  */
96 {
97  int i;
98 
100 
102  if (*list == NULL)
103  return db_get_error_code();
104 
105  for (i = 0; i < *count; i++) {
106  DB_RECV_INDEX(&((*list)[i]));
107  }
108 
109  return DB_OK;
110 }
#define NULL
Definition: ccmath.h:32
#define DB_OK
Definition: dbmi.h:71
dbIndex * db_alloc_index_array(int)
Allocate index array.
void db_init_index(dbIndex *)
Initialize dbIndex.
int db_get_error_code(void)
Get error code.
int db_alloc_index_columns(dbIndex *, int)
Allocate index columns.
int count
#define DB_RECV_INDEX(x)
Definition: macros.h:235
#define DB_SEND_STRING(x)
Definition: macros.h:24
#define DB_SEND_CHAR(x)
Definition: macros.h:50
#define DB_RECV_CHAR(x)
Definition: macros.h:55
#define DB_SEND_INT(x)
Definition: macros.h:82
#define DB_RECV_INT(x)
Definition: macros.h:87
#define DB_RECV_STRING(x)
Definition: macros.h:39
#define DB_SEND_INDEX(x)
Definition: macros.h:225
dbString * columnNames
Definition: dbmi.h:234
int numColumns
Definition: dbmi.h:233
dbString indexName
Definition: dbmi.h:231
dbString tableName
Definition: dbmi.h:232
char unique
Definition: dbmi.h:235
Definition: manage.h:4
int db__send_index(dbIndex *index)
Send index.
Definition: xdrindex.c:25
int db__recv_index_array(dbIndex **list, int *count)
Receive index array.
Definition: xdrindex.c:95
int db__send_index_array(dbIndex *list, int count)
Send index array.
Definition: xdrindex.c:50
int db__recv_index(dbIndex *index)
Receive index.
Definition: xdrindex.c:68