SQLite Forum

[Closed, answered myself] Cannot select from newly created tables with Python 3 connector
Login

[Closed, answered myself] Cannot select from newly created tables with Python 3 connector

(1.1) By zhangyushao (zhangysh1995) on 2020-06-08 13:32:38 edited from 1.0 [source]

Hi,

My script reads from the sql files, and executes the query one by one. But I found that it cannot select the correct number of rows from the table.

For the script (Python 3.6.9):

SELECT col3, col1 from t0;

Error >>>>>> SELECT col3, col1 from t0; // this means no row returned

However, if I run it in the binary:

SQLite version 3.30.1 2019-10-10 20:19:45
Enter ".help" for usage hints.
sqlite> .tables
t0  t1  t2  t3  t4  t5  t6  t7  t8  t9
sqlite> select col3, col1 from t0;
df6320a9-6c4b-4fe3-972a-382fea3ca440|1970-01-02 00:00:01
sqlite>

This gives the correct result.

I provide the script together with the queries (all included) here.

(2) By zhangyushao (zhangysh1995) on 2020-06-08 13:31:55 in reply to 1.0 [link] [source]

I found that I misunderstood the behavior of the rowcount.

Related links:

https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.rowcount

https://stackoverflow.com/questions/839069/cursor-rowcount-always-1-in-sqlite3-in-python3k

https://stackoverflow.com/questions/21829266/how-to-get-the-numbers-of-data-rows-from-sqlite-table-in-python