GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sqltype.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <grass/dbmi.h>
3 
9 const char *db_sqltype_name(int sqltype)
10 {
11  static char buf[256];
12  int from, to;
13 
14  switch (sqltype) {
15  case DB_SQL_TYPE_CHARACTER:
16  return "CHARACTER";
17  case DB_SQL_TYPE_NUMERIC:
18  return "NUMERIC";
19  case DB_SQL_TYPE_DECIMAL:
20  return "DECIMAL";
21  case DB_SQL_TYPE_SMALLINT:
22  return "SMALLINT";
23  case DB_SQL_TYPE_INTEGER:
24  return "INTEGER";
25  case DB_SQL_TYPE_REAL:
26  return "REAL";
27  case DB_SQL_TYPE_DOUBLE_PRECISION:
28  return "DOUBLE PRECISION";
29  case DB_SQL_TYPE_DATE:
30  return "DATE";
31  case DB_SQL_TYPE_TIME:
32  return "TIME";
33  case DB_SQL_TYPE_SERIAL:
34  return "SERIAL";
35  case DB_SQL_TYPE_TEXT:
36  return "TEXT";
37  }
38  switch (sqltype & ~DB_DATETIME_MASK) {
39  case DB_SQL_TYPE_TIMESTAMP:
40  strcpy(buf, "TIMESTAMP ");
41  break;
42  case DB_SQL_TYPE_INTERVAL:
43  strcpy(buf, "INTERVAL ");
44  break;
45  default:
46  return "UNKNOWN";
47  }
48 
49  db_interval_range(sqltype, &from, &to);
50 
51  switch (from) {
52  case DB_YEAR:
53  strcat(buf, "YEAR");
54  break;
55  case DB_MONTH:
56  strcat(buf, "MONTH");
57  break;
58  case DB_DAY:
59  strcat(buf, "DAY");
60  break;
61  case DB_HOUR:
62  strcat(buf, "HOUR");
63  break;
64  case DB_MINUTE:
65  strcat(buf, "MINUTE");
66  break;
67  case DB_SECOND:
68  strcat(buf, "SECOND");
69  break;
70  case DB_FRACTION:
71  strcat(buf, "FRACTION");
72  break;
73  }
74 
75  if (from)
76  strcat(buf, " to");
77  if (to)
78  strcat(buf, " ");
79 
80  switch (to) {
81  case DB_YEAR:
82  strcat(buf, "YEAR");
83  break;
84  case DB_MONTH:
85  strcat(buf, "MONTH");
86  break;
87  case DB_DAY:
88  strcat(buf, "DAY");
89  break;
90  case DB_HOUR:
91  strcat(buf, "HOUR");
92  break;
93  case DB_MINUTE:
94  strcat(buf, "MINUTE");
95  break;
96  case DB_SECOND:
97  strcat(buf, "SECOND");
98  break;
99  case DB_FRACTION:
100  strcat(buf, "FRACTION");
101  break;
102  }
103 
104  return buf;
105 }
const char * db_sqltype_name(int sqltype)
returns sqltype description
Definition: sqltype.c:9
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
void db_interval_range(int sqltype, int *from, int *to)
Definition: interval.c:9