Browse Source

bugfixe because of keywords

refactor
Ulrich 1 year ago
parent
commit
681b9a55fa
  1. 8
      model/datatable.csv
  2. 2
      model/datatable.py
  3. 11
      model/entity.py
  4. 2
      model/prelease.csv
  5. 9
      model/project.py
  6. 22
      test/test_16project.py
  7. 4
      tools/dbmysql_tool.py
  8. 6
      tools/dbrel_tool.py

8
model/datatable.csv

@ -2,10 +2,10 @@ _type;ctlg;;;;;;;;;
_key;_field;;;;;;;;;
table:datatable;_field;type;format;index;generic;aggregat;key;acceptance;alias;description
;dtid;pk;integer;N;;;T:1;;;
;name;str;vchar(256);I;;;F:3;;;
;component;str;vchar(256);I;;;F:3;;;
;database;str;vchar(256);I;;;F:1;;;
;schema;str;vchar(256);I;;;F:2;;;
;name;str;vchar(128);I;;;F:3;;;
;component;str;vchar(128);I;;;F:3;;;
;dtdatabase;str;vchar(128);I;;;F:1;;;
;dtschema;str;vchar(128);I;;;F:2;;;
;description;string;vchar(256);N;;;;;;
;reference;str;vchar(256);N;;;;;;story
;attributes;jlob;jlob;N;;;;;;

1 _type ctlg
2 _key _field
3 table:datatable _field type format index generic aggregat key acceptance alias description
4 dtid pk integer N T:1
5 name str vchar(256) vchar(128) I F:3
6 component str vchar(256) vchar(128) I F:3
7 database dtdatabase str vchar(256) vchar(128) I F:1
8 schema dtschema str vchar(256) vchar(128) I F:2
9 description string vchar(256) N
10 reference str vchar(256) N story
11 attributes jlob jlob N

2
model/datatable.py

@ -25,7 +25,7 @@ LIST_SUBTABLES = {}
class Datatable(model.entity.Entity):
FIELD_ID = "dtid"
LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, "database", "schema",
LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, "dtdatabase", "dtschema",
B.SUBJECT_DESCRIPTION, B.SUBJECT_REFERENCE, B.SUBJECT_COMP]
LIST_NODES = [B.DATA_NODE_HEADER, B.DATA_NODE_DATA, B.DATA_NODE_FIELDS, B.NODE_ATTRIBUTES, "fieldnames"]

11
model/entity.py

@ -578,8 +578,6 @@ class Entity:
raise Exception("Fehler bei createSchema "+s)
def getHistoryFields(self):
dbtype = self.job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]
dbi = basic.toolHandling.getDbTool(self.job, None, dbtype)
@ -605,6 +603,15 @@ class Entity:
sql = dbi.getSchemaIndex(table, "actual") + "\n"
return sql
def insert_entity(self, job):
"""
inserts the entity into the database
it similar to update_entity
:param job:
:param name:
:return:
"""
pass
def read_spec(job, testentity, testgran, specpath):
if not os.path.isfile(specpath):

2
model/prelease.csv

@ -5,6 +5,4 @@ table:prelease;_field;type;format;index;generic;aggregat;key;acceptance;alias;de
;reference;str;vchar(256);N;;;;;;
;project;string;vchar(256);I;;;;;;
;attributes;string;jlob;N;;;;;;
;applications;subtable;subtable;N;;;;;;
;stories;subtable;subtable;N;;;;;;

1 table:prelease _field type format index generic aggregat key acceptance alias description
5 reference str vchar(256) N
6 project string vchar(256) I
7 attributes string jlob N
applications subtable subtable N
stories subtable subtable N
8

9
model/project.py

@ -159,7 +159,7 @@ class Project(model.entity.Entity):
tools.file_tool.write_file_dict(job.m, job, pathname, config)
return self
def insert_entity(self, job, name, table="", rows={}):
def insert_entity(self, job, name="", table="", rows={}):
"""
inserts the entity into the database
it similar to update_entity
@ -167,7 +167,9 @@ class Project(model.entity.Entity):
:param name:
:return:
"""
self.setDbAttributes(job, [TABLE_NAME])
if table == "" and len(self.ddls) == 0:
self.insert_entity(job, name=name, table=self.entityname, rows=rows)
# self.setDbAttributes(job, [TABLE_NAME])
dbi = basic.toolHandling.getDbTool(job, self, job.conf[B.TOPIC_NODE_DB]["type"])
condition = "where"
for f in UNIQUE_FIELDS:
@ -179,10 +181,9 @@ class Project(model.entity.Entity):
print("update statt insert")
return
if rows is None or len(rows) == 0:
insheader = dbi.getInsertFields(self.conf[B.DATA_NODE_DDL][table])
rows = []
row = {}
for f in insheader:
for f in self.ddls[table]:
row[f] = getattr(self, f)
rows.append(row)
dbi.insertRows(job, table, rows)

22
test/test_16project.py

@ -15,7 +15,7 @@ PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity",
"test_13writeEntity" #, "test_14insertEntity"
]
#TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity"]
TEST_FUNCTIONS = ["test_14insertEntity"]
PROGRAM_NAME = "clean_workspace"
class MyTestCase(unittest.TestCase):
@ -62,7 +62,7 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob()
project = model.project.Project(job)
name = "TESTPROJ"
actproject = project.read_entity(job, name)
actproject = project.read_entity(job, name=name)
self.assertEqual(getattr(actproject, model.project.FIELD_NAME), name)
self.assertRaises(Exception, project.read_entity, job, "xyzxyz")
#
@ -87,22 +87,10 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
username = "hans_xyz"
project = model.project.Project(job)
entityNames = collectInnerList(project.get_unique_names(job, storage=model.entity.STORAGE_DB))
#self.assertNotIn(username, entityNames)
project.username = username
project.name = "Hans"
project.famname = "im Glueck"
project.project = "TESTPROJ"
#project.insert_entity(job, username, table="project")
entityNames = collectInnerList(project.get_unique_names(job, storage=model.entity.STORAGE_DB))
self.assertIn(username, entityNames)
actUser = project.select_entity(job, username)
self.assertEqual(getattr(actUser, model.project.FIELD_USERNAME), username)
actUser.delete_entity(job, username, "project")
entityNames = collectInnerList(project.get_unique_names(job, storage=model.entity.STORAGE_DB))
self.assertNotIn(username, entityNames)
name = "TESTPROJ"
actproject = project.read_entity(job, name=name)
actproject.insert_entity(job)
def collectInnerList(inList):
outList = []

4
tools/dbmysql_tool.py

@ -34,7 +34,7 @@ class DbFcts(tools.dbrel_tool.DbFcts):
sql += " "+where
sql += ";"
print("sql " + sql)
self.comp.m.logInfo(sql)
self.log(job, sql)
connector = self.getConnector()
try:
mycursor = connector.cursor()
@ -56,7 +56,7 @@ class DbFcts(tools.dbrel_tool.DbFcts):
r[f] = str(x[i])
i += 1
tdata[B.DATA_NODE_DATA].append(r)
self.comp.m.logInfo(str(tdata))
self.log(job, str(tdata))
return tdata
def deleteRows(self, job, table, where=""):

6
tools/dbrel_tool.py

@ -18,6 +18,12 @@ class DbFcts(tools.db_abstract.DbFcts):
def __init__(self):
pass
def log(self, job, text: str):
if hasattr(self, "comp") and hasattr(self.comp, "m"):
self.comp.m.logInfo(text)
else:
job.m.logInfo(text)
def selectRows(self, table, job):
""" method to select rows from a database
statement written in sql """

Loading…
Cancel
Save