1 |
dpavlin |
1 |
%{ |
2 |
|
|
/* |
3 |
|
|
* This SQL Lexer is copied from the O'Reilly Lex & Yacc book, 2nd Edition, |
4 |
|
|
* 1995, by John R. Levine, Tony Mason, and Doug Brown. It probably contains |
5 |
|
|
* words that we don't need for the Object Server, and will probably need |
6 |
|
|
* enhancements. I removed the DDL and non-query words, but I'm going to |
7 |
|
|
* leave in all other O'Reilly stuff unless it becomes real obvious that we |
8 |
|
|
* don't need it. |
9 |
|
|
* |
10 |
|
|
* Jeremy Hickerson, 5/8/2002 |
11 |
|
|
*/ |
12 |
|
|
#define LEX_SOURCE_FILE |
13 |
|
|
|
14 |
|
|
#include <string.h> |
15 |
|
|
#include "obj_srvr.h" |
16 |
dpavlin |
3 |
/*#include "flexdef.h"*/ |
17 |
dpavlin |
1 |
|
18 |
|
|
#ifdef VMS |
19 |
|
|
#include <unixio.h> |
20 |
|
|
#endif |
21 |
|
|
|
22 |
dpavlin |
3 |
/* |
23 |
dpavlin |
1 |
#include <string.h> |
24 |
|
|
#include <stdlib.h> |
25 |
|
|
#include <unistd.h> |
26 |
|
|
#include <types.h> |
27 |
|
|
#include <socket.h> |
28 |
|
|
#include <in.h> |
29 |
|
|
#include <inet.h> |
30 |
|
|
#include <netdb.h> |
31 |
|
|
#include <stdio.h> |
32 |
|
|
#include <errno.h> |
33 |
|
|
#include <time.h> |
34 |
|
|
#include <timeb.h> |
35 |
dpavlin |
3 |
*/ |
36 |
dpavlin |
1 |
|
37 |
dpavlin |
3 |
#include <ctype.h> |
38 |
|
|
#include <stdarg.h> |
39 |
|
|
#include <stdio.h> |
40 |
|
|
#include <stdlib.h> |
41 |
|
|
#include <string.h> |
42 |
|
|
#include <stdbool.h> |
43 |
|
|
|
44 |
|
|
|
45 |
dpavlin |
1 |
#define bcopy(s,d,l) memcpy(d,s,l) |
46 |
|
|
#define bzero(d,l) memset(d,0,l) |
47 |
|
|
#define BUF_SIZE 2048 |
48 |
|
|
|
49 |
|
|
char buf[BUF_SIZE]; |
50 |
|
|
int sock; |
51 |
|
|
|
52 |
dpavlin |
3 |
#include "obj_srvr.tab.h" |
53 |
dpavlin |
1 |
|
54 |
|
|
int lineno = 1; |
55 |
|
|
char mode; |
56 |
|
|
|
57 |
|
|
void yyerror(char *s); |
58 |
|
|
void connect_to_oracle_obj_srvr(char *host, int port); |
59 |
|
|
|
60 |
|
|
/* macro to save the text of a SQL token */ |
61 |
|
|
#define SV save_str(yytext) |
62 |
|
|
|
63 |
|
|
/* macro to save the text and return a token */ |
64 |
|
|
#define TOK(name) { SV; token = name; return name; } |
65 |
|
|
|
66 |
|
|
/* read input through perl, since perl has access to oracle_obj_srvr socket */ |
67 |
|
|
/* (we connected to it in perl, because if we connect in C (here) then haven't |
68 |
|
|
figured out how to make perl see socket for output) */ |
69 |
|
|
#define YY_INPUT(buf,result,max_size) { \ |
70 |
|
|
strcpy(buf, call_perl_get_yyin(max_size) ); \ |
71 |
|
|
result = strlen(buf); \ |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
%} |
75 |
|
|
|
76 |
|
|
%s SQL |
77 |
|
|
%% |
78 |
|
|
|
79 |
|
|
/* EXEC[ \t]+SQL { BEGIN SQL; printf("SQL> "); start_save(); } */ |
80 |
|
|
SQL { |
81 |
|
|
|
82 |
|
|
BEGIN SQL; |
83 |
|
|
|
84 |
|
|
call_perl_send_yyout("SQL> "); |
85 |
|
|
|
86 |
|
|
if (mode == 'S') |
87 |
|
|
call_perl_send_yyout("\n"); |
88 |
|
|
|
89 |
|
|
start_save(); |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
QUIT { close(sock); exit(0); } |
93 |
|
|
|
94 |
|
|
/* literal keyword tokens */ |
95 |
|
|
<SQL>ALL TOK(ALL) |
96 |
|
|
<SQL>AND TOK(AND) |
97 |
|
|
<SQL>AVG TOK(AMMSC) |
98 |
|
|
<SQL>MIN TOK(AMMSC) |
99 |
|
|
<SQL>MAX TOK(AMMSC) |
100 |
|
|
<SQL>SUM TOK(AMMSC) |
101 |
|
|
<SQL>COUNT TOK(AMMSC) |
102 |
|
|
<SQL>ANY TOK(ANY) |
103 |
|
|
<SQL>AS TOK(AS) |
104 |
|
|
<SQL>ASC TOK(ASC) |
105 |
|
|
<SQL>AUTHORIZATION TOK(AUTHORIZATION) |
106 |
|
|
<SQL>BETWEEN TOK(BETWEEN) |
107 |
|
|
<SQL>BY TOK(BY) |
108 |
|
|
<SQL>CHAR(ACTER)? TOK(CHARACTER) |
109 |
|
|
<SQL>CHECK TOK(CHECK) |
110 |
|
|
<SQL>CLOSE TOK(CLOSE) |
111 |
|
|
<SQL>CONTINUE TOK(CONTINUE) |
112 |
|
|
<SQL>CURRENT TOK(CURRENT) |
113 |
|
|
<SQL>CURSOR TOK(CURSOR) |
114 |
|
|
<SQL>DECIMAL TOK(DECIMAL) |
115 |
|
|
<SQL>DECLARE TOK(DECLARE) |
116 |
|
|
<SQL>DEFAULT TOK(DEFAULT) |
117 |
|
|
<SQL>DESC TOK(DESC) |
118 |
|
|
<SQL>DISTINCT TOK(DISTINCT) |
119 |
|
|
<SQL>DOUBLE TOK(DOUBLE) |
120 |
|
|
<SQL>ESCAPE TOK(ESCAPE) |
121 |
|
|
<SQL>EXISTS TOK(EXISTS) |
122 |
|
|
<SQL>FETCH TOK(FETCH) |
123 |
|
|
<SQL>FLOAT TOK(FLOAT) |
124 |
|
|
<SQL>FOR TOK(FOR) |
125 |
|
|
<SQL>FOREIGN TOK(FOREIGN) |
126 |
|
|
<SQL>FOUND TOK(FOUND) |
127 |
|
|
<SQL>FROM TOK(FROM) |
128 |
|
|
<SQL>GO[ \t]*TO TOK(GOTO) |
129 |
|
|
<SQL>GROUP TOK(GROUP) |
130 |
|
|
<SQL>HAVING TOK(HAVING) |
131 |
|
|
<SQL>IN TOK(IN) |
132 |
|
|
<SQL>INDICATOR TOK(INDICATOR) |
133 |
|
|
<SQL>INT(EGER)? TOK(INTEGER) |
134 |
|
|
<SQL>INTO TOK(INTO) |
135 |
|
|
<SQL>IS TOK(IS) |
136 |
|
|
<SQL>KEY TOK(KEY) |
137 |
|
|
<SQL>LANGUAGE TOK(LANGUAGE) |
138 |
|
|
<SQL>LIKE TOK(LIKE) |
139 |
|
|
<SQL>NOT TOK(NOT) |
140 |
|
|
<SQL>NULL TOK(NULLX) |
141 |
|
|
<SQL>NUMERIC TOK(NUMERIC) |
142 |
|
|
<SQL>OF TOK(OF) |
143 |
|
|
<SQL>ON TOK(ON) |
144 |
|
|
<SQL>OPEN TOK(OPEN) |
145 |
|
|
<SQL>OPTION TOK(OPTION) |
146 |
|
|
<SQL>OR TOK(OR) |
147 |
|
|
<SQL>ORDER TOK(ORDER) |
148 |
|
|
<SQL>PRECISION TOK(PRECISION) |
149 |
|
|
<SQL>PRIMARY TOK(PRIMARY) |
150 |
|
|
<SQL>PRIVILEGES TOK(PRIVILEGES) |
151 |
|
|
<SQL>PROCEDURE TOK(PROCEDURE) |
152 |
|
|
<SQL>REAL TOK(REAL) |
153 |
|
|
<SQL>REFERENCES TOK(REFERENCES) |
154 |
|
|
<SQL>SCHEMA TOK(SCHEMA) |
155 |
|
|
<SQL>SELECT TOK(SELECT) |
156 |
|
|
<SQL>SMALLINT TOK(SMALLINT) |
157 |
|
|
<SQL>SOME TOK(SOME) |
158 |
|
|
<SQL>SQLCODE TOK(SQLCODE) |
159 |
|
|
<SQL>TO TOK(TO) |
160 |
|
|
<SQL>UNION TOK(UNION) |
161 |
|
|
<SQL>UNIQUE TOK(UNIQUE) |
162 |
|
|
<SQL>USER TOK(USER) |
163 |
|
|
<SQL>VALUES TOK(VALUES) |
164 |
|
|
<SQL>WHENEVER TOK(WHENEVER) |
165 |
|
|
<SQL>WHERE TOK(WHERE) |
166 |
|
|
<SQL>WITH TOK(WITH) |
167 |
|
|
<SQL>WORK TOK(WORK) |
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
/* punctuation */ |
172 |
|
|
<SQL>"=" TOK(COMP_EQ) |
173 |
|
|
<SQL>"<>" TOK(COMP_NE1) |
174 |
|
|
<SQL>"!=" TOK(COMP_NE2) |
175 |
|
|
<SQL>"<" TOK(COMP_LT) |
176 |
|
|
<SQL>">" TOK(COMP_GT) |
177 |
|
|
<SQL>"<=" TOK(COMP_LE) |
178 |
|
|
<SQL>">=" TOK(COMP_GE) |
179 |
|
|
|
180 |
|
|
<SQL>[-+*/:(),.;] TOK(yytext[0]) |
181 |
|
|
|
182 |
|
|
|
183 |
|
|
/* names */ |
184 |
|
|
<SQL>[A-Za-z][A-Za-z0-9_]* TOK(NAME) |
185 |
|
|
|
186 |
|
|
/* strings */ |
187 |
|
|
<SQL>'[^'\n]*' TOK(STRING) |
188 |
|
|
|
189 |
|
|
<SQL>'[^'\n]*$ { yyerror("Unterminated string"); } |
190 |
|
|
|
191 |
|
|
|
192 |
|
|
/* numbers */ |
193 |
|
|
<SQL>[0-9]+ | |
194 |
|
|
<SQL>[0-9]+"."[0-9]* | |
195 |
|
|
<SQL>"."[0-9]* TOK(INTNUM) |
196 |
|
|
|
197 |
|
|
<SQL>[0-9]+[eE][+-]?[0-9]+ | |
198 |
|
|
<SQL>[0-9]+"."[0-9]*[eE][+-]?[0-9]+ | |
199 |
|
|
<SQL>"."[0-9]*[eE][+-]?[0-9]+ TOK(APPROXNUM) |
200 |
|
|
|
201 |
|
|
|
202 |
|
|
/* whitespace */ |
203 |
|
|
<SQL>\n { save_str(" "); lineno++; } |
204 |
|
|
\n { save_str(" "); lineno++; } /* jh: non-SQL */ |
205 |
|
|
|
206 |
|
|
<SQL>[ \t\r]+ save_str(" "); /* whitespace */ |
207 |
|
|
|
208 |
|
|
<SQL>"--".* ; /* comment */ |
209 |
|
|
|
210 |
|
|
|
211 |
|
|
/* anything else */ |
212 |
|
|
. ; /* ignore */ |
213 |
|
|
|
214 |
|
|
%% |
215 |
|
|
|
216 |
|
|
|
217 |
|
|
void yyerror(char *s) { |
218 |
|
|
printf("%d: %s at %s\n", lineno, s, yytext); |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
|
222 |
|
|
/* leave SQL lexing mode */ |
223 |
|
|
un_sql() { |
224 |
|
|
BEGIN INITIAL; |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
|
228 |
|
|
main(int argc, char *argv[]) { |
229 |
|
|
|
230 |
|
|
|
231 |
|
|
if (argc < 4) { |
232 |
|
|
fprintf(stderr, "Usage: obj_srvr <db_uid> db_passwd> <mode: (I)nteractive/(S)erver> [host] [port]\n"); |
233 |
|
|
return; |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
char perlscript_to_embed[] = "obj_srvr.pl"; |
237 |
|
|
static char *perl_argv[5]; |
238 |
|
|
int i; |
239 |
|
|
|
240 |
|
|
perl_argv[0] = argv[0]; |
241 |
|
|
perl_argv[1] = perlscript_to_embed; |
242 |
|
|
perl_argv[2] = argv[1]; |
243 |
|
|
perl_argv[3] = argv[2]; |
244 |
|
|
|
245 |
|
|
/* start the perl interpreter and compile obj_srvr.pl */ |
246 |
|
|
if ( !strcmp(argv[3], "S") || !strcmp(argv[3], "s") ) { |
247 |
|
|
strcpy(perl_argv[2], ""); |
248 |
|
|
strcpy(perl_argv[3], ""); |
249 |
|
|
} |
250 |
|
|
embed_perl_obj_srvr(4, perl_argv, NULL); |
251 |
|
|
|
252 |
|
|
/* connect to "wrapper" server running on foreign tnslsnr */ |
253 |
|
|
if ( !strcmp(argv[3], "S") || !strcmp(argv[3], "s") ) { |
254 |
|
|
mode = 'S'; |
255 |
|
|
call_perl_connect2client(argv[4], argv[5]); |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
do { |
259 |
|
|
if (yyparse() ) { |
260 |
|
|
call_perl_send_yyout("\nQUIT\n"); |
261 |
|
|
break; |
262 |
|
|
} |
263 |
|
|
} while (!feof(yyin) ) ; |
264 |
|
|
|
265 |
|
|
end_perl(); |
266 |
|
|
} |
267 |
|
|
|