Results 1 to 8 of 8

Thread: Can't create table

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Can't create table

    Can anyone see why the following code is not creating the table?

    Qt Code:
    1. #include <iostream>
    2. #include <QString>
    3. #include <QtSql>
    4. #include "stninfodialog.h"
    5. #include <QDialog>
    6.  
    7. bool makeStnDB() {
    8. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    9. db.setDatabaseName("StnInfo.sqlite");
    10. db.open();
    11.  
    12. //Check to see if stninfo exists...
    13. QSqlQuery query = QSqlQuery::QSqlQuery("StnInfo.sqlite");
    14. query.exec("SELECT call FROM stnInfo");
    15.  
    16. if (query.isNull(1)) {
    17. query.exec("CREATE table stnInfo (id int recNum primary key, call varchar(8), name varchar(80),"
    18. " address1 varchar(80), accress2 varchar(80), city varchar(80), state varchar(80), state varchar(40),"
    19. " postalCode varchar(20), country varchar(40), grid varchar(8), cqZone varchar(8), ituZone varchar(8),"
    20. " latitude varchar(8), longitude varchar(8), licenseClass varchar(12))");
    21.  
    22. StnInfoDialog *StnInfoD = new StnInfoDialog();
    23. StnInfoD->show();
    24.  
    25. }
    26. if (!db.open()) {
    27. return false;
    28. }
    29. return true;
    30. }
    To copy to clipboard, switch view to plain text mode 

    It does return true.
    I also tried it without the check to see if stninfo exists and still no luck.

  2. #2
    Join Date
    Oct 2009
    Location
    tathra nsw australia
    Posts
    14
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Can't create table

    typo line 14 ????????
    select all from???

    briang

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't create table

    Thanks for trying Briang.
    Nope, "call" is the name of the second column in the table.
    If you wanted all columns in sql, you would select * .

  4. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't create table

    I now know the source of the problem, but not how to fix it yet.
    It fails to create the table when the create table statement extends beyond one line of code.

    For example, this works ok and creates a table:

    Qt Code:
    1. query.exec("CREATE table stnInfo(id int primary key,call varchar(8),name varchar(80))");
    To copy to clipboard, switch view to plain text mode 

    Any ideas anyone?

  5. #5
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't create table

    Why not put the create table string into a QString first, maybe even a const QString in the header.

  6. #6
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Can't create table

    by the way, whu don't you write it in only one line? does exec() give you true or false?
    Last edited by jano_alex_es; 30th October 2009 at 09:24. Reason: I was wrong :P

  7. #7
    Join Date
    Mar 2006
    Posts
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't create table

    Use command line sqlite or check for any error after creating table.
    Enter SQL statements terminated with a ";"
    sqlite> CREATE table stnInfo (id int recNum primary key, call varchar(8), name varchar(80), addr
    ess1 varchar(80), accress2 varchar(80), city varchar(80), state varchar(80), state varchar(40),
    postalCode varchar(20), country varchar(40), grid varchar(8), cqZone varchar(8), ituZone varchar
    (8), latitude varchar(8), longitude varchar(8), licenseClass varchar(12));
    SQL error: duplicate column name: state
    sqlite>

  8. The following user says thank you to Rembobo for this useful post:

    waynew (30th October 2009)

  9. #8
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't create table

    Thanks Rembobo, my eyes must be getting bad. Typos are the pits.
    Works fine now.

Similar Threads

  1. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 17:18
  2. How create a two level table?
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2008, 18:16
  3. Replies: 3
    Last Post: 5th October 2008, 23:41
  4. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  5. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.