Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.7 KiB

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import basic.program
import utils.config_tool
import utils.db_abstract
import basic.constants as B
import utils.path_tool
import utils.file_tool
import utils.tdata_tool
class DbFcts(utils.db_abstract.DbFcts):
"""
This interface defines each necessary connection to any kind of database.
The specific technique how to connect to the concrete DBMS has to be implemented in the specific tool.
"""
def __init__(self):
pass
def selectRows(self, table, job):
""" method to select rows from a database
statement written in sql """
sqlTable = utils.db_abstract.getSqlTable(self.comp, table)
header = ""
path = utils.path_tool.composePattern(job, "{env.dompath}/"+sqlTable+".csv", self.comp)
print(path)
tdata = {}
data = utils.tdata_tool.readCsv(self.comp.m, job, path, self.comp)
tdata[B.DATA_NODE_HEADER] = self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]
if B.DATA_NODE_TABLES in data \
and table in data[B.DATA_NODE_TABLES]\
and B.DATA_NODE_DATA in data[B.DATA_NODE_TABLES][table]:
tdata[B.DATA_NODE_DATA] = data[B.DATA_NODE_TABLES][table][B.DATA_NODE_DATA]
else:
tdata[B.DATA_NODE_DATA] = {}
return tdata
def deleteRows(self, table, job):
""" method to delete rows from a database
statement written in sql """
verify = -1+job.getDebugLevel("db_tool")
sqlTable = utils.db_abstract.getSqlTable(self.comp, table)
header = ""
path = utils.path_tool.composePattern(job, "{env.dompath}/"+sqlTable+".csv", self.comp)
for h in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]:
print(h)
header += ";"+h
cmd = header[1:]+"\n"
utils.file_tool.writeFileText(self.comp.m, job, path, cmd)
self.comp.m.logInfo(cmd)
def updateRows(self, statement):
""" method to delete rows from a database
statement written in sql """
raise Exception(B.EXCEPT_NOT_IMPLEMENT)
def insertRows(self, table, rows, job):
""" method to insert rows into a database
the rows will be interpreted by the ddl of the component
"""
verify = -1+job.getDebugLevel("db_tool")
sqlTable = utils.db_abstract.getSqlTable(self.comp, table)
header = ""
path = utils.path_tool.composePattern(job, "{env.dompath}/"+sqlTable+".csv", self.comp)
if len(rows) == 0:
return ""
else:
pass
for h in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]:
print(h)
header += ";"+h
cmd = "table:" + table + header+"\n"
print("HEADER : "+cmd)
rowvalues = ""
for r in rows:
if not utils.db_abstract.isCompRow(self.comp, r):
continue
print("r-----------------")
print(r)
rowvalues = self.comp.name+":"+table
for h in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]:
print("head "+h)
if h in [B.DATA_NODE_HEADER, B.DATA_NODE_DATA]:
continue
print("h "+h)
if (h in r):
rowvalues += ";"+str(self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][h], r[h]))
else:
rowvalues += ";"+str(self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][h], ""))
print("rv " + rowvalues)
cmd += rowvalues+"\n"
utils.file_tool.writeFileText(self.comp.m, job, path, cmd)
self.comp.m.logInfo(cmd)
def getConnector(self):
""" add-on-method to get the connector
this method should only called by the class itself """
#job = basic.program.Job.getInstance()
return ""