Results 1 to 1 of 1

Thread: error with a sql view

  1. #1
    Join Date
    Apr 2010
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: error with a sql view

    Hi all,

    I get a weird error message when i create a view with concatenate function and link it against a QTableView. My qt code works when i link QTableView with the same view with out concatenation.

    Qt Code:
    1. //Sqlite side:
    2. bool Database::safeQueryExec(QString query)
    3. {
    4. bool ret = true;
    5. if(!q.exec(query))
    6. {
    7. ret = false;
    8. qDebug() << "*** Database::safeQueryExec: query fallita: " << query << q.lastError().text();
    9. }
    10. return ret;
    11. }
    12.  
    13. if(!safeQueryExec("CREATE TABLE persone (idpersona integer primary key autoincrement, firstname varchar(20) NOT NULL,lastname varchar(20) NOT NULL, dtna date,codfisc varchar(16) UNIQUE, piva varchar(11) UNIQUE,ragsoc varchar(40) UNIQUE,cellphone varchar(30), workphone varchar(30), email varchar(30), isdipendente int references dipendente(iddipendente),isfornitore int references fornitore(idfornitore), iscondomino int references condomino(idcondomino))"))
    14. return false;
    15.  
    16. if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname || ' ' || p.firstname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
    17. return false;
    18. /* working view:
    19. if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
    20.   return false;
    21. */
    22.  
    23. //widgets side:
    24. m_afferenzeviewmodel = new QSqlTableModel(this);
    25. m_afferenzeviewmodel->setTable("vafferenze");
    26. ui->tvProprieta->setModel(m_afferenzeviewmodel);
    27. ui->tvProprieta->horizontalHeader()->setStretchLastSection(true);
    28. m_afferenzeviewmodel->setFilter("idtipo = 1");
    29. m_afferenzeviewmodel->select();
    To copy to clipboard, switch view to plain text mode 

    this is the error message:

    Qt Code:
    1. ASSERT: "idx >= 0 && idx < s" in file ../../include/QtCore/../../src/corelib/tools/qvarlengtharray.h, line 110
    2. Invalid parameter passed to C runtime function.
    3. Invalid parameter passed to C runtime function.
    To copy to clipboard, switch view to plain text mode 

    I suppose that QTableView rely on columns number so using concatenate function make a mess somewhere.
    But i need to show lastname and firstname of a person into a single cell of QTableView. As it manage insertion,
    modify and delete of a relation table. So i need that data about persons are displayed as "name+surname" while
    on db it's managed as the person id. I tried using QSqlRelationalTableModel too, but i doesn't fix my needs for
    several reasons:
    1. idpersona is part of afferenze table so i can't use it,
    2. i need to show two table fields (firstname, and lastname) into a single QTableView's cell. While QSqlRelationalTable allow only one-to-one relation.


    I hope to be clear even if my english sucks
    thanks in advance.

    Hi all,

    I get a weird error message when i create a view with concatenate function and link it against a QTableView. My qt code works when i link QTableView with the same view with out concatenation.

    Qt Code:
    1. //Sqlite side:
    2. bool Database::safeQueryExec(QString query)
    3. {
    4. bool ret = true;
    5. if(!q.exec(query))
    6. {
    7. ret = false;
    8. qDebug() << "*** Database::safeQueryExec: query fallita: " << query << q.lastError().text();
    9. }
    10. return ret;
    11. }
    12.  
    13. if(!safeQueryExec("CREATE TABLE persone (idpersona integer primary key autoincrement, firstname varchar(20) NOT NULL,lastname varchar(20) NOT NULL, dtna date,codfisc varchar(16) UNIQUE, piva varchar(11) UNIQUE,ragsoc varchar(40) UNIQUE,cellphone varchar(30), workphone varchar(30), email varchar(30), isdipendente int references dipendente(iddipendente),isfornitore int references fornitore(idfornitore), iscondomino int references condomino(idcondomino))"))
    14. return false;
    15.  
    16. if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname || ' ' || p.firstname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
    17. return false;
    18. /* working view:
    19. if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
    20.   return false;
    21. */
    22.  
    23. //widgets side:
    24. m_afferenzeviewmodel = new QSqlTableModel(this);
    25. m_afferenzeviewmodel->setTable("vafferenze");
    26. ui->tvProprieta->setModel(m_afferenzeviewmodel);
    27. ui->tvProprieta->horizontalHeader()->setStretchLastSection(true);
    28. m_afferenzeviewmodel->setFilter("idtipo = 1");
    29. m_afferenzeviewmodel->select();
    To copy to clipboard, switch view to plain text mode 

    this is the error message:

    Qt Code:
    1. ASSERT: "idx >= 0 && idx < s" in file ../../include/QtCore/../../src/corelib/tools/qvarlengtharray.h, line 110
    2. Invalid parameter passed to C runtime function.
    3. Invalid parameter passed to C runtime function.
    To copy to clipboard, switch view to plain text mode 

    I suppose that QTableView rely on columns number so using concatenate function make a mess somewhere.
    But i need to show lastname and firstname of a person into a single cell of QTableView. As it manage insertion,
    modify and delete of a relation table. So i need that data about persons are displayed as "name+surname" while
    on db it's managed as the person id. I tried using QSqlRelationalTableModel too, but i doesn't fix my needs for
    several reasons:
    1. idpersona is part of afferenze table so i can't use it,
    2. i need to show two table fields (firstname, and lastname) into a single QTableView's cell. While QSqlRelationalTable allow only one-to-one relation.


    I hope to be clear even if my english sucks
    thanks in advance.


    Added after 41 minutes:


    i solved. Sorry for dumb question. I fond that qt make a mess if the new field doesn't have a name. So the right view is this:

    Qt Code:
    1. if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname || ' ' || p.firstname as Condomino,a.idafferenza"
    2. ",a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,"
    3. "a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
    4. return false;
    To copy to clipboard, switch view to plain text mode 

    Thanks all.
    Last edited by AlbertoN; 20th September 2012 at 13:53.

Similar Threads

  1. How to switch view in sliding/moving new view from right of device to the left
    By curiouswalker in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 16th November 2010, 12:55
  2. Model/View Programming - User Error Management
    By Zuzzu in forum Qt Programming
    Replies: 0
    Last Post: 4th March 2009, 17:39
  3. Replies: 5
    Last Post: 21st November 2007, 21:38
  4. Model-view: Creating a custom view
    By taboom in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2007, 21:36
  5. Error building chart model/view example
    By brcain in forum Qt Programming
    Replies: 5
    Last Post: 26th August 2006, 00:37

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.