Coder Social home page Coder Social logo

sqlparser's Introduction

The most full-featured MySQL's SQL parser implement in golang at present.

This parser is part of TiDB from PingCap

You can use this module independently

Install the package with:

go get github.com/ruiaylin/sqlparser

Make the module before use:

cd $GOPATH/src/github.com/ruiaylin/sqlparser/
make 

Import it with:

import "github.com/ruiaylin/sqlparser/parser"

and use parser as the package name inside the code.

Do the test by the following command

➜  parser git:(master) cd test ; go test parser_test.go 
ok  	command-line-arguments	0.044s

The Licence port from TiDB

Hope you guys enjoy this parser

sqlparser's People

Contributors

ruiaylin avatar

Stargazers

Kurt Larsen avatar Shan Huanming avatar xwinie avatar  avatar Rugwiro Valentin avatar ik5 avatar zbv avatar Arystan avatar 爱好奇 avatar ibradypod avatar Josh White avatar Charlie Hu avatar Xu Dong avatar  avatar wolfi3 avatar Leo avatar pay_attention_to_key_point avatar Matt A avatar V G avatar David Terei avatar wanghe avatar Magicshui avatar Chenglin Huang avatar Shengyu Zhang avatar tom.wen avatar tom--bo avatar elvuel avatar  avatar kerrigell avatar  avatar antdb avatar  avatar zhanglei avatar Guangning E avatar  avatar aland-zhang avatar huang jw avatar Ian Kirker avatar Alsman avatar 高庆丰 avatar ♫♨  ฏ๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎ avatar codedump avatar Chen Chenglong avatar dongxu avatar  avatar 举起手来 avatar wwc avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

sqlparser's Issues

How do you use this?

I've gotten as far as ...

stmts, err := parser.New().Parse(query, "", "")
	if err != nil {
		return nil, err
	}

	for _, stmt := range stmts {
	}

I'm trying to compare the statements and see if it's an "insert" and then iterate over the values.

compile error on mac

pengfeis-MacBook-Pro:sqlparser developer$ make
GO15VENDOREXPERIMENT="1" go get github.com/ruiaylin/sqlparser/parser/goyacc
GO15VENDOREXPERIMENT="1" go install github.com/ruiaylin/sqlparser/parser/goyacc
/Users/developer/Go/bin/goyacc -o /dev/null -xegen temp_parser_file parser/parser.y
Parse table entries: 436227 of 1058536, x 16 bits == 872454 bytes
/Users/developer/Go/bin/goyacc -o parser/parser.go -xe temp_parser_file parser/parser.y 2>&1 | egrep "(shift|reduce)/reduce" | awk '{print} END {if (NR > 0) {print "Find conflict in parser.y. Please check y.output for more information."; system("rm -f temp_parser_file"); exit 1;}}'
rm -f temp_parser_file
rm -f y.output
/Users/developer/Go/bin/golex -o parser/scanner.go parser/scanner.l
GO15VENDOREXPERIMENT="1" go test github.com/ruiaylin/sqlparser/parser

github.com/ruiaylin/sqlparser/parser

parser/lexer.go:24: cannot convert Scanner literal (type *Scanner) to type yyLexer:
*Scanner does not implement yyLexer (missing Error method)
parser/lexer.go:96: cannot use s (type *Scanner) as type yyLexer in argument to toInt:
*Scanner does not implement yyLexer (missing Error method)
parser/lexer.go:98: cannot use s (type *Scanner) as type yyLexer in argument to toFloat:
*Scanner does not implement yyLexer (missing Error method)
parser/lexer.go:100: cannot use s (type *Scanner) as type yyLexer in argument to toHex:
*Scanner does not implement yyLexer (missing Error method)
parser/lexer.go:102: cannot use s (type *Scanner) as type yyLexer in argument to toBit:
*Scanner does not implement yyLexer (missing Error method)
parser/parser.go:7475: yylex.Errorf undefined (type yyLexer has no field or method Errorf)
parser/parser.go:7752: yylex.Errorf undefined (type yyLexer has no field or method Errorf)
parser/parser.go:7831: undefined: parser in parser.startOffset
parser/parser.go:7840: undefined: parser in parser.endOffset
parser/parser.go:7841: undefined: parser
parser/parser.go:7841: too many errors
FAIL github.com/ruiaylin/sqlparser/parser [build failed]
make: *** [test] Error 2

no license

Would like to see a LICENSE file so that we know if we can use this project.

how to parse a query

Hi how can i parse a query and get every part of the query and its name?
i.e. query1: INSERT INTO QBAdminGroup.abmc_contacts(id, name) VALUES (1, 'jimmy')
output1: 'DML', 'Keyword', 'Identifier', 'Keyword', 'Parenthesis'
query2: select 2 from admin
output2: 'DML', 'Integer', 'Keyword', 'Keyword'

the query part's name no need to be the same as the outputs,but i wonder if sqlparser has similar function or something else.Thanks!

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.