def insert(self, table, columns, types, values, primary_key_index=[], is_orreplace=False, is_commit=True):
"""
Insert into the table
:param table: Table name
:param columns: Column array
:param types: Type array
:param values: Value array
:param primary_key_index: An array of indices of primary keys in columns,
e.g. [0] means the first column is the primary key
:param is_orreplace: Indicate if the query is "INSERT OR REPLACE"
"""
ret = True
file_path = os.path.join(self.file_directory, table + ".csv")
if len(columns) != len(values):
return False
self.lock.acquire()
if not os.path.isfile(file_path):
ret = False
else:
with open(file_path, "a+") as csvfile:
writer = csv.writer(csvfile, lineterminator='\n', quotechar='\"', quoting=csv.QUOTE_NONNUMERIC)
writer.writerow(values)
self.lock.release()
if not ret:
raise Exception("File (%s) has not been created.")
return True
评论列表
文章目录