Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
news
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sartika Aritonang
news
Commits
6fd7748c
Commit
6fd7748c
authored
May 29, 2020
by
Sartika Aritonang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
bef84408
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
0 deletions
+124
-0
output.py
stbi/Lib/site-packages/sqlparse/filters/output.py
+124
-0
No files found.
stbi/Lib/site-packages/sqlparse/filters/output.py
0 → 100644
View file @
6fd7748c
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2018 the sqlparse authors and contributors
# <see AUTHORS file>
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
from
sqlparse
import
sql
,
tokens
as
T
from
sqlparse.compat
import
text_type
class
OutputFilter
(
object
):
varname_prefix
=
''
def
__init__
(
self
,
varname
=
'sql'
):
self
.
varname
=
self
.
varname_prefix
+
varname
self
.
count
=
0
def
_process
(
self
,
stream
,
varname
,
has_nl
):
raise
NotImplementedError
def
process
(
self
,
stmt
):
self
.
count
+=
1
if
self
.
count
>
1
:
varname
=
u'{f.varname}{f.count}'
.
format
(
f
=
self
)
else
:
varname
=
self
.
varname
has_nl
=
len
(
text_type
(
stmt
)
.
strip
()
.
splitlines
())
>
1
stmt
.
tokens
=
self
.
_process
(
stmt
.
tokens
,
varname
,
has_nl
)
return
stmt
class
OutputPythonFilter
(
OutputFilter
):
def
_process
(
self
,
stream
,
varname
,
has_nl
):
# SQL query assignation to varname
if
self
.
count
>
1
:
yield
sql
.
Token
(
T
.
Whitespace
,
'
\n
'
)
yield
sql
.
Token
(
T
.
Name
,
varname
)
yield
sql
.
Token
(
T
.
Whitespace
,
' '
)
yield
sql
.
Token
(
T
.
Operator
,
'='
)
yield
sql
.
Token
(
T
.
Whitespace
,
' '
)
if
has_nl
:
yield
sql
.
Token
(
T
.
Operator
,
'('
)
yield
sql
.
Token
(
T
.
Text
,
"'"
)
# Print the tokens on the quote
for
token
in
stream
:
# Token is a new line separator
if
token
.
is_whitespace
and
'
\n
'
in
token
.
value
:
# Close quote and add a new line
yield
sql
.
Token
(
T
.
Text
,
" '"
)
yield
sql
.
Token
(
T
.
Whitespace
,
'
\n
'
)
# Quote header on secondary lines
yield
sql
.
Token
(
T
.
Whitespace
,
' '
*
(
len
(
varname
)
+
4
))
yield
sql
.
Token
(
T
.
Text
,
"'"
)
# Indentation
after_lb
=
token
.
value
.
split
(
'
\n
'
,
1
)[
1
]
if
after_lb
:
yield
sql
.
Token
(
T
.
Whitespace
,
after_lb
)
continue
# Token has escape chars
elif
"'"
in
token
.
value
:
token
.
value
=
token
.
value
.
replace
(
"'"
,
"
\\
'"
)
# Put the token
yield
sql
.
Token
(
T
.
Text
,
token
.
value
)
# Close quote
yield
sql
.
Token
(
T
.
Text
,
"'"
)
if
has_nl
:
yield
sql
.
Token
(
T
.
Operator
,
')'
)
class
OutputPHPFilter
(
OutputFilter
):
varname_prefix
=
'$'
def
_process
(
self
,
stream
,
varname
,
has_nl
):
# SQL query assignation to varname (quote header)
if
self
.
count
>
1
:
yield
sql
.
Token
(
T
.
Whitespace
,
'
\n
'
)
yield
sql
.
Token
(
T
.
Name
,
varname
)
yield
sql
.
Token
(
T
.
Whitespace
,
' '
)
if
has_nl
:
yield
sql
.
Token
(
T
.
Whitespace
,
' '
)
yield
sql
.
Token
(
T
.
Operator
,
'='
)
yield
sql
.
Token
(
T
.
Whitespace
,
' '
)
yield
sql
.
Token
(
T
.
Text
,
'"'
)
# Print the tokens on the quote
for
token
in
stream
:
# Token is a new line separator
if
token
.
is_whitespace
and
'
\n
'
in
token
.
value
:
# Close quote and add a new line
yield
sql
.
Token
(
T
.
Text
,
' ";'
)
yield
sql
.
Token
(
T
.
Whitespace
,
'
\n
'
)
# Quote header on secondary lines
yield
sql
.
Token
(
T
.
Name
,
varname
)
yield
sql
.
Token
(
T
.
Whitespace
,
' '
)
yield
sql
.
Token
(
T
.
Operator
,
'.='
)
yield
sql
.
Token
(
T
.
Whitespace
,
' '
)
yield
sql
.
Token
(
T
.
Text
,
'"'
)
# Indentation
after_lb
=
token
.
value
.
split
(
'
\n
'
,
1
)[
1
]
if
after_lb
:
yield
sql
.
Token
(
T
.
Whitespace
,
after_lb
)
continue
# Token has escape chars
elif
'"'
in
token
.
value
:
token
.
value
=
token
.
value
.
replace
(
'"'
,
'
\\
"'
)
# Put the token
yield
sql
.
Token
(
T
.
Text
,
token
.
value
)
# Close quote
yield
sql
.
Token
(
T
.
Text
,
'"'
)
yield
sql
.
Token
(
T
.
Punctuation
,
';'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment