Parsing SQL CREATE TABLE using jQuery?

I am writing a web application in which SQL is used as input. This SQL should always be a statement CREATE TABLE, and my application should do the following attributes:

  • Field name
  • A type
  • Length (if available)
  • Binary (if available)
  • Allow NULL (if available)
  • Auto zoom (if available)

SQL example:

CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
Birth_Date date)

I don't know where to start, and I'm not so good at writing such parsers. Are there any SQL syntaxes for JavaScript / jQuery that I can use, or any sample code? Thank.

+1
source share
2 answers

This is not a complete solution, but hopefully something to get you started.

You can check the following regular expression:

/^CREATE\s+TABLE\s+(\S*)\s*\((.*)\)$/

He is rude, but he must be consistent.

( , ),

, . , , /^(.)\s(.)$/... (, lengths, null/not null, default, identity (1,1)), - , , , . , , , .

+2

OpenSource, Google Projects " TrimQuery", :

var selectStatement = queryLang.parseSQL("SELECT Customer.* FROM Customer");

SQL, JOINS SELECT item.*,relation.other FROM X

, .

+1

Source: https://habr.com/ru/post/1787862/


All Articles