db.py 文件源码

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

项目:postsai 作者: postsai 项目源码 文件源码
def import_data(self, head, rows):
        """Imports data"""

        self.connect()
        self.cache = Cache()
        cursor = self.conn.cursor()

        sql = """INSERT INTO importactions (remote_addr, remote_user, sender_addr, sender_user, ia_when) VALUES (%s, %s, %s, %s, %s)"""
        cursor.execute(sql, [
            environ.get("REMOTE_ADDR", ""), environ.get("REMOTE_USER", ""),
            head["sender_addr"],head["sender_user"],
            datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
        ])
        importactionid = cursor.lastrowid

        for row in rows:
            for key in self.column_table_mapping:
                self.fill_id_cache(cursor, key, row, row[key])

        for row in rows:
            sql = """INSERT IGNORE INTO checkins(type, ci_when, whoid, repositoryid, dirid, fileid, revision, branchid, addedlines, removedlines, descid, stickytag, commitid, importactionid)
                 VALUE (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
            cursor.execute(self.rewrite_sql(sql), [
                row["type"],
                row["ci_when"],
                self.cache.get("who", row["who"]),
                self.cache.get("repository", row["repository"]),
                self.cache.get("dir", row["dir"]),
                self.cache.get("file", row["file"]),
                row["revision"],
                self.cache.get("branch", row["branch"]),
                row["addedlines"],
                row["removedlines"],
                self.cache.get("description", row["description"]),
                "",
                self.cache.get("hash", row["commitid"]),
                str(importactionid)
                ])

        cursor.close()
        self.disconnect()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号