JakeWheat / simple-sql-parser

SQL parser in Haskell
http://jakewheat.github.io/simple-sql-parser/latest
Other
82 stars 29 forks source link

Support for VARCHAR2(maximum_size [CHAR | BYTE]) #7

Closed ralphtq closed 5 years ago

ralphtq commented 9 years ago

Hi,

It would be nice to have PL/SQL data types like the above.

See http://docs.oracle.com/cd/B10500_01/appdev.920/a96624/03_types.htm for more.

Hope this is easy

Successfully parsed other constructs.

Great library thanks.

Ralph

JakeWheat commented 9 years ago

Seems pretty reasonable. Can you give some quick examples of sql with varchar2 in which doesn't currently parse?

ralphtq commented 8 years ago

I'm back working on this after some months. Here's an example of what does not parse:

sql2rdf: TestVARCHARs.sql:6:24: Field3 varchar2 (55 BYTE) ^ "TestVARCHARs.sql" (line 6, column 24): unexpected Identifier "BYTE" expecting ), ,, k, m, g, t, p, characters or octets CallStack (from HasCallStack): error, called at sql2rdf.lhs:78:17 in main:Main

This was the input file:

CREATE TABLE VarcharTests ( Field1 varchar2 (20) NOT NULL , Field2 varchar2 (10) NOT NULL , Field3 varchar2 (55 BYTE) );

This is a typical definition in ORACLE SQL.

Appreciate your response. Thanks.

JakeWheat commented 8 years ago

I see it now, I think the issue is that in ansi sql, the unit type for the size is spelt 'characters' or 'octets', and in oracle the same thing is instead spelt 'char' or 'byte'. Do you want to add this? It should be pretty easy, if you search for the word 'octets' in the code there are just a couple of places to change.

ralphtq commented 8 years ago

Thanks for your quick response. I'd have to be a collaborator to change code.

I changed my local copy of Parse.lhs in one place as follows:

lobUnits = PrecCharacters <$ keyword_ "characters"
           <|> PrecCharacters <$ keyword_ "char"
           <|> PrecOctets <$ keyword_ "octets"
           <|> PrecOctets <$ keyword_ "byte"
JakeWheat commented 8 years ago

Thanks, I will add this change.

JakeWheat commented 5 years ago

This is now in the released version, thanks again.