file_client.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:BitcoinExchangeFH 作者: Aurora-Team 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号