The purpose of this script is to learn how to use lambda functions in conjunction with map.
I tried to insert a string to all columns of an sqlite table and no error is shown yet the values didn't change.
class DB(SomeDbBase):
def get_columns(self):
res = self.get_cursor().execute("SELECT * FROM EVENTS")
names = list(map(lambda x: x[0], res.description))
return names`
def update_to_last(self,column:str,data:str):
c = self.get_cursor()
print(column,data)
c.execute(
f"UPDATE EVENTS SET
'{column}'='{data}' WHERE ID ='(SELECT last_insert_rowid())'")
self.conn.commit()
if __name__ == "__main__":
d=DB()
columns=d.get_columns()
# this pile of map and lambda's ment to first get all of the columns names
# then add to every string a pair of some fictionary "data" to a list
# then the list is sent to update
map(
lambda x:d.update_to_last(x[0],x[1]),
(list(map(lambda column:[column,"data"],columns)))
)
mapfor side effects. That is confusing and unidiomatic. Just use a regular for-loop.