GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-f63024f571
xdrvalue.c
Go to the documentation of this file.
1 /*!
2  \file lib/db/dbmi_base/xdrvalue.c
3 
4  \brief DBMI Library (base) - external data representation (value)
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 <grass/glocale.h>
17 
18 #include "macros.h"
19 
20 /*!
21  \brief Send value
22 
23  \param value
24  \param Ctype
25 
26  \return
27  */
28 int db__send_value(dbValue *value, int Ctype)
29 {
30  DB_SEND_CHAR(value->isNull);
31  if (value->isNull)
32  return DB_OK;
33 
34  switch (Ctype) {
35  case DB_C_TYPE_INT:
36  DB_SEND_INT(value->i);
37  break;
38  case DB_C_TYPE_DOUBLE:
39  DB_SEND_DOUBLE(value->d);
40  break;
41  case DB_C_TYPE_STRING:
42  DB_SEND_STRING(&value->s);
43  break;
44  case DB_C_TYPE_DATETIME:
45  DB_SEND_DATETIME(&value->t);
46  break;
47  default:
48  db_error("send data: invalid C-type");
49  return DB_FAILED;
50  }
51  return DB_OK;
52 }
53 
54 /*!
55  \brief Receive value
56 
57  \param value
58  \param Ctype
59 
60  \return
61  */
62 int db__recv_value(dbValue *value, int Ctype)
63 {
64  DB_RECV_CHAR(&value->isNull);
65  if (value->isNull)
66  return DB_OK;
67 
68  switch (Ctype) {
69  case DB_C_TYPE_INT:
70  DB_RECV_INT(&value->i);
71  break;
72  case DB_C_TYPE_DOUBLE:
73  DB_RECV_DOUBLE(&value->d);
74  break;
75  case DB_C_TYPE_STRING:
76  DB_RECV_STRING(&value->s);
77  break;
78  case DB_C_TYPE_DATETIME:
79  DB_RECV_DATETIME(&value->t);
80  break;
81  default:
82  db_error(_("send data: invalid C-type"));
83  return DB_FAILED;
84  }
85  return DB_OK;
86 }
#define DB_C_TYPE_INT
Definition: dbmi.h:108
#define DB_FAILED
Definition: dbmi.h:72
#define DB_C_TYPE_STRING
Definition: dbmi.h:107
#define DB_C_TYPE_DOUBLE
Definition: dbmi.h:109
#define DB_OK
Definition: dbmi.h:71
#define DB_C_TYPE_DATETIME
Definition: dbmi.h:110
void db_error(const char *)
Report error message.
#define _(str)
Definition: glocale.h:10
#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_RECV_DOUBLE(x)
Definition: macros.h:109
#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_DATETIME(x)
Definition: macros.h:115
#define DB_RECV_DATETIME(x)
Definition: macros.h:120
#define DB_SEND_DOUBLE(x)
Definition: macros.h:104
dbString s
Definition: dbmi.h:191
dbDateTime t
Definition: dbmi.h:192
char isNull
Definition: dbmi.h:188
double d
Definition: dbmi.h:190
int i
Definition: dbmi.h:189
int db__send_value(dbValue *value, int Ctype)
Send value.
Definition: xdrvalue.c:28
int db__recv_value(dbValue *value, int Ctype)
Receive value.
Definition: xdrvalue.c:62