GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
sqltype.c
Go to the documentation of this file.
1 /*!
2  \file lib/db/dbmi_base/sqltype.c
3 
4  \brief DBMI Library (base) - SQL data type
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
12  \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
13 */
14 
15 #include <string.h>
16 #include <grass/dbmi.h>
17 
18 /*!
19  \brief Get SQL data type description
20 
21  \param sqltype SQL data type
22 
23  \return string buffer with description
24 */
25 const char *db_sqltype_name(int sqltype)
26 {
27  static char buf[256];
28  int from, to;
29 
30  switch (sqltype) {
32  return "CHARACTER";
34  return "NUMERIC";
36  return "DECIMAL";
38  return "SMALLINT";
40  return "INTEGER";
41  case DB_SQL_TYPE_REAL:
42  return "REAL";
44  return "DOUBLE PRECISION";
45  case DB_SQL_TYPE_DATE:
46  return "DATE";
47  case DB_SQL_TYPE_TIME:
48  return "TIME";
49  case DB_SQL_TYPE_SERIAL:
50  return "SERIAL";
51  case DB_SQL_TYPE_TEXT:
52  return "TEXT";
53  }
54  switch (sqltype & ~DB_DATETIME_MASK) {
56  strcpy(buf, "TIMESTAMP ");
57  break;
59  strcpy(buf, "INTERVAL ");
60  break;
61  default:
62  return "UNKNOWN";
63  }
64 
65  db_interval_range(sqltype, &from, &to);
66 
67  switch (from) {
68  case DB_YEAR:
69  strcat(buf, "YEAR");
70  break;
71  case DB_MONTH:
72  strcat(buf, "MONTH");
73  break;
74  case DB_DAY:
75  strcat(buf, "DAY");
76  break;
77  case DB_HOUR:
78  strcat(buf, "HOUR");
79  break;
80  case DB_MINUTE:
81  strcat(buf, "MINUTE");
82  break;
83  case DB_SECOND:
84  strcat(buf, "SECOND");
85  break;
86  case DB_FRACTION:
87  strcat(buf, "FRACTION");
88  break;
89  }
90 
91  if (from)
92  strcat(buf, " to");
93  if (to)
94  strcat(buf, " ");
95 
96  switch (to) {
97  case DB_YEAR:
98  strcat(buf, "YEAR");
99  break;
100  case DB_MONTH:
101  strcat(buf, "MONTH");
102  break;
103  case DB_DAY:
104  strcat(buf, "DAY");
105  break;
106  case DB_HOUR:
107  strcat(buf, "HOUR");
108  break;
109  case DB_MINUTE:
110  strcat(buf, "MINUTE");
111  break;
112  case DB_SECOND:
113  strcat(buf, "SECOND");
114  break;
115  case DB_FRACTION:
116  strcat(buf, "FRACTION");
117  break;
118  }
119 
120  return buf;
121 }
#define DB_SQL_TYPE_INTEGER
Definition: dbmi.h:83
const char * db_sqltype_name(int sqltype)
Get SQL data type description.
Definition: sqltype.c:25
#define DB_SQL_TYPE_INTERVAL
Definition: dbmi.h:91
#define DB_SQL_TYPE_TIMESTAMP
Definition: dbmi.h:90
#define DB_SECOND
Definition: dbmi.h:102
#define DB_FRACTION
Definition: dbmi.h:103
#define DB_SQL_TYPE_REAL
Definition: dbmi.h:84
#define DB_HOUR
Definition: dbmi.h:100
#define DB_SQL_TYPE_CHARACTER
Definition: dbmi.h:81
#define DB_DAY
Definition: dbmi.h:99
#define DB_SQL_TYPE_SERIAL
Definition: dbmi.h:94
#define DB_YEAR
Definition: dbmi.h:97
#define DB_SQL_TYPE_DATE
Definition: dbmi.h:88
#define DB_SQL_TYPE_TEXT
Definition: dbmi.h:92
#define DB_MONTH
Definition: dbmi.h:98
#define DB_SQL_TYPE_NUMERIC
Definition: dbmi.h:87
#define DB_SQL_TYPE_DOUBLE_PRECISION
Definition: dbmi.h:85
void db_interval_range(int, int *, int *)
Define range based on SQL data type.
Definition: interval.c:24
#define DB_SQL_TYPE_TIME
Definition: dbmi.h:89
#define DB_SQL_TYPE_SMALLINT
Definition: dbmi.h:82
#define DB_SQL_TYPE_DECIMAL
Definition: dbmi.h:86
#define DB_MINUTE
Definition: dbmi.h:101
#define DB_DATETIME_MASK
Definition: dbmi.h:104