Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

allow [$:] as prefix and plain ? for prepared statements#15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
oger000 wants to merge1 commit intoJavaScriptor:master
base:master
Choose a base branch
Loading
fromoger000:pr/prepared-statement
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletionssrc/sqlParser.jison
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,10 +10,12 @@
[-][-]\s.*\n /* skip sql comments */
[#]\s.*\n /* skip sql comments */
\s+ /* skip whitespace */

[`][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*[`] return 'IDENTIFIER'
[\w]+[\u4e00-\u9fa5]+[0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
[\u4e00-\u9fa5][0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
[\$:][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]* return 'PREP_TERM'
[?] return 'PREP_TERM'
SELECT return 'SELECT'
ALL return 'ALL'
ANY return 'ANY'
Expand DownExpand Up@@ -116,7 +118,7 @@ LIMIT return 'LIMIT'
"{" return '{'
"}" return '}'
";" return ';'

['](\\.|[^'])*['] return 'STRING'
["](\\.|[^"])*["] return 'STRING'
[0][x][0-9a-fA-F]+ return 'HEX_NUMERIC'
Expand All@@ -126,7 +128,7 @@ LIMIT return 'LIMIT'
[a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]* return 'IDENTIFIER'
\. return 'DOT'
['"][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*["'] return 'QUOTED_IDENTIFIER'

<<EOF>> return 'EOF'
. return 'INVALID'

Expand DownExpand Up@@ -164,7 +166,7 @@ main
;

selectClause
: SELECT
: SELECT
distinctOpt
highPriorityOpt
maxStateMentTimeOpt
Expand DownExpand Up@@ -203,7 +205,7 @@ selectClause
;

distinctOpt
: ALL { $$ = $1 }
: ALL { $$ = $1 }
| DISTINCT { $$ = $1 }
| DISTINCTROW { $$ = $1 }
| { $$ = null }
Expand DownExpand Up@@ -295,6 +297,7 @@ function_call_param
identifier
: IDENTIFIER { $$ = { type: 'Identifier', value: $1 } }
| identifier DOT IDENTIFIER { $$ = $1; $1.value += '.' + $3 }
| PREP_TERM { $$ = { type: 'Identifier', value: $1 } }
;
identifier_list
: identifier { $$ = { type: 'IdentifierList', value: [ $1 ] } }
Expand DownExpand Up@@ -336,7 +339,7 @@ simple_expr
;
bit_expr
: simple_expr { $$ = $1 }
| bit_expr '|' bit_expr { $$ = { type: 'BitExpression', operator: '|', left: $1, right: $3 } }
| bit_expr '|' bit_expr { $$ = { type: 'BitExpression', operator: '|', left: $1, right: $3 } }
| bit_expr '&' bit_expr { $$ = { type: 'BitExpression', operator: '&', left: $1, right: $3 } }
| bit_expr '<<' bit_expr { $$ = { type: 'BitExpression', operator: '<<', left: $1, right: $3 } }
| bit_expr '>>' bit_expr { $$ = { type: 'BitExpression', operator: '>>', left: $1, right: $3 } }
Expand DownExpand Up@@ -446,6 +449,7 @@ limit
: LIMIT NUMERIC { $$ = { type: 'Limit', value: [ $2 ] } }
| LIMIT NUMERIC ',' NUMERIC { $$ = { type: 'Limit', value: [ $2, $4 ] } }
| LIMIT NUMERIC OFFSET NUMERIC { $$ = { type: 'Limit', value: [ $4, $2 ], offsetMode: true } }
| LIMIT PREP_TERM { $$ = { type: 'Limit', value: [ $2 ] } }
;
limit_opt
: { $$ = null }
Expand Down
4 changes: 3 additions & 1 deletiontest/main.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -360,5 +360,7 @@ describe('select grammar support', function () {
testParser('SELECT COUNT(*) AS total FROM b');
});

it ('allow prepared statement prefix ("$" or ":") or plain ?.', function () {
testParser('SELECT * FROM b WHERE id=$id OR id=:id ORDER BY ?');
});
});


[8]ページ先頭

©2009-2025 Movatter.jp