io_sql.py 文件源码

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

项目:netcrawl 作者: Wyko 项目源码 文件源码
def get_next(self):
        '''Gets the next pending device.

        Returns: 
            Dict: The next pending device as a dictionary object
                with the names of the rows as keys.
        '''
        proc = 'main_db.get_next'

        # User a special cursor which returns results as dicts
        with self.conn, self.conn.cursor(cursor_factory=RealDictCursor) as cur:        
            cur.execute('''
                SELECT * FROM 
                    pending 
                WHERE 
                    working= FALSE
                ORDER BY pending_id ASC LIMIT 1
                ''')
            output = cur.fetchone()


            # Mark the new entry as being worked on 
            if output:
                cur.execute('''
                    UPDATE pending 
                    SET working= TRUE
                    WHERE pending_id= %s
                    ''',
                    (output['pending_id'],))

                # Return the next device
                output = dict(output)
                return output

            else: return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号