22 #include <grass/sqlp.h>
25 static void print_node(SQLPNODE * nptr,
int level)
29 for (i = 0; i < level; i++) {
33 if (nptr->node_type == SQLP_NODE_EXPRESSION) {
36 print_node(nptr->left, level + 1);
39 print_node(nptr->right, level + 1);
42 else if (nptr->node_type == SQLP_NODE_VALUE) {
43 switch (nptr->value.type) {
45 fprintf(stderr,
"val: NULL\n");
48 fprintf(stderr,
"val: %e\n", nptr->value.d);
51 fprintf(stderr,
"val: %d\n", nptr->value.i);
54 fprintf(stderr,
"val: '%s'\n", nptr->value.s);
59 fprintf(stderr,
"col: %s\n", nptr->column_name);
67 fprintf(stderr,
"********** SQL PARSER RESULT **********\n");
68 fprintf(stderr,
"INPUT: %s\n", sqlpStmt->stmt);
69 fprintf(stderr,
"COMMAND: ");
70 switch (sqlpStmt->command) {
71 case (SQLP_ADD_COLUMN):
72 fprintf(stderr,
"ADD COLUMN\n");
75 fprintf(stderr,
"CREATE\n");
78 fprintf(stderr,
"DROP\n");
80 case (SQLP_DROP_COLUMN):
81 fprintf(stderr,
"DROP COLUMN\n");
84 fprintf(stderr,
"INSERT\n");
87 fprintf(stderr,
"UPDATE\n");
90 fprintf(stderr,
"SELECT\n");
93 fprintf(stderr,
"DELETE\n");
96 fprintf(stderr,
"UNKNOWN\n");
99 fprintf(stderr,
"TABLE: %s\n", sqlpStmt->table);
102 for (i = 0; i < st->nCol; i++) {
103 if (sqlpStmt->command == SQLP_CREATE) {
104 fprintf(stderr,
"COLUMN %2d: ", i + 1);
105 switch (sqlpStmt->ColType[i]) {
107 fprintf(stderr,
"type:varchar width:%d",
108 sqlpStmt->ColWidth[i]);
111 fprintf(stderr,
"type:integer");
114 fprintf(stderr,
"type:double");
117 fprintf(stderr,
"type:date");
120 fprintf(stderr,
"type:time");
123 fprintf(stderr,
"type:unknown");
126 fprintf(stderr,
" name:%s\n", sqlpStmt->Col[i].s);
129 fprintf(stderr,
"COLUMN %2d: %s\n", i + 1, sqlpStmt->Col[i].s);
134 for (i = 0; i < st->nVal; i++) {
135 fprintf(stderr,
"VALUE %2d ", i + 1);
136 switch (sqlpStmt->Val[i].type) {
138 fprintf(stderr,
"(string) : %s\n", sqlpStmt->Val[i].s);
141 fprintf(stderr,
"(integer): %d\n", sqlpStmt->Val[i].i);
144 fprintf(stderr,
"(float) : %f\n", sqlpStmt->Val[i].d);
147 fprintf(stderr,
"(unknown) : null\n");
150 fprintf(stderr,
"(expression) :\n");
151 print_node(sqlpStmt->Val[i].expr, 0);
154 fprintf(stderr,
"unknown\n");
159 if (sqlpStmt->upperNodeptr) {
160 fprintf(stderr,
"WHERE:\n");
161 print_node(sqlpStmt->upperNodeptr, 0);
165 if (sqlpStmt->command == SQLP_SELECT) {
166 if (sqlpStmt->orderDir) {
167 fprintf(stderr,
"ORDER BY: %s %s\n", sqlpStmt->orderCol,
168 sqlpStmt->orderDir == 1 ?
"ASC" :
"DESC");
171 fprintf(stderr,
"ORDER BY: %s\n", sqlpStmt->orderCol);
176 fprintf(stderr,
"***************************************\n");
int sqpPrintStmt(SQLPSTMT *st)
char * sqpOperatorName(int oper)