Results 1 to 11 of 11

Thread: QDataTable setFilter

  1. #1
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Angry QDataTable setFilter

    Hello,

    I need to make one update in the filtered data of the QDataTable more I am not obtaining, would like to store setFilter in an variable to execute in the SQL.

    /******************************************/
    void FormTest:rimeUpdateValuesData()
    {
    dataTable->setFilter("id_test = id_test");
    int i = dataTable->currentRow();
    if ( i == -1 ) i = 0;

    /* it would like to effect update of id_test in clause SQL WHERE */
    QSqlQuery query;
    query.exec( "UPDATE tabletest SET date_time=now() WHERE id_test;" );

    dataTable->refresh(QDataTable::RefreshData);
    }
    /******************************************/

    Cristiano

  2. #2
    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: QDataTable setFilter

    Quote Originally Posted by cristiano View Post
    it would like to effect update of id_test in clause SQL WHERE
    Do you mean something like this?
    Qt Code:
    1. query.exec( "UPDATE tabletest SET date_time=now() WHERE " + dataTable->filter() );
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. query.prepare( "UPDATE tabletest SET date_time=now() WHERE id_test = :id" );
    2. query.bindValue( ":id", ... );
    3. query.exec();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Talking Re: QDataTable setFilter

    Yes, Now it is working.

    query.exec( "UPDATE tabletest SET date_time=now() WHERE " + dataTable->filter() );

    Thanks Jacek

    Cristiano

  4. #4
    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: QDataTable setFilter

    Just beware, that if user can use any string as the filter, he can mess up your database through SQL injection.

  5. #5
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QDataTable setFilter

    Hi,

    I have in mine form of accompaniment, type three occurrences with the same ID, when I make query below only functions when I have "1 occurrence", more he will be had more than one, query modifies all the fields.

    Here it functions only for one.

    queryVtr.exec( "UPDATE viatures SET dt_tm_chg=now() WHERE " + dataTable->filter() );

    Query SQL would be this,

    UPDATE viatures SET dt_tm_chg=now() WHERE id_num_ocor=???? AND id_viature_ocor=???? AND id_city_ocor=????

    The possibility of the use of setFilter() exists to filter the fields of the QDataTable.

  6. #6
    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: QDataTable setFilter

    Sorry, I don't quite follow you.

  7. #7
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Unhappy Re: QDataTable setFilter

    Sorry for the bad English

    With this command below, when I have equal ID, and I effect one update it modifies the date for the two registers.

    void Form::updateDataVtr()
    {
    queryVtr.exec( "UPDATE viatures SET dt_tm_chg=now() WHERE " + dataTable->filter() );
    }

    It has the example here:

    http://200.193.29.195/qt/form_app.png

    it would not like that ocorrece this, I only want to change 1 register

  8. #8
    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: QDataTable setFilter

    Then maybe you should try this way:
    Qt Code:
    1. q.prepare( "UPDATE viatures SET dt_tm_chg=now() WHERE id_num_ocor= :id_num_ocor "
    2. " AND id_viature_ocor= :id_viature_ocor AND id_city_ocor= :id_city_ocor" );
    3. q.bindValue( ":id_num_ocor", ... );
    4. q.bindValue( ":id_viature_ocor", ... );
    5. q.bindValue( ":id_city_ocor", ... );
    6. q.exec();
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QDataTable setFilter

    Yes !

    More as I read the variable of the QDataTable? setFilter() does not filter the field.

    q.bindValue( ":id_num_ocor", ... );

  10. #10
    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: QDataTable setFilter

    You can retrieve field values through QDataTable::currentRecord() or QDataTable::value().

  11. #11
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Smile Re: QDataTable setFilter

    Thanks Jacek,

    functioned using QDataTable::value()

    /*****************************************/
    QVariant getCurrentItemId;
    getCurrentItemId= myDataTable->value(0,0);
    ...
    ..
    query.prepare( "UPDATE ...." );
    query.bindValue( "::id_num_ocor", getCurrentItemId );
    ...
    ...
    query.exec();
    /*****************************************/

Similar Threads

  1. QDataTable Inserts and Updates
    By ederbs in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2006, 23:23
  2. Signal QDataTable
    By cristiano in forum Qt Programming
    Replies: 3
    Last Post: 17th October 2006, 06:28
  3. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  4. Refreshing QDataTable
    By zlatko in forum Qt Programming
    Replies: 5
    Last Post: 2nd May 2006, 16:11
  5. problem with QDataTable
    By zlatko in forum Qt Programming
    Replies: 3
    Last Post: 26th April 2006, 15:31

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.