SQL parser - Syntax checker
As I previously noted, one of the main components of this DBMS would be the SQL interpreting engine. One thing it would have to do is check for Syntax errors. I have been thinking that regular expressions would be a good way to check the SQL syntax and I have roughly come up with some (I just brushed up on my regex by reading some tutorials) - these may not be syntatically correct (i.e. have not been tested), but should contain the basic idea. Here we go:
SELECT statement
/
^SELECT[:space:].*[:space:]
FROM[:space:].*[:space:]
/
WHERE clause
/
^WHERE[:space:]
[a-zA-Z0-9]=( ([a-zA-Z0-9]*) ^ \'([a-zA-Z0-9\"[\\\']*]*)\' ^ \"([a-zA-Z0-9\'[\\\"]*]*)\" )
((AND ^ OR) [a-zA-Z0-9]=( ([a-zA-Z0-9]*) ^ \'([a-zA-Z0-9\"[\\\']*]*)\' ^ \"([a-zA-Z0-9\'[\\\"]*]*)\" ))*
/
INSERT statement
/
^INSERT[:space:]INTO[:space:][a-zA-Z0-9]*
[\(]
([a-zA-Z0-9]*[,])*
([a-zA-Z0-9]*)
[\)]
/
I will test these tomorrow, feeling sleepy now.
SELECT statement
/
^SELECT[:space:].*[:space:]
FROM[:space:].*[:space:]
/
WHERE clause
/
^WHERE[:space:]
[a-zA-Z0-9]=( ([a-zA-Z0-9]*) ^ \'([a-zA-Z0-9\"[\\\']*]*)\' ^ \"([a-zA-Z0-9\'[\\\"]*]*)\" )
((AND ^ OR) [a-zA-Z0-9]=( ([a-zA-Z0-9]*) ^ \'([a-zA-Z0-9\"[\\\']*]*)\' ^ \"([a-zA-Z0-9\'[\\\"]*]*)\" ))*
/
INSERT statement
/
^INSERT[:space:]INTO[:space:][a-zA-Z0-9]*
[\(]
([a-zA-Z0-9]*[,])*
([a-zA-Z0-9]*)
[\)]
/
I will test these tomorrow, feeling sleepy now.
0 Comments:
Post a Comment
<< Home