sqlp.h 2.7 KB

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