Coder Social home page Coder Social logo

mysql-parser's Issues

CREATE VIEW parsing issue

Hi, Fallowing spec does not work as expected:

    it 'tests for create view' do
      @result = @evaluator.parse('CREATE VIEW asd AS select * FROM def')
      test.to eq(' CREATE VIEW asd AS select * FROM def ')
    end
 1) Testing the Parser tests for create view
     Failure/Error: raise  ScanError, "can not match: '" + text + "'"
     
     MySQLParser::ScanError:
       can not match: '* FROM def '
     # ./lib/lexer.rb:635:in `_next_token'
     # ./lib/lexer.rb:50:in `next_token'
     # ./lib/lexer.rb:726:in `tokenize'
     # mysql.y.rb:1284:in `parse'
     # ./spec/parser_spec.rb:63:in `block (2 levels) in <class:MySQLParserTester>'

Racc::ParseError: parse can be raised for correct SQL statements.

When trying to parse a alter table query containing DEFAULT 0 NOT NULL, Racc::ParseError: parse error on value "NOT" (NOT) is raised. According to the MySQL documentation, this query is using the correct syntax.

Interestingly, if we replace DEFAULT 0 NOT NULL with NOT NULL DEFAULT 0, the parsing is successful.

irb(main):001:0> require 'mysql-parser'
=> true
irb(main):002:0> query = "ALTER TABLE `some_table` ADD `something` int DEFAULT 0 NOT NULL"
=> "ALTER TABLE `some_table` ADD `something` int DEFAULT 0 NOT NULL"
irb(main):003:0> MySQLParser.new.parse(query)
Racc::ParseError:
parse error on value "NOT" (NOT)
	from /Users/gabrieltanase/.rbenv/versions/2.4.5/lib/ruby/2.4.0/racc/parser.rb:528:in `on_error'
	from /Users/gabrieltanase/.rbenv/versions/2.4.5/lib/ruby/2.4.0/racc/parser.rb:259:in `_racc_do_parse_c'
	from /Users/gabrieltanase/.rbenv/versions/2.4.5/lib/ruby/2.4.0/racc/parser.rb:259:in `do_parse'
	from /Users/gabrieltanase/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/mysql-parser-0.0.3/lib/lexer.rb:29:in `scan_str'
	from mysql.y.rb:1288:in `parse'
	from (irb):3
	from /Users/gabrieltanase/.rbenv/versions/2.4.5/bin/irb:11:in `<main>'
irb(main):004:0>
irb(main):005:0*
irb(main):006:0* query = "ALTER TABLE `some_table` ADD `something` int NOT NULL DEFAULT 0"
=> "ALTER TABLE `some_table` ADD `something` int NOT NULL DEFAULT 0"
irb(main):007:0> MySQLParser.new.parse(query)
=> {:tree=><root: [<S: [" "]>, <r_commands: [<r_ALTER_TABLE: ["ALTER", <S: [" "]>, <r_ONLINE_OFFLINE: []>, <r_opt_IGNORE: []>, "TABLE", <S: [" "]>, <r_tbl_name: [<r_tbl_name_int: [<ident: ["`", <opt_ident_in_backtick: [<opt_ident_in_backtick: []>, "some_table"]>, "`", <S: [" "]>]>]>]>, <r_opt_alter_commands: [<r_comma_separated_alter_specification: [<r_alter_specification: ["ADD", <S: [" "]>, <r_opt_COLUMN: []>, <r_col_name: [<ident: ["`", <opt_ident_in_backtick: [<opt_ident_in_backtick: []>, "something"]>, "`", <S: [" "]>]>]>, <r_column_definition: [<r_datatype: ["int", <S: [" "]>, <r_opt_datatype_int: [<r_opt_length_int: []>, <r_opt_UNSIGNED: []>, <r_opt_ZEROFILL: []>]>]>, <r_opt_NULL_status: ["NOT", <S: [" "]>, <null: ["NULL", <S: [" "]>]>]>, <r_opt_DEFAULT_with_val: ["DEFAULT", <S: [" "]>, <value: [<number: [<integer: [<nat: [<binary: ["0", <S: [" "]>]>]>]>]>]>]>, <r_opt_AUTO_INCREMENT: []>, <r_opt_UNIQUE_or_PRIMARY: []>, <r_opt_COMMENT_with_val: []>, <r_opt_COLUMN_FORMAT: []>, <r_opt_STORAGE: []>, <r_opt_COLUMN_ON_UPDATE: []>]>, <r_opt_pos_column: []>]>]>]>, <r_opt_after_alter: []>, <r_opt_PARTITION_options: []>]>]>]>, :state=>{}}

Seems related to https://github.com/square/mysql-parser/blob/master/mysql.y.rb#L418-L422

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.