This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: SQLite3 PRAGMA table_info doesn't respect database on Win32
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amadu, amaury.forgeotdarc, christoph, loewis
Priority: normal Keywords:

Created on 2010-03-21 18:28 by christoph, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg101440 - (view) Author: Christoph Burgmer (christoph) Date: 2010-03-21 18:28
'PRAGMA database.table_info("SOME_TABLE_NAME")' will report table metadata for the given database. The main database called 'main', can be extended by attaching further databases via 'ATTACH DATABASE'. The above PRAGMA should respect the chosen database, but fails to do so on Win32 (tested on Wine) while it does on Linux.

How to reproduce:

FILE 'first.db' has table:

  CREATE TABLE "First" (
          "Test" INTEGER NOT NULL
  );

FILE 'second.db' has table:

  CREATE TABLE "Second" (
          "Test" INTEGER NOT NULL
  );

The final result of the following code shoule be empty, but returns table data from second.db instead.

Y:\>python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> conn = sqlite3.connect('first.db')
>>> c = conn.cursor()
>>> c.execute("ATTACH DATABASE 'second.db' AS 'second'")
<sqlite3.Cursor object at 0x0071FB00>
>>> for row in c:
...     print repr(row)
...
>>> c.execute("PRAGMA 'main'.table_info('Second')")
<sqlite3.Cursor object at 0x0071FB00>
>>> for row in c:
...     print repr(row)
...
(0, u'Test', u'INTEGER', 99, None, 0)
>>>

In contrast sqlite3.exe respects the value for the same command:

Y:\>sqlite3.exe first.db
SQLite version 3.6.23
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
First
sqlite> ATTACH DATABASE 'second.db' AS 'second';
sqlite> .tables
First
sqlite> PRAGMA main.table_info('Second');
sqlite> PRAGMA second.table_info('Second');
0|Test|INTEGER|1||0
sqlite>

Advice on further debugging possibilities is requested. I do not have a Windows system available though, nor can I currently compile for Win32.
msg110873 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-07-20 07:41
python2.7 includes a newer version of sqlite. Does the problem still reproduces there?
msg221280 - (view) Author: Amadu Durham (amadu) Date: 2014-06-22 17:10
Tested in both versions 2.7 and 3.4 this sqlite3 inconsistency has been corrected and no longer exists.
msg221285 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2014-06-22 17:35
Thanks for the check.
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52439
2014-06-22 17:35:52loewissetstatus: open -> closed

nosy: + loewis
messages: + msg221285

resolution: fixed
2014-06-22 17:10:49amadusetversions: + Python 2.7, Python 3.4, - Python 2.6
nosy: + amadu

messages: + msg221280

type: behavior
2010-07-20 07:41:28amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg110873
2010-03-21 18:28:37christophcreate