read.py 文件源码

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

项目:trough 作者: internetarchive 项目源码 文件源码
def execute_query(self, segment, query):
        '''Returns a cursor.'''
        logging.info('Servicing request: {query}'.format(query=query))
        # if the user sent more than one query, or the query is not a SELECT, raise an exception.
        if len(sqlparse.split(query)) != 1 or sqlparse.parse(query)[0].get_type() != 'SELECT':
            raise Exception('Exactly one SELECT query per request, please.')
        assert os.path.isfile(segment.local_path())

        logging.info("Connecting to sqlite database: {segment}".format(segment=segment.local_path()))
        connection = sqlite3.connect(segment.local_path())
        trough.sync.setup_connection(connection)
        cursor = connection.cursor()
        cursor.execute(query.decode('utf-8'))
        return cursor

    # uwsgi endpoint
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号