Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alecs_myu
erp5
Commits
aac3b08b
Commit
aac3b08b
authored
Jun 13, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ZSQLCatalog: optimize rendering of values
parent
a162f0a5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
16 deletions
+20
-16
product/ZSQLCatalog/Operator/OperatorBase.py
product/ZSQLCatalog/Operator/OperatorBase.py
+20
-16
No files found.
product/ZSQLCatalog/Operator/OperatorBase.py
View file @
aac3b08b
...
...
@@ -29,6 +29,7 @@
##############################################################################
from
zLOG
import
LOG
from
DateTime
import
DateTime
from
Products.ZSQLCatalog.interfaces.operator
import
IOperator
from
Products.ZSQLCatalog.Utils
import
sqlquote
as
escapeString
from
zope.interface.verify
import
verifyClass
...
...
@@ -50,16 +51,18 @@ def valueNoneRenderer(value):
return
'NULL'
value_renderer
=
{
'int'
:
str
,
'long'
:
str
,
'float'
:
valueFloatRenderer
,
'DateTime'
:
valueDateTimeRenderer
,
'NoneType'
:
valueNoneRenderer
,
'bool'
:
int
,
int
:
str
,
long
:
str
,
float
:
valueFloatRenderer
,
DateTime
:
valueDateTimeRenderer
,
None
.
__class__
:
valueNoneRenderer
,
bool
:
int
,
str
:
escapeString
,
unicode
:
escapeString
,
}
value_search_text_renderer
=
{
'DateTime'
:
str
,
DateTime
:
str
,
}
def
valueDefaultSearchTextRenderer
(
value
):
...
...
@@ -111,7 +114,9 @@ class OperatorBase(object):
def
getOperatorSearchText
(
self
):
return
self
.
operator_search_text
def
_render
(
self
,
column
,
value
):
def
_render
(
self
,
column
,
value
,
value_renderer_get
=
{
k
.
__name__
:
v
for
k
,
v
in
value_renderer
.
iteritems
()}.
get
):
"""
Render given column and value for use in SQL.
Value is rendered to convert it to SQL-friendly value.
...
...
@@ -125,26 +130,25 @@ class OperatorBase(object):
if
isinstance
(
value
,
dict
):
type
=
value
[
'type'
]
column
=
column_renderer
.
get
(
type
,
columnDefaultRenderer
)(
column
,
format
=
value
[
'format'
])
value
=
value_renderer
.
get
(
type
,
valueDefaultRenderer
)(
value
[
'query'
])
value
=
value_renderer
_
get
(
type
,
valueDefaultRenderer
)(
value
[
'query'
])
else
:
value
=
self
.
_renderValue
(
value
)
return
column
,
value
def
_renderValue
(
self
,
value
):
def
_renderValue
(
self
,
value
,
value_renderer_get
=
value_renderer
.
get
,
valueDefaultRenderer
=
valueDefaultRenderer
):
"""
Render given value as string.
value (int, float, long, DateTime, string, None)
Value to render as a string for use in SQL (quoted, escaped).
"""
if
isinstance
(
value
,
basestring
):
value
=
escapeString
(
value
)
else
:
value
=
value_renderer
.
get
(
value
.
__class__
.
__name__
,
valueDefaultRenderer
)(
value
)
return
value
return
value_renderer_get
(
value
.
__class__
,
valueDefaultRenderer
)(
value
)
def
asSearchText
(
self
,
value
):
return
value_search_text_renderer
.
get
(
value
.
__class__
.
__name__
,
valueDefaultSearchTextRenderer
)(
value
)
return
value_search_text_renderer
.
get
(
value
.
__class__
,
valueDefaultSearchTextRenderer
)(
value
)
def
asSQLExpression
(
self
,
column
,
value_list
,
only_group_columns
):
raise
NotImplementedError
,
'This method must be overloaded by a subclass '
\
...
...
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