Set type declaration in column names of SQLite only on top-level query
Closes #12532 (grafted from c07764f86f1655997d1271a5d2b30b9607a02a72) --HG-- branch : 7.0
This commit is contained in:
@@ -2,20 +2,13 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from decimal import Decimal
|
||||
|
||||
from sql import As, Cast, CombiningQuery, Literal, Select
|
||||
from sql import Cast, CombiningQuery, Literal, Select
|
||||
|
||||
from trytond import backend
|
||||
|
||||
from .float import Float
|
||||
|
||||
|
||||
class SQLite_Cast(Cast):
|
||||
|
||||
def as_(self, output_name):
|
||||
# Use PARSE_COLNAMES instead of CAST for final column
|
||||
return As(self.expression, '%s [NUMERIC]' % output_name)
|
||||
|
||||
|
||||
class Numeric(Float):
|
||||
'''
|
||||
Define a numeric field (``decimal``).
|
||||
@@ -24,18 +17,16 @@ class Numeric(Float):
|
||||
_sql_type = 'NUMERIC'
|
||||
_py_type = Decimal
|
||||
|
||||
def sql_column(self, table):
|
||||
column = super(Numeric, self).sql_column(table)
|
||||
db_type = backend.name
|
||||
if db_type == 'sqlite':
|
||||
def _domain_column(self, operator, column):
|
||||
column = super()._domain_column(operator, column)
|
||||
if backend.name == 'sqlite':
|
||||
# Must be casted as Decimal is stored as bytes
|
||||
column = SQLite_Cast(column, self.sql_type().base)
|
||||
column = Cast(column, self.sql_type().base)
|
||||
return column
|
||||
|
||||
def _domain_value(self, operator, value):
|
||||
value = super(Numeric, self)._domain_value(operator, value)
|
||||
db_type = backend.name
|
||||
if db_type == 'sqlite':
|
||||
if backend.name == 'sqlite':
|
||||
if isinstance(value, (Select, CombiningQuery)):
|
||||
return value
|
||||
# Must be casted as Decimal is adapted to bytes
|
||||
|
||||
@@ -1784,6 +1784,11 @@ class ModelSQL(ModelStorage):
|
||||
# compute it here because __search_order might modify tables
|
||||
table = convert_from(None, tables)
|
||||
columns = cls.__searched_columns(main_table, eager=not query)
|
||||
if backend.name == 'sqlite':
|
||||
for column in columns:
|
||||
field = cls._fields.get(column.output_name)
|
||||
if field:
|
||||
column.output_name += ' [%s]' % field.sql_type().base
|
||||
select = table.select(
|
||||
*columns, where=expression, limit=limit, offset=offset,
|
||||
order_by=order_by)
|
||||
|
||||
Reference in New Issue
Block a user