Skip to content

Commit

Permalink
fixes #110
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Dec 19, 2022
1 parent 07b571e commit 5e47064
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
15 changes: 10 additions & 5 deletions lodstorage/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def getDebugInfo(self,record,index,executeMany):
debugInfo="\nrecord #%d" % index
return debugInfo

def store(self,listOfRecords,entityInfo,executeMany=False,fixNone=False):
def store(self,listOfRecords,entityInfo,executeMany=False,fixNone=False,replace=False):
'''
store the given list of records based on the given entityInfo
Expand All @@ -134,8 +134,9 @@ def store(self,listOfRecords,entityInfo,executeMany=False,fixNone=False):
entityInfo(EntityInfo): the meta data to be used for storing
executeMany(bool): if True the insert command is done with many/all records at once
fixNone(bool): if True make sure empty columns in the listOfDict are filled with "None" values
replace(bool): if True allow replace for insert
'''
insertCmd=entityInfo.insertCmd
insertCmd=entityInfo.getInsertCmd(replace=replace)
record=None
index=0
try:
Expand Down Expand Up @@ -507,12 +508,15 @@ def getCreateTableCmd(self,sampleRecords):
print (ddlCmd)
return ddlCmd

def getInsertCmd(self):
def getInsertCmd(self,replace:bool=False)->str:
'''
get the INSERT command for this entityInfo
Args:
replace(bool): if True allow replace for insert
Returns:
the INSERT INTO SQL command for his entityInfo e.g.
str: the INSERT INTO SQL command for his entityInfo e.g.
Example:
Expand All @@ -523,7 +527,8 @@ def getInsertCmd(self):
'''
columns =','.join(self.typeMap.keys())
placeholders=':'+',:'.join(self.typeMap.keys())
insertCmd="INSERT INTO %s (%s) values (%s)" % (self.name, columns,placeholders)
replaceClause=" OR REPLACE" if replace else ""
insertCmd=f"INSERT{replaceClause} INTO {self.name} ({columns}) values ({placeholders})"
if self.debug:
print(insertCmd)
return insertCmd
Expand Down
4 changes: 2 additions & 2 deletions lodstorage/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Version(object):
Version handling for pyLoDStorage
'''
name="pylodstorage"
version='0.4.7'
version='0.4.8'
date = '2020-09-10'
updated = '2022-08-17'
updated = '2022-12-18'
description='python List of Dict (Table) Storage library'
16 changes: 14 additions & 2 deletions tests/testSqlite3.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,24 @@ def testIssue18(self):
'''
sqlDB=self.getSampleTableDB()
tableDict=sqlDB.getTableDict()
if self.debug:
debug=self.debug
#debug=True
if debug:
print (tableDict)
self.assertTrue("sample" in tableDict)
cols=tableDict["sample"]["columns"]
self.assertTrue("pkey" in cols)


def testIssue110(self):
"""
https://github.com/WolfgangFahl/pyLoDStorage/issues/110
"""
sqlDB=self.getSampleTableDB()
sample1=Sample.getSample(10)
sample2=Sample.getSample(10)
sample1.extend(sample2)
entityInfo=sqlDB.createTable(sample1,"sample1","pkey")
sqlDB.store(sample1,entityInfo=entityInfo,replace=True)


if __name__ == "__main__":
Expand Down

0 comments on commit 5e47064

Please sign in to comment.