Results 1 to 4 of 4

Thread: QSQLITE Unable to fetch row in create

  1. #1
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Angry QSQLITE Unable to fetch row in create

    Qt Code:
    1. bool crearTablas(QWidget *parent){
    2. QSqlQuery query("CREATE TABLE itinerario(id INTEGER, nombre VARCHAR(32), tipo_sendero INTEGER, "
    3. "municipio VARCHAR(25), fecha_visita DATE, punto_salida VARCHAR(25), punto_llegada VARCHAR(25), "
    4. "zona VARCHAR(25), provincia VARCHAR(25), fecha DATE, mapa VARCHAR(25), modo_realizacion INTEGER);");
    5.  
    6. if(!query.exec()){
    7. QMessageBox::critical(parent, "", query.lastError().text());
    8.  
    9. return false;
    10. }
    11. return true;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Is this code wrong? I'm trying to query a database created in another function and it gives the error:
    SQL logic error or missing database Unable to fetch row
    But if I redo the query the error changes to:
    table itinerario already exists Unable to fetch
    Any help?

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

    Default Re: QSQLITE Unable to fetch row in create

    I use QSqlQuery the following way and it works fine.

    Qt Code:
    1. QSqlQuery query;
    2.  
    3. if(!query.exec("CREATE TABLE cgroup(id INTEGER PRIMARY KEY,name TEXT,category INTEGER,operator TEXT)")){
    4. //Error message
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSQLITE Unable to fetch row in create

    WTF!

    Why if I use the SQL into the exec() it works?

    Now it works :s

  4. #4
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSQLITE Unable to fetch row in create

    It's simple!
    you might have understood the docs incorrectly

    Qt Code:
    1. QSqlQuery q( queryStirng );
    To copy to clipboard, switch view to plain text mode 
    Will execute the query. which explains why you get the warning
    SQL logic error or missing database Unable to fetch row
    when you run query.exec(). " Qt expects a prepared query here; which is not there "

    Now you will be able to figure out why query.exec( createTableQuery ) works
    We can't solve problems by using the same kind of thinking we used when we created them

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.