Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41304

sqlite3 - a create of table x fails after dropping table x (only on Windows)

Newsgroups comp.lang.python
Date 2013-03-16 00:26 -0700
Message-ID <721daa7e-11bf-4ce9-827c-348b0ab28936@googlegroups.com> (permalink)
Subject sqlite3 - a create of table x fails after dropping table x (only on Windows)
From ppotrebic@box.com

Show all headers | View raw


Interested to understand this problem. It only happens in Windows, not MacOS. Running python 2.7.3. sqlite3 3.7.12. The following script:

    import sqlite3
    table_name = 'table_name'
    conn = sqlite3.connect('data2.db')
    c = conn.cursor()
    
    sql = 'create table if not exists ' + table_name + ' (id integer)'
    c.execute(sql)
    sql = 'drop table ' + table_name
    c.execute(sql)
    
    sql = 'create table if not exists ' + table_name + ' (id integer)'
    c.execute(sql)
    
    sql = 'insert into ' + table_name + ' (id) values (%d)' % 97
    c.execute(sql)
    
    conn.commit()

Fails every other time it is executed. Here's the error:
   Traceback (most recent call last):
     File "C:/Users/potrebic/PycharmProjects/play/play.py", line 15, in <module>
       c.execute(sql)
   sqlite3.OperationalError: no such table: table_name

line 15 is the execute of the 'insert' stmt.

If the "if not exists" is removed from line 11, then the scripts works every time.

(Note - on MacOS it succeeds every time).

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

sqlite3 - a create of table x fails after dropping table x (only on Windows) ppotrebic@box.com - 2013-03-16 00:26 -0700

csiph-web