#!/usr/bin/python # -*- coding: utf-8 -*- # --------------------------------------------------------------------------------------------------------- # Author : Ulrich Carmesin # Source : gitea.ucarmesin.de # --------------------------------------------------------------------------------------------------------- import basic.program import utils.config_tool import utils.db_abstract 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): """ method to select rows from a database statement written in sql """ tdata = {} return tdata def deleteRows(self, table): """ method to delete rows from a database statement written in sql """ job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel("db_tool") cmd = "DELETE FROM "+table+";" self.comp.m.logInfo(cmd) def updateRows(self, statement): """ method to delete rows from a database statement written in sql """ raise Exception("method is not implemented") def insertRows(self, table, rows): """ method to insert rows into a database the rows will be interpreted by the ddl of the component """ job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel("db_tool") cmd = "INSERT INTO "+table+";" header = "" for h in self.comp.conf["ddl"][table]["fields"]: print(h) header += ", "+h cmd += " (" + header[1:]+" ) " rowvalues = "" for r in rows: print("r-----------------") print(r) rowvalues = "" cmd += "\n ( " for h in self.comp.conf["ddl"][table]["fields"]: print("h "+h) if (h in r): rowvalues += ", "+self.getDbValue(self.comp.conf["ddl"][table]["data"][h], r[h]) else: rowvalues += ", "+self.getDbValue(self.comp.conf["ddl"][table]["data"][h], "") print("rv " + rowvalues) cmd += rowvalues[1:]+" )," cmd = cmd[0:-1]+";" 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 ""