Results 1 to 20 of 20

Thread: select query with like

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: select query with like

    this code working hith PostgreSql
    Qt Code:
    1. QString first_name = "arc";
    2. query.prepare( "SELECT name FROM people WHERE name LIKE :name" );
    3. query.bindValue( ":name", "%" + first_name + "%" );
    4. query.exec();
    5.  
    6. while( query.next() )
    7. {
    8. ....
    9. }
    To copy to clipboard, switch view to plain text mode 
    i hope that will help you

  2. The following user says thank you to mazurekwrc for this useful post:

    ag.sitesh (11th April 2008)

  3. #2
    Join Date
    Jan 2008
    Location
    India
    Posts
    31
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Smile Re: select query with like

    Thanks a lot!!!!!!!!!!!!!!!
    thats the way!!!!!!!
    now everything fine....
    @shish

  4. #3
    Join Date
    Jan 2008
    Location
    India
    Posts
    31
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: select query with like on Multiple conditions

    On a single text search its fine but if i have 3 lineEdits(as search criteria) for 3 columns and user can enter search text in any or every or some of those lineEdits then how to implement it???

    I have written this code : but it needs that all the lineEdits must be filled ....leaving blank any lineEdit ,then query fetches every row of the table and i want to search for any text enetered in any lineEdits ....

    void MultipleSearch::search()
    {


    }
    @shish

  5. #4
    Join Date
    Jan 2008
    Location
    India
    Posts
    31
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Re: select query with like on Multiple conditions

    On a single text search its fine but if i have 3 lineEdits(as search criteria) for 3 columns and user can enter search text in any or every or some of those lineEdits then how to implement it???

    I have written this code : but it needs that all the lineEdits must be filled ....leaving blank any lineEdit ,then query fetches every row of the table and i want to search for any text enetered in any lineEdits ....

    void MultipleSearch::search()
    {
    QString titletxt=titlesrchTxt->text();
    QString composerTxt=composersrchTxt->text();
    QString releaseDateTxt=rdatesrchTxt->text();
    QSqlQuery query;
    QString querytxt="SELECT title FROM mediadetails WHERE title LIKE :title OR composer LIKE :composer OR releasedate LIKE :rdate";
    query.prepare(querytxt);
    query.bindValue( ":title", "%" + titletxt + "%" );
    query.bindValue( ":rdate", "%" + releaseDateTxt + "%" );
    query.bindValue( ":composer", "%" + composerTxt+ "%" );
    query.exec();
    while(query.next())
    {
    listView->addItem(query.value(0).toString());
    }
    }
    @shish

  6. #5
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: select query with like on Multiple conditions

    First of all change this line
    Quote Originally Posted by sinha.ashish View Post
    QString querytxt="SELECT title FROM mediadetails WHERE title LIKE :title OR composer LIKE :composer OR releasedate LIKE :rdate";
    to

    Qt Code:
    1. QString querytxt="SELECT title, composer, releasedate FROM mediadetails WHERE title LIKE :title OR composer LIKE :composer OR releasedate LIKE :rdate";
    To copy to clipboard, switch view to plain text mode 

    and try

  7. #6
    Join Date
    Jan 2008
    Location
    India
    Posts
    31
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: select query with like

    sorry ...tahts not the syntex which i was trying to post ...u said right...i just missed to ommit ';' ...but do u have idea to do multiple search????
    ..
    @shish

  8. #7
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: select query with like

    you missed 'composer' and 'releasedate' not ';'
    here is my code which work with multiple search
    Qt Code:
    1. QString first_name = "arc";
    2. QString surname = "LA";
    3. query.prepare( "SELECT name, surname FROM people WHERE ( ( name LIKE :name ) OR ( surname LIKE :surname ) )" );
    4. query.bindValue( ":name", "%" + first_name + "%" );
    5. query.bindValue( ":surname", "%" + surname + "%" );
    6. query.exec();
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to mazurekwrc for this useful post:

    sinha.ashish (14th April 2008)

  10. #8
    Join Date
    Jan 2008
    Location
    India
    Posts
    31
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Smile Re: select query with like

    thanks....its working fine...
    @shish

Similar Threads

  1. Unable to fetch data when searching through select query
    By sinha.ashish in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2008, 14:06
  2. Select query using mysql for searching
    By sinha.ashish in forum Qt Programming
    Replies: 4
    Last Post: 10th April 2008, 06:14
  3. Sql Server cannot retrieve data from select
    By Atomino in forum Qt Programming
    Replies: 10
    Last Post: 7th September 2006, 16:37
  4. Aborting a query set on a TableModel
    By Quid in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2006, 22:36
  5. Record update windowd entered data saving
    By MarkoSan in forum Qt Programming
    Replies: 56
    Last Post: 18th January 2006, 18: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
  •  
Qt is a trademark of The Qt Company.