Results 1 to 11 of 11

Thread: [QT4][SQLITE] Database and query

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QT4][SQLITE] Database and query

    Quote Originally Posted by agent007se
    I begin to think that there is a problem with QSqlite but I think that it's an integrated db with Qt, isn't it ?
    Yes it is.

    Quote Originally Posted by agent007se
    Do I have to install some specific programs ?
    No you don't have to.

    what is databaseFile->filePath()?

    Qt Code:
    1. QSqlQuery query = new QSqlQuery(db);//This line should give error
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Arrow Re: [QT4][SQLITE] Database and query

    Quote Originally Posted by munna
    what is databaseFile->filePath()?
    Isn't enough to know that the connect() function return a true value ?

    Anyway here's the code you asked:

    in CDatabase.h:
    Qt Code:
    1. private:
    2. QFileInfo *databaseFile;
    To copy to clipboard, switch view to plain text mode 

    in CDatabase.cpp:
    Qt Code:
    1. // constructor
    2. CDatabase::CDatabase(QString dbName)
    3. {
    4. databaseFile = new QFileInfo(dbName);
    5. CDatabase::dbName = databaseFile->fileName();
    6. }
    To copy to clipboard, switch view to plain text mode 

    in SomeFile.cpp:
    Qt Code:
    1. static CDatabase *CDB;
    2. ...
    3. // instantiation of CDB where stest is the return of a QFileDialog::getExistingDirectory (and is not a null string)
    4. CDB = new CDatabase(stest + "/" + dbNameStr + ".db");
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by munna
    Qt Code:
    1. QSqlQuery query = new QSqlQuery(db);//This line should give error
    To copy to clipboard, switch view to plain text mode 
    Just see in the public functions in QSqlQuery :
    QSqlQuery ( QSqlDatabase db )
    Like I said, the compilation is nice ;-). I don't understand why there might be an error...

    I use : Qt 4.1, Windows (mingw) and Code::Blocks...

  3. #3
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QT4][SQLITE] Database and query

    try to append a semicolon (" ; ") to the sqlstring:
    Qt Code:
    1. QString createQuery = "CREATE TABLE test;";
    To copy to clipboard, switch view to plain text mode 

    and if that doesn't help, try to get the error:
    http://doc.trolltech.com/4.1/qsqlquery.html#lastError


    regards aman..

  4. #4
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Arrow Re: [QT4][SQLITE] Database and query

    with AND without a semicolon :

    Qt Code:
    1. QSqlError QSE = query.lastError();
    2. QString tmp = QSE.text();
    3. QMessageBox::warning(NULL, "", tmp);
    To copy to clipboard, switch view to plain text mode 

    tmp value:
    "near "test": syntax error Unable to execute statement"
    text() function


  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QT4][SQLITE] Database and query

    Quote Originally Posted by agent007se
    "near "test": syntax error Unable to execute statement"
    It looks like your query is wrong. Can you execute that statement from SQLite console?

    I don't use SQLite, but usually "CREATE TABLE xxx" is not enough --- you must add column definitions.

    http://www.sqlite.org/lang_createtable.html

  6. #6
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: [QT4][SQLITE] Database and query

    After you call this:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    2. db.setDatabaseName(databaseFile->filePath());
    do you call this?
    1. bool ok = db.open();
    If it succeeds, ok should be true.
    If it doesn't, then all the following exec() calls will probably fail too.
    Software Engineer



Similar Threads

  1. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 17:50
  2. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53
  3. Replies: 8
    Last Post: 7th March 2006, 13:40

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.