Skip to content

Commit

Permalink
Merge branch 'master' into orm
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Apr 20, 2019
2 parents 12ad059 + e9f97b2 commit b4b338d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
13 changes: 13 additions & 0 deletions BACKERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sponsors & Backers

Pony ORM is Apache 2.0 licensed open source project. If you would like to support Pony ORM development, please consider:

[Become a backer or sponsor](https://ponyorm.org/donation.html)

## Backers

- Sergio Aguilar Guerrero
- David ROUBLOT
- Elijas Dapšauskas
- Dan Swain

6 changes: 5 additions & 1 deletion pony/orm/dbproviders/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ def JSON_ARRAY_LENGTH(builder, value):
throw(TranslationError, 'Oracle does not provide `length` function for JSON arrays')
def GROUP_CONCAT(builder, distinct, expr, sep=None):
assert distinct in (None, True, False)
result = 'LISTAGG(', builder(expr)
if distinct and builder.provider.server_version >= (19,):
distinct = 'DISTINCT '
else:
distinct = ''
result = 'LISTAGG(', distinct, builder(expr)
if sep is not None:
result = result, ', ', builder(sep)
else:
Expand Down
8 changes: 7 additions & 1 deletion pony/orm/dbproviders/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def sql_type(converter):
return dbapiprovider.IntConverter.sql_type(converter)

class SQLiteDecimalConverter(dbapiprovider.DecimalConverter):
inf = Decimal('infinity')
neg_inf = Decimal('-infinity')
NaN = Decimal('NaN')
def sql2py(converter, val):
try: val = Decimal(str(val))
except: return val
Expand All @@ -182,7 +185,10 @@ def sql2py(converter, val):
def py2sql(converter, val):
if type(val) is not Decimal: val = Decimal(val)
exp = converter.exp
if exp is not None: val = val.quantize(exp)
if exp is not None:
if val in (converter.inf, converter.neg_inf, converter.NaN):
throw(ValueError, 'Cannot store %s Decimal value in database' % val)
val = val.quantize(exp)
return str(val)

class SQLiteDateConverter(dbapiprovider.DateConverter):
Expand Down
5 changes: 4 additions & 1 deletion pony/orm/sqlbuilding.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,10 @@ def GROUP_CONCAT(builder, distinct, expr, sep=None):
assert distinct in (None, True, False)
result = distinct and 'GROUP_CONCAT(DISTINCT ' or 'GROUP_CONCAT(', builder(expr)
if sep is not None:
result = result, ', ', builder(sep)
if builder.provider.dialect == 'MySQL':
result = result, ' SEPARATOR ', builder(sep)
else:
result = result, ', ', builder(sep)
return result, ')'
UPPER = make_unary_func('upper')
LOWER = make_unary_func('lower')
Expand Down
1 change: 1 addition & 0 deletions pony/orm/tests/test_declarative_func_monad.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def test_datetime_now1(self):
self.assertEqual(result, {Student[1], Student[2], Student[3], Student[4], Student[5]})
@raises_exception(ExprEvalError, "`1 < datetime.now()` raises TypeError: " + (
"can't compare 'datetime' to 'int'" if PYPY2 else
"'<' not supported between instances of 'int' and 'datetime'" if PYPY and sys.version_info >= (3, 6) else
"unorderable types: int < datetime" if PYPY else
"can't compare datetime.datetime to int" if PY2 else
"unorderable types: int() < datetime.datetime()" if sys.version_info < (3, 6) else
Expand Down
6 changes: 4 additions & 2 deletions pony/orm/tests/test_select_from_select_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pony.orm import *
from pony.orm.tests.testutils import *
from pony.py23compat import PYPY2

db = Database('sqlite', ':memory:')

Expand Down Expand Up @@ -88,7 +89,8 @@ def test_6(self): # selecting hybrid property in the first query
self.assertEqual(db.last_sql.count('SELECT'), 1)

@db_session
@raises_exception(ExprEvalError, "`s.scholarship > 0` raises NameError: name 's' is not defined")
@raises_exception(ExprEvalError, "`s.scholarship > 0` raises NameError: name 's' is not defined" if not PYPY2
else "`s.scholarship > 0` raises NameError: global name 's' is not defined")
def test_7(self): # test access to original query var name from the new query
q = select(s.first_name for s in Student if s.scholarship < 500)
q2 = select(x for x in q if s.scholarship > 0)
Expand Down Expand Up @@ -377,7 +379,7 @@ def test_44(self):

@db_session
def test_45(self):
q = select(s for s in Student).order_by(Student.first_name).limit(3, offset=1)
q = select(s for s in Student).order_by(Student.first_name, Student.id).limit(3, offset=1)
q2 = select(s for s in q if s.age > 18).limit(2, offset=1)
q3 = select(s.last_name for s in q2).limit(2, offset=1)
self.assertEqual(set(q3), {'Brown'})
Expand Down

0 comments on commit b4b338d

Please sign in to comment.