mirror of
https://gitlab.com/datalifeit/trytond-edw_mssql
synced 2023-12-14 05:52:58 +01:00
Simplify field mapping code.
This commit is contained in:
parent
44f36eed79
commit
93985a63e4
27
connector.py
27
connector.py
|
@ -1,25 +1,26 @@
|
||||||
# The COPYRIGHT file at the top level of this repository contains the full
|
# The COPYRIGHT file at the top level of this repository contains the full
|
||||||
# copyright notices and license terms.
|
# copyright notices and license terms.
|
||||||
|
from trytond.model import fields
|
||||||
from trytond.modules.edw.instance import BackendConnector
|
from trytond.modules.edw.instance import BackendConnector
|
||||||
import pymssql
|
import pymssql
|
||||||
|
|
||||||
INSERT_QUERY = (
|
INSERT_QUERY = (
|
||||||
"""INSERT INTO "%(tablename)s" """ +
|
"""INSERT INTO "%(tablename)s" """ +
|
||||||
"""(%(fields)s) """ +
|
"""(%(fields)s) """ +
|
||||||
"""VALUES (%(values)s)""")
|
"""VALUES (%(values)s);""")
|
||||||
|
|
||||||
TRUNCATE_QUERY = (
|
TRUNCATE_QUERY = (
|
||||||
"""TRUNCATE TABLE "%(tablename)s" """)
|
"""TRUNCATE TABLE "%(tablename)s"; """)
|
||||||
|
|
||||||
CREATE_QUERY = (
|
CREATE_QUERY = (
|
||||||
"""IF NOT EXISTS (select * from sysobjects """ +
|
"""IF NOT EXISTS (select * from sysobjects """ +
|
||||||
""" where name='%(tablename)s' and xtype='U') """ +
|
""" where name='%(tablename)s' and xtype='U') """ +
|
||||||
""" CREATE TABLE "%(tablename)s" (%(fields)s)""")
|
""" CREATE TABLE "%(tablename)s" (%(fields)s);""")
|
||||||
|
|
||||||
DELETE_QUERY = (
|
DELETE_QUERY = (
|
||||||
"""IF EXISTS (select * from sysobjects """ +
|
"""IF EXISTS (select * from sysobjects """ +
|
||||||
""" where name='%(tablename)s' and xtype='U') """ +
|
""" where name='%(tablename)s' and xtype='U') """ +
|
||||||
""" DROP TABLE "%(tablename)s" """)
|
""" DROP TABLE "%(tablename)s"; """)
|
||||||
|
|
||||||
|
|
||||||
class BackendConnectorMSsql(BackendConnector):
|
class BackendConnectorMSsql(BackendConnector):
|
||||||
|
@ -74,13 +75,17 @@ class BackendConnectorMSsql(BackendConnector):
|
||||||
|
|
||||||
def get_mapped_types(self):
|
def get_mapped_types(self):
|
||||||
return {
|
return {
|
||||||
'integer': 'int',
|
fields.Integer: 'int',
|
||||||
'char': 'nvarchar(max)',
|
fields.Many2One: 'int',
|
||||||
'date': 'date',
|
fields.Char: 'nvarchar(max)',
|
||||||
'numeric': 'numeric',
|
fields.Text: 'nvarchar(max)',
|
||||||
'timedelta': 'nvarchar(32)',
|
fields.Selection: 'nvarchar(max)',
|
||||||
'timestamp': 'datetime',
|
fields.Date: 'date',
|
||||||
'float': 'numeric(18,0)'
|
fields.Numeric: 'numeric(32, 18)',
|
||||||
|
fields.TimeDelta: 'nvarchar(32)',
|
||||||
|
fields.Timestamp: 'datetime',
|
||||||
|
fields.Float: 'numeric(32, 18)',
|
||||||
|
fields.Reference: 'nvarchar(max)'
|
||||||
}
|
}
|
||||||
|
|
||||||
def execute_query(self, query, results=None):
|
def execute_query(self, query, results=None):
|
||||||
|
|
Loading…
Reference in a new issue