#1
  1. ID10T
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2004
    Location
    Yes
    Posts
    632
    Rep Power
    27

    sqlite not creating table


    cx = sqlite.connect("db")

    cu = cx.cursor()
    cu.execute('create table my_table(one varchar(200), two varchar(10))')

    cx.close()

    Im using the above code to create an sqlite database with a table caleld my_table.

    The code runs fine, however the table my_table is not created. The code definitely runs, raises no exceptions and the db file is definitely not being created when attempting to insert something in a different part of the code.


    Any ideas or help appreciated.

    sqlite-3.1.2-3
    python-sqlite-1.1.6-1
    Both installed as standard with fedora core four, i also have the exact same problem on ubuntu 5.04.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    It's been a long time since Ive used SQLite but you need to call the connection objects commit() method when you want to save changes to a database. I would call this just before closing the connection .

    There is also an autocommit option that can be set at connection time (and an autocommit attribute) if this is more what you're looking for.

    Code:
    con = sqlite.connect('mydb', autocommit = True)
    Hope this helps,

    Mark.

    Comments on this post

    • Civ247 agrees : thanks
    programming language development: www.netytan.com Hula

  4. #3
  5. ID10T
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2004
    Location
    Yes
    Posts
    632
    Rep Power
    27
    Its always the little things. I actually spent a whole day trying to figure that one out before giving up, even though i had done many times before.

    Thanks, im going to go bang my head off a wall

IMN logo majestic logo threadwatch logo seochat tools logo