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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
erp5
Commits
8e073789
Commit
8e073789
authored
May 25, 2015
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up sqlvar patch
parent
e0388ecc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
60 deletions
+29
-60
product/ERP5Type/patches/sqlvar.py
product/ERP5Type/patches/sqlvar.py
+29
-60
No files found.
product/ERP5Type/patches/sqlvar.py
View file @
8e073789
...
@@ -17,100 +17,69 @@
...
@@ -17,100 +17,69 @@
from
Shared.DC.ZRDB.sqlvar
import
SQLVar
from
Shared.DC.ZRDB.sqlvar
import
SQLVar
from
Shared.DC.ZRDB
import
sqlvar
from
Shared.DC.ZRDB
import
sqlvar
from
string
import
atoi
,
atof
from
string
import
atoi
,
atof
from
types
import
StringType
from
Products.ERP5Type.PsycoWrapper
import
psyco
from
DateTime
import
DateTime
from
DateTime
import
DateTime
def
SQLVar_render
(
self
,
md
):
def
SQLVar_render
(
self
,
md
):
name
=
self
.
__name__
args
=
self
.
args
args
=
self
.
args
t
=
args
[
'type'
]
t
=
args
[
'type'
]
try
:
try
:
expr
=
self
.
expr
expr
=
self
.
expr
if
type
(
expr
)
is
type
(
''
)
:
v
=
md
[
expr
]
if
type
(
expr
)
is
str
:
v
=
md
[
expr
]
else
:
v
=
expr
(
md
)
else
:
v
=
expr
(
md
)
except
:
except
Exception
:
if
args
.
has_key
(
'optional'
)
and
args
[
'optional'
]
:
if
args
.
get
(
'optional'
)
:
return
'null'
return
'null'
if
type
(
expr
)
is
not
type
(
''
)
:
if
type
(
expr
)
is
not
str
:
raise
raise
raise
ValueError
,
'Missing input variable, <em>%s</em>'
%
name
raise
ValueError
(
'Missing input variable, <em>%s</em>'
%
self
.
__name__
)
if
v
is
None
and
args
.
get
(
'optional'
):
return
'null'
if
t
==
'int'
:
if
t
==
'int'
:
try
:
try
:
if
type
(
v
)
is
StringType
:
if
type
(
v
)
is
str
:
if
v
[
-
1
:]
==
'L'
:
if
v
[
-
1
:]
==
'L'
:
v
=
v
[:
-
1
]
v
=
v
[:
-
1
]
atoi
(
v
)
atoi
(
v
)
else
:
v
=
str
(
int
(
v
))
return
v
except
:
return
str
(
int
(
v
))
if
not
v
and
args
.
has_key
(
'optional'
)
and
args
[
'optional'
]:
except
Exception
:
return
'null'
t
=
'integer'
raise
ValueError
,
(
'Invalid integer value for <em>%s</em>: %r'
%
(
name
,
v
))
elif
t
==
'float'
:
elif
t
==
'float'
:
try
:
try
:
if
type
(
v
)
is
StringType
:
if
type
(
v
)
is
str
:
if
v
[
-
1
:]
==
'L'
:
if
v
[
-
1
:]
==
'L'
:
v
=
v
[:
-
1
]
v
=
v
[:
-
1
]
atof
(
v
)
atof
(
v
)
return
v
# ERP5 patch, we use repr that have better precision than str for
# ERP5 patch, we use repr that have better precision than str for
# floats
# floats
else
:
v
=
repr
(
float
(
v
))
return
repr
(
float
(
v
))
except
:
except
Exception
:
if
not
v
and
args
.
has_key
(
'optional'
)
and
args
[
'optional'
]:
t
=
'floating-point'
return
'null'
raise
ValueError
,
(
'Invalid floating-point value for <em>%s</em>: %r'
%
(
name
,
v
))
# Patched by yo
elif
t
==
'datetime'
:
elif
t
==
'datetime'
:
if
v
is
None
:
if
args
.
has_key
(
'optional'
)
and
args
[
'optional'
]:
return
'null'
else
:
raise
ValueError
,
(
'Invalid datetime value for <em>%s</em>: %r'
%
(
name
,
v
))
try
:
try
:
v
=
(
v
if
isinstance
(
v
,
DateTime
)
else
DateTime
(
v
)).
toZone
(
'UTC'
)
v
=
(
v
if
isinstance
(
v
,
DateTime
)
else
DateTime
(
v
)).
toZone
(
'UTC'
)
# For subsecond precision in MySQL, use 'datetime(N)' type,
# For subsecond precision in MySQL, use 'datetime(N)' type,
# where N is the number of digits after the decimal point.
# where N is the number of digits after the decimal point.
v
=
"'%s.%06u'"
%
(
v
.
ISO
(),
v
.
micros
()
%
1000000
)
return
"'%s.%06u'"
%
(
v
.
ISO
(),
v
.
micros
()
%
1000000
)
except
:
except
Exception
:
if
not
v
and
args
.
has_key
(
'optional'
)
and
args
[
'optional'
]:
pass
return
'null'
elif
t
==
'nb'
and
not
v
:
raise
ValueError
,
(
t
=
'empty string'
'Invalid datetime value for <em>%s</em>: %r'
%
(
name
,
v
))
# End of patch
else
:
# Patched by yo
if
v
is
None
:
if
args
.
has_key
(
'optional'
)
and
args
[
'optional'
]:
return
'null'
else
:
raise
ValueError
,
(
'Invalid string value for <em>%s</em>: %r'
%
(
name
,
v
))
# End of patch
if
not
isinstance
(
v
,
(
str
,
unicode
)):
v
=
str
(
v
)
if
not
v
and
t
==
'nb'
:
if
args
.
has_key
(
'optional'
)
and
args
[
'optional'
]:
return
'null'
else
:
else
:
raise
ValueError
,
(
v
=
md
.
getitem
(
'sql_quote__'
,
0
)(
'Invalid empty string value for <em>%s</em>'
%
name
)
v
if
isinstance
(
v
,
basestring
)
else
str
(
v
))
v
=
md
.
getitem
(
'sql_quote__'
,
0
)(
v
)
#if find(v,"\'") >= 0: v=join(split(v,"\'"),"''")
#if find(v,"\'") >= 0: v=join(split(v,"\'"),"''")
#v="'%s'" % v
#v="'%s'" % v
return
v
return
v
psyco
.
bind
(
SQLVar_render
)
raise
ValueError
(
'Invalid %s value for <em>%s</em>: %r'
%
(
t
,
self
.
__name__
,
v
))
# Patched by yo. datetime is added.
# Patched by yo. datetime is added.
valid_type
=
{
'int'
:
1
,
'float'
:
1
,
'string'
:
1
,
'nb'
:
1
,
'datetime'
:
1
}.
has_key
valid_type
=
(
'int'
,
'float'
,
'string'
,
'nb'
,
'datetime'
).
__contains__
SQLVar
.
render
=
SQLVar_render
SQLVar
.
render
=
SQLVar_render
SQLVar
.
__call__
=
SQLVar_render
SQLVar
.
__call__
=
SQLVar_render
...
...
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