sqlite3-创建游标并执行

sqlite3-创建游标并执行,sqlite,Sqlite,你好!!SQLite3的新特性 有一些示例程序在前面创建了“游标” 执行。。以及其他不创建光标的程序 问题:我需要创建一个“游标”还是可以忽略它 以下示例不带光标: 使用光标的以下示例: 使用execute而不使用cursor是一种非标准的快捷方式,即其他数据库驱动程序可能无法使用该快捷方式。 但是,如果您没有在需要输出的位置执行选择,它就可以正常工作。谢谢!将使用光标使其更标准:-) con = sqlite3.connect(":memory:") con.execute(

你好!!SQLite3的新特性

有一些示例程序在前面创建了“游标” 执行。。以及其他不创建光标的程序

问题:我需要创建一个“游标”还是可以忽略它

以下示例不带光标:

使用光标的以下示例:


使用
execute
而不使用
cursor
是一种非标准的快捷方式,即其他数据库驱动程序可能无法使用该快捷方式。
但是,如果您没有在需要输出的位置执行
选择
,它就可以正常工作。

谢谢!将使用光标使其更标准:-)
    con = sqlite3.connect(":memory:")

    con.execute("create table person(firstname, lastname)")
    db = sqlite3.connect('test.db')
    db.row_factory = sqlite3.Row
    db.execute('drop table if exists test')
    db.execute('create table test(t1 text, i1 int)')
    db.execute('insert into test (t1, i1) values (?,?)', ('one', 1))
    db.execute('insert into test (t1, i1) values (?,?)', ('two', 2))
    db.commit()
    cursor = db.execute('select * from test order by t1')
    for row in cursor:
        print(dict(row))