GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
sqlp.h
Go to the documentation of this file.
1 #ifndef GRASS_SQLP_H
2 #define GRASS_SQLP_H
3 
4 /* SQL Parser */
5 
6 /* KEYWORD OPS */
7 
8 /* SQL COMMANDS */
9 #define SQLP_CREATE 1
10 #define SQLP_DROP 2
11 #define SQLP_INSERT 3
12 #define SQLP_SELECT 4
13 #define SQLP_UPDATE 5
14 #define SQLP_DELETE 6
15 #define SQLP_ADD_COLUMN 7
16 #define SQLP_DROP_COLUMN 8
17 
18 /* SQL OPERATORS */
19  /* Arithmetical */
20 #define SQLP_ADD 1 /* + */
21 #define SQLP_SUBTR 2 /* - */
22 #define SQLP_MLTP 3 /* * */
23 #define SQLP_DIV 4 /* / */
24 
25  /* Comparison */
26 #define SQLP_EQ 11 /* = */
27 #define SQLP_LT 12 /* < */
28 #define SQLP_LE 13 /* <= */
29 #define SQLP_GT 14 /* > */
30 #define SQLP_GE 15 /* >= */
31 #define SQLP_NE 16 /* <> */
32 #define SQLP_MTCH 17 /* ~ */
33 
34 #define SQLP_ISNULL 18 /* IS NULL */
35 #define SQLP_NOTNULL 19 /* IS NULL */
36 
37  /* Logical */
38 #define SQLP_AND 21
39 #define SQLP_OR 22
40 #define SQLP_NOT 23
41 
42 /* SQL VALUE TYPES, NOT COLUMN TYPES */
43 #define SQLP_NULL 1 /* value NULL -> unknown type */
44 #define SQLP_S 2 /* string */
45 #define SQLP_I 3 /* integer */
46 #define SQLP_D 4 /* float */
47 #define SQLP_BOOL 5 /* used only for type of expression */
48 #define SQLP_EXPR 6 /* expression XXX */
49 
50 /* SQL COLUMN TYPES */
51 #define SQLP_VARCHAR 1
52 #define SQLP_INTEGER 2
53 #define SQLP_DOUBLE 3
54 #define SQLP_DATE 4
55 #define SQLP_TIME 5
56 
57 #define SQLP_MAX_TABLE 200
58 #define SQLP_MAX_ERR 500
59 
60 /* Condition node */
61 #define SQLP_NODE_COLUMN 1
62 #define SQLP_NODE_VALUE 2
63 #define SQLP_NODE_EXPRESSION 3
64 
65 /* Order direction */
66 #define SORT_ASC 1
67 #define SORT_DESC 2
68 
69 
70 typedef struct
71 {
72  int type; /* SQLP_S, SQLP_I, SQLP_D, SQLP_NULL, SQL_EXPR */
73  char *s; /* pointer to string or NULL */
74  int i;
75  double d;
76  struct sqlpnode *expr;
77 } SQLPVALUE;
78 
79 typedef struct sqlpnode
80 {
81  int node_type; /* Node type: SQLP_NODE_COLUMN, SQLP_NODE_VALUE, SQLP_NODE_EXPRESSION */
82  int oper; /* Operator code */
83  struct sqlpnode *left; /* left argument, sometimes NULL */
84  struct sqlpnode *right; /* right argument, sometimes NULL */
85  char *column_name;
87 } SQLPNODE;
88 
89 typedef struct
90 {
91  char *stmt; /* input statement string */
92  char *cur; /* cursor for parser */
93  char errmsg[SQLP_MAX_ERR + 1];
94  int command;
95  char table[SQLP_MAX_TABLE + 1];
96  SQLPVALUE *Col; /* column names */
97  int *ColType;
98  int *ColWidth; /* length */
99  int *ColDecim; /* decimals */
100  int aCol; /* allocated */
101  int nCol; /* number of columns */
102  SQLPVALUE *Val; /* values */
103  int aVal;
104  int nVal;
106  char *orderCol; /* column name which should be used for sorting (ORDER BY) or NULL (no sorting) */
107  int orderDir; /* direction of ordering (ASC or DESC) */
108 } SQLPSTMT;
109 
110 #include <grass/defs/sqlp.h>
111 
112 extern SQLPSTMT *sqlpStmt;
113 
114 #endif
Definition: sqlp.h:70
int nVal
Definition: sqlp.h:104
SQLPVALUE * Val
Definition: sqlp.h:102
struct sqlpnode * expr
Definition: sqlp.h:76
SQLPVALUE * Col
Definition: sqlp.h:96
char * cur
Definition: sqlp.h:92
int type
Definition: sqlp.h:72
int orderDir
Definition: sqlp.h:107
char * stmt
Definition: sqlp.h:91
double d
Definition: sqlp.h:75
int oper
Definition: sqlp.h:82
Definition: sqlp.h:89
int * ColType
Definition: sqlp.h:97
int aCol
Definition: sqlp.h:100
int * ColDecim
Definition: sqlp.h:99
int aVal
Definition: sqlp.h:103
SQLPVALUE value
Definition: sqlp.h:86
SQLPNODE * upperNodeptr
Definition: sqlp.h:105
SQLPSTMT * sqlpStmt
Definition: sql.c:38
struct sqlpnode SQLPNODE
int * ColWidth
Definition: sqlp.h:98
int nCol
Definition: sqlp.h:101
Definition: sqlp.h:79
int command
Definition: sqlp.h:94
char * column_name
Definition: sqlp.h:85
int i
Definition: sqlp.h:74
char * s
Definition: sqlp.h:73
int node_type
Definition: sqlp.h:81
struct sqlpnode * left
Definition: sqlp.h:83
#define SQLP_MAX_ERR
Definition: sqlp.h:58
char * orderCol
Definition: sqlp.h:106
#define SQLP_MAX_TABLE
Definition: sqlp.h:57
struct sqlpnode * right
Definition: sqlp.h:84