Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5-Boxiang
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
Hamza
erp5-Boxiang
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 @@
...
@@ -29,6 +29,7 @@
##############################################################################
##############################################################################
from
zLOG
import
LOG
from
zLOG
import
LOG
from
DateTime
import
DateTime
from
Products.ZSQLCatalog.interfaces.operator
import
IOperator
from
Products.ZSQLCatalog.interfaces.operator
import
IOperator
from
Products.ZSQLCatalog.Utils
import
sqlquote
as
escapeString
from
Products.ZSQLCatalog.Utils
import
sqlquote
as
escapeString
from
zope.interface.verify
import
verifyClass
from
zope.interface.verify
import
verifyClass
...
@@ -50,16 +51,18 @@ def valueNoneRenderer(value):
...
@@ -50,16 +51,18 @@ def valueNoneRenderer(value):
return
'NULL'
return
'NULL'
value_renderer
=
{
value_renderer
=
{
'int'
:
str
,
int
:
str
,
'long'
:
str
,
long
:
str
,
'float'
:
valueFloatRenderer
,
float
:
valueFloatRenderer
,
'DateTime'
:
valueDateTimeRenderer
,
DateTime
:
valueDateTimeRenderer
,
'NoneType'
:
valueNoneRenderer
,
None
.
__class__
:
valueNoneRenderer
,
'bool'
:
int
,
bool
:
int
,
str
:
escapeString
,
unicode
:
escapeString
,
}
}
value_search_text_renderer
=
{
value_search_text_renderer
=
{
'DateTime'
:
str
,
DateTime
:
str
,
}
}
def
valueDefaultSearchTextRenderer
(
value
):
def
valueDefaultSearchTextRenderer
(
value
):
...
@@ -111,7 +114,9 @@ class OperatorBase(object):
...
@@ -111,7 +114,9 @@ class OperatorBase(object):
def
getOperatorSearchText
(
self
):
def
getOperatorSearchText
(
self
):
return
self
.
operator_search_text
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.
Render given column and value for use in SQL.
Value is rendered to convert it to SQL-friendly value.
Value is rendered to convert it to SQL-friendly value.
...
@@ -125,26 +130,25 @@ class OperatorBase(object):
...
@@ -125,26 +130,25 @@ class OperatorBase(object):
if
isinstance
(
value
,
dict
):
if
isinstance
(
value
,
dict
):
type
=
value
[
'type'
]
type
=
value
[
'type'
]
column
=
column_renderer
.
get
(
type
,
columnDefaultRenderer
)(
column
,
format
=
value
[
'format'
])
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
:
else
:
value
=
self
.
_renderValue
(
value
)
value
=
self
.
_renderValue
(
value
)
return
column
,
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.
Render given value as string.
value (int, float, long, DateTime, string, None)
value (int, float, long, DateTime, string, None)
Value to render as a string for use in SQL (quoted, escaped).
Value to render as a string for use in SQL (quoted, escaped).
"""
"""
if
isinstance
(
value
,
basestring
):
return
value_renderer_get
(
value
.
__class__
,
valueDefaultRenderer
)(
value
)
value
=
escapeString
(
value
)
else
:
value
=
value_renderer
.
get
(
value
.
__class__
.
__name__
,
valueDefaultRenderer
)(
value
)
return
value
def
asSearchText
(
self
,
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
):
def
asSQLExpression
(
self
,
column
,
value_list
,
only_group_columns
):
raise
NotImplementedError
,
'This method must be overloaded by a subclass '
\
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