#!/usr/bin/python # -*- coding: utf-8 -*- # --------------------------------------------------------------------------------------------------------- # Author : Ulrich Carmesin # Source : gitea.ucarmesin.de # --------------------------------------------------------------------------------------------------------- import basic.program import utils.config_tool import basic.constants as B import os class 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): self.comp = None pass def setComp(self, comp): self.comp = comp def selectTables(self): """ method to delete rows from a database statement written in sql """ self.loadDdl() tdata = {} for t in self.comp.conf[B.DATA_NODE_DDL]: tdata[t] = self.selectRows(t) return tdata def selectRows(self, statement): """ method to select rows from a database statement written in sql """ raise Exception("method is not implemented") def deleteTables(self): """ method to delete rows from a database statement written in sql """ self.loadDdl() for t in self.comp.conf[B.DATA_NODE_DDL]: print("zu loeschende Tabelle "+t) self.deleteRows(t) def deleteRows(self, table): """ method to delete rows from a database statement written in sql """ raise Exception("method is not implemented") def updateRows(self, statement): """ method to delete rows from a database statement written in sql """ raise Exception("method is not implemented") def getConnector(self): """ add-on-method to get the connector this method should only called by the class itself """ raise Exception("method is not implemented") def insertTables(self, tdata): """ method to insert rows into a database statement written in sql """ plainname = basic.componentHandling.getPlainCompname(self.comp.name) self.loadDdl() for t in self.comp.conf["ddl"]: print("einzufuegende Tabelle "+t) if (t in tdata[plainname]): self.insertRows(t, tdata[plainname][t][B.DATA_NODE_DATA]) def insertRows(self, rows): """ method to insert rows into a database the rows will be interpreted by the ddl of the component """ raise Exception("method is not implemented") def execStatement(self, statement): """ add-on-method to execute the statement this method should only called by the class itself """ raise Exception("method is not implemented") def loadDdl(self): job = basic.program.Job.getInstance() if (B.DATA_NODE_DDL in self.comp.conf): return conf = utils.config_tool.getConfig("DATASTRUCTURE", self.comp.name) self.comp.conf[B.DATA_NODE_DDL] = {} for k in conf[self.comp.name]: self.comp.conf[B.DATA_NODE_DDL][k] = conf[self.comp.name][k] return conf[self.comp.name] def getWhere(self): return "" def getOrder(self): return "" def getDbValue(self, fo, value): if len(value.strip()) == 0 and fo["nullable"] == "y": return self.getDbNull() if fo["type"] == "string": return "'"+value.strip()+"'" elif fo["type"] == "int": return value.strip() elif fo["type"] == "double": return self.getDbDouble(value) elif fo["type"] == "float": return self.getDbFloat(value) elif fo["type"] == "date": return self.getDbDate(value) elif fo["type"] == "time": return self.getDbTime(value) def getDbDouble(self, value): return value def getDbFloat(self, value): return value def getDbDate(self, value): return value def getDbTime(self, value): return value def getDbNull(self): return "null"