parent
d3fb408c26
commit
2d241cff73
32
connector.py
32
connector.py
|
@ -2,6 +2,7 @@
|
|||
# copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.modules.edw.connector import BackendConnector
|
||||
from trytond.modules.edw.tools import evaluate_sql_domain
|
||||
import pymssql
|
||||
|
||||
INSERT_QUERY = (
|
||||
|
@ -17,11 +18,14 @@ CREATE_QUERY = (
|
|||
""" where name='%(tablename)s' and xtype='U') """ +
|
||||
""" CREATE TABLE [%(tablename)s] (%(fields)s);""")
|
||||
|
||||
DELETE_QUERY = (
|
||||
DROP_QUERY = (
|
||||
"""IF EXISTS (select * from sysobjects """ +
|
||||
""" where name='%(tablename)s' and xtype='U') """ +
|
||||
""" DROP TABLE [%(tablename)s]; """)
|
||||
|
||||
DELETE_QUERY = (
|
||||
""" DELETE FROM \"%(tablename)s\" WHERE %(where)s; """)
|
||||
|
||||
|
||||
class BackendConnectorMSsql(BackendConnector):
|
||||
"""MS SQL Connector"""
|
||||
|
@ -34,7 +38,7 @@ class BackendConnectorMSsql(BackendConnector):
|
|||
user=self.username, password=self.password, database=database)
|
||||
return conn
|
||||
|
||||
def create_table(self, fields, tablename):
|
||||
def create(self, fields, tablename):
|
||||
query = self._get_create_query(fields, tablename)
|
||||
self.execute_query(query)
|
||||
|
||||
|
@ -42,12 +46,15 @@ class BackendConnectorMSsql(BackendConnector):
|
|||
query = self._get_insert_query(tablename, results)
|
||||
self.execute_query(query, [tuple(r.values()) for r in results])
|
||||
|
||||
def truncate(self, tablename):
|
||||
query = self._get_truncate_query(tablename)
|
||||
def clean(self, tablename, domain=None):
|
||||
if not domain:
|
||||
query = self._get_truncate_query(tablename)
|
||||
else:
|
||||
query = self._get_delete_query(tablename, domain)
|
||||
self.execute_query(query)
|
||||
|
||||
def delete_table(self, tablename):
|
||||
query = self._get_delete_query(tablename)
|
||||
def drop(self, tablename):
|
||||
query = self._get_drop_query(tablename)
|
||||
self.execute_query(query)
|
||||
|
||||
def _get_create_query(self, fields, tablename):
|
||||
|
@ -71,8 +78,14 @@ class BackendConnectorMSsql(BackendConnector):
|
|||
def _get_truncate_query(self, tablename):
|
||||
return TRUNCATE_QUERY % {'tablename': tablename}
|
||||
|
||||
def _get_delete_query(self, tablename):
|
||||
return DELETE_QUERY % {'tablename': tablename}
|
||||
def _get_drop_query(self, tablename):
|
||||
return DROP_QUERY % {'tablename': tablename}
|
||||
|
||||
def _get_delete_query(self, tablename, where):
|
||||
return DELETE_QUERY % {
|
||||
'tablename': tablename,
|
||||
'where': where or '1=1'
|
||||
}
|
||||
|
||||
def get_mapped_types(self):
|
||||
return {
|
||||
|
@ -107,3 +120,6 @@ class BackendConnectorMSsql(BackendConnector):
|
|||
raise e
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
def evaluate_domain(self, model, domain):
|
||||
return evaluate_sql_domain(model, domain)
|
||||
|
|
Loading…
Reference in New Issue