Hello,
How can a string with multiple sqlite statements be executed (for example "select * from tab1; select * from tab2") and print the results?
How can a string with multiple sqlite statements be executed (for example "select * from tab1; select * from tab2") and print the results?
Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> conn = sqlite3.connect('sqlfun.db') >>> c = conn.cursor() >>> c.execute("select * from tab1") <sqlite3.Cursor object at 0x7f7462ce0960> >>> c.fetchall() [(1,), (2,)] >>> c.execute("select * from tab2") <sqlite3.Cursor object at 0x7f7462ce0960> >>> c.fetchall() [(3,), (4,)] >>> c.executescript("select * from tab1; select * from tab2") <sqlite3.Cursor object at 0x7f7462ce0960> >>> c.fetchall() []compare this with sqlite3 -
SSQLite version 3.25.3 2018-11-05 20:37:38 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> .open sqlfun.db sqlite> select * from tab1; 1 2 sqlite> select * from tab2; 3 4 sqlite> select * from tab1; select * from tab2; 1 2 3 4