Results 1 to 6 of 6

Thread: SQLite Woes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default SQLite Woes

    Hello ive been trying to work out all day long why my sql lite database was not accepting insert queries until i finally found the problem:

    basically using this pyqt code:
    Qt Code:
    1. query.exec_("""CREATE TABLE calls (
    2. id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
    3. caller VARCHAR(40) NOT NULL,
    4. starttime DATETIME NOT NULL,
    5. endtime DATETIME NOT NULL,
    6. random_new_field VARCHAR(80) NOT NULL,
    7. topic VARCHAR(80) NOT NULL)""")
    8.  
    9. topics = ("Complaint", "Information request", "Off topic",
    10. "Information supplied", "Complaint", "Complaint")
    11.  
    12. now = QDateTime.currentDateTime()
    13. print "Populating table..."
    14. query.prepare("INSERT INTO calls (caller, starttime, endtime, "
    15. "topic) VALUES (?, ?, ?, ?)")
    16. for name in ('Joshan Cockerall', 'Ammanie Ingham',
    17. 'Diarmuid Bettington', 'Juliana Bannister',
    18. 'Oakley-Jay Buxton', 'Reilley Collinge',
    19. 'Ellis-James Mcgehee', 'Jazmin Lawton',
    20. 'Lily-Grace Smythe', 'Coskun Lant', 'Lauran Lanham',
    21. 'Millar Poindexter', 'Naqeeb Neild', 'Maxlee Stoddart',
    22. 'Rebia Luscombe', 'Briana Christine', 'Charli Pease',
    23. 'Deena Mais', 'Havia Huffman', 'Ethan Davie',
    24. 'Thomas-Jack Silver', 'Harpret Bray', 'Leigh-Ann Goodliff',
    25. 'Seoras Bayes', 'Jenna Underhill', 'Veena Helps',
    26. 'Mahad Mcintosh', 'Allie Hazlehurst', 'Aoife Warrington',
    27. 'Cameron Burton', 'Yildirim Ahlberg', 'Alissa Clayton',
    28. 'Josephine Weber', 'Fiore Govan', 'Howard Ragsdale',
    29. 'Tiernan Larkins', 'Seren Sweeny', 'Arisha Keys',
    30. 'Kiki Wearing', 'Kyran Ponsonby', 'Diannon Pepper',
    31. 'Mari Foston', 'Sunil Manson', 'Donald Wykes',
    32. 'Rosie Higham', 'Karmin Raines', 'Tayyibah Leathem',
    33. 'Kara-jay Knoll', 'Shail Dalgleish', 'Jaimie Sells'):
    34. start = now.addDays(-random.randint(1, 30))
    35. start = now.addSecs(-random.randint(60 * 5, 60 * 60 * 2))
    36. end = start.addSecs(random.randint(20, 60 * 13))
    37. topic = random.choice(topics)
    38. query.addBindValue(QVariant(QString(name)))
    39. query.addBindValue(QVariant(start))
    40. query.addBindValue(QVariant(end))
    41. query.addBindValue(QVariant(QString(topic)))
    42. query.exec_()
    43. QApplication.processEvents()
    To copy to clipboard, switch view to plain text mode 

    it creates the database table but does not insert the information because there are more fields in the database than there is in the insert query?!?!?!?

    Now i come from using php and mysql background and it no problem at all to insert less data into a database than the fields that take up the database.

    IS this normal behaviour? im i the one who is crazy?

    basically to make this query work i had to put the extra field in the query and just send a null value to is in the addBindValue variable for it:

    Qt Code:
    1. query.prepare("INSERT INTO calls (caller, starttime, endtime, random_new_field, "
    2. "topic) VALUES (?, ?, ?, ?, ?)")
    3. for name in ('Joshan Cockerall', 'Ammanie Ingham',
    4. 'Diarmuid Bettington', 'Juliana Bannister',
    5. 'Oakley-Jay Buxton', 'Reilley Collinge',
    6. 'Ellis-James Mcgehee', 'Jazmin Lawton',
    7. 'Lily-Grace Smythe', 'Coskun Lant', 'Lauran Lanham',
    8. 'Millar Poindexter', 'Naqeeb Neild', 'Maxlee Stoddart',
    9. 'Rebia Luscombe', 'Briana Christine', 'Charli Pease',
    10. 'Deena Mais', 'Havia Huffman', 'Ethan Davie',
    11. 'Thomas-Jack Silver', 'Harpret Bray', 'Leigh-Ann Goodliff',
    12. 'Seoras Bayes', 'Jenna Underhill', 'Veena Helps',
    13. 'Mahad Mcintosh', 'Allie Hazlehurst', 'Aoife Warrington',
    14. 'Cameron Burton', 'Yildirim Ahlberg', 'Alissa Clayton',
    15. 'Josephine Weber', 'Fiore Govan', 'Howard Ragsdale',
    16. 'Tiernan Larkins', 'Seren Sweeny', 'Arisha Keys',
    17. 'Kiki Wearing', 'Kyran Ponsonby', 'Diannon Pepper',
    18. 'Mari Foston', 'Sunil Manson', 'Donald Wykes',
    19. 'Rosie Higham', 'Karmin Raines', 'Tayyibah Leathem',
    20. 'Kara-jay Knoll', 'Shail Dalgleish', 'Jaimie Sells'):
    21. start = now.addDays(-random.randint(1, 30))
    22. start = now.addSecs(-random.randint(60 * 5, 60 * 60 * 2))
    23. end = start.addSecs(random.randint(20, 60 * 13))
    24. topic = random.choice(topics)
    25. random_new_field = ""
    26. query.addBindValue(QVariant(QString(name)))
    27. query.addBindValue(QVariant(start))
    28. query.addBindValue(QVariant(end))
    29. query.addBindValue(QVariant(QString(random_new_field)))
    30. query.addBindValue(QVariant(QString(topic)))
    31. query.exec_()
    32. QApplication.processEvents()
    To copy to clipboard, switch view to plain text mode 

    the main reson i ask about this is is this just an sqlite problem or is this a qt problem and i will have this same issue what ever database i put on the end of these queries.

    or have i totally f-d up the way i should be using the sql module and i can actually just insert one new field and row into a table with 20 colums if ishould ever feel like so with out having to send null values to the rest of the colums
    Last edited by morraine; 12th August 2008 at 17:10.

Similar Threads

  1. Insert unicode in SQlite
    By Kastagne in forum Qt Programming
    Replies: 3
    Last Post: 11th October 2011, 14:07
  2. SQLite
    By cyberboy in forum Installation and Deployment
    Replies: 1
    Last Post: 15th April 2008, 19:46
  3. sqlbrowser and sqlite
    By janus in forum Installation and Deployment
    Replies: 2
    Last Post: 31st March 2008, 14:59
  4. The Sqlite Error In Run!
    By alphaboy in forum Installation and Deployment
    Replies: 1
    Last Post: 19th November 2007, 14:45
  5. Bulk insert into SQLite
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 19th November 2007, 03:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.