GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
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 typedef struct {
70  int type; /* SQLP_S, SQLP_I, SQLP_D, SQLP_NULL, SQL_EXPR */
71  char *s; /* pointer to string or NULL */
72  int i;
73  double d;
74  struct sqlpnode *expr;
75 } SQLPVALUE;
76 
77 typedef struct sqlpnode {
78  int node_type; /* Node type: SQLP_NODE_COLUMN, SQLP_NODE_VALUE,
79  SQLP_NODE_EXPRESSION */
80  int oper; /* Operator code */
81  struct sqlpnode *left; /* left argument, sometimes NULL */
82  struct sqlpnode *right; /* right argument, sometimes NULL */
83  char *column_name;
86 
87 typedef struct {
88  char *stmt; /* input statement string */
89  char *cur; /* cursor for parser */
90  char errmsg[SQLP_MAX_ERR + 1];
91  int command;
92  char table[SQLP_MAX_TABLE + 1];
93  SQLPVALUE *Col; /* column names */
94  int *ColType;
95  int *ColWidth; /* length */
96  int *ColDecim; /* decimals */
97  int aCol; /* allocated */
98  int nCol; /* number of columns */
99  SQLPVALUE *Val; /* values */
100  int aVal;
101  int nVal;
103  char *orderCol; /* column name which should be used for sorting (ORDER BY)
104  or NULL (no sorting) */
105  int orderDir; /* direction of ordering (ASC or DESC) */
106 } SQLPSTMT;
107 
108 #include <grass/defs/sqlp.h>
109 
110 extern SQLPSTMT *sqlpStmt;
111 
112 #endif
struct sqlpnode SQLPNODE
#define SQLP_MAX_ERR
Definition: sqlp.h:58
#define SQLP_MAX_TABLE
Definition: sqlp.h:57
SQLPSTMT * sqlpStmt
Definition: sql.c:37
Definition: sqlp.h:87
int nCol
Definition: sqlp.h:98
char * stmt
Definition: sqlp.h:88
int aCol
Definition: sqlp.h:97
SQLPVALUE * Col
Definition: sqlp.h:93
SQLPNODE * upperNodeptr
Definition: sqlp.h:102
char * orderCol
Definition: sqlp.h:103
int * ColWidth
Definition: sqlp.h:95
int orderDir
Definition: sqlp.h:105
int command
Definition: sqlp.h:91
int nVal
Definition: sqlp.h:101
int aVal
Definition: sqlp.h:100
int * ColType
Definition: sqlp.h:94
char * cur
Definition: sqlp.h:89
SQLPVALUE * Val
Definition: sqlp.h:99
int * ColDecim
Definition: sqlp.h:96
Definition: sqlp.h:69
double d
Definition: sqlp.h:73
char * s
Definition: sqlp.h:71
struct sqlpnode * expr
Definition: sqlp.h:74
int i
Definition: sqlp.h:72
int type
Definition: sqlp.h:70
Definition: sqlp.h:77
struct sqlpnode * left
Definition: sqlp.h:81
char * column_name
Definition: sqlp.h:83
struct sqlpnode * right
Definition: sqlp.h:82
int oper
Definition: sqlp.h:80
SQLPVALUE value
Definition: sqlp.h:84
int node_type
Definition: sqlp.h:78