Results 1 to 7 of 7

Thread: Sql Query Problem

  1. #1
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Lightbulb Sql Query Problem

    Hello ,
    I wana retreive value from database .so I wana execute this query.
    SELECT * FROM Schedule WHERE StartDateTime <=now() and EndDateTime>=now();
    for this I m using
    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("SELECT *FROM Schedules WHERE StartDateTime<=:date ORDER BY ScheduleNo ASC");
    3. query.bindValue(":date",currentSystemStartDate);
    4. query.bindValue(":endTime",currentSystemEndTime);
    5. query.exec();
    6.  
    7.  
    8.  
    9. if(query.isActive())
    10.  
    11. {
    12.  
    13. while(query.next())
    14.  
    15. {
    16.  
    17. startTime=query.value(2).toString();
    18. }
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    But My problem is that it does not perform this query I mean to say it give all the value of table either it satisfy the condition or not ....................
    So Please if any one can do something for me then I m very thankful for him.............
    Last edited by jpn; 30th May 2008 at 08:10. Reason: missing [code] tags

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

    Default Re: Sql Query Problem

    you want to have value that
    StartDateTime <=now() and EndDateTime>=now()
    but in query you check only first condition
    query.prepare("SELECT *FROM Schedules WHERE StartDateTime<=:date ORDER BY ScheduleNo ASC");
    you forgot add EndDateTime >= :endTime

  3. #3
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Sql Query Problem

    thanx for reply .....
    I m sorry I really forgot to write the actual code on that thread....
    I m using this in my code but it is not working
    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("SELECT *FROM Schedules WHERE StartDateTime<=:date EndDateTime>=:endTime ORDER BY ScheduleNo ASC");
    3. query.bindValue(":date",currentSystemStartDate);
    4. query.bindValue(":endTime",currentSystemEndTime);
    5. query.exec();
    6.  
    7.  
    8.  
    9. if(query.isActive())
    10.  
    11. {
    12.  
    13. while(query.next())
    14.  
    15. {
    16.  
    17. startTime=query.value(2).toString();
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    Now can you tell me what mistake I m doing ?????????
    Last edited by jpn; 30th May 2008 at 08:10. Reason: missing [code] tags

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

    Default Re: Sql Query Problem

    there is still syntax mistake in your sql request
    it should be
    Qt Code:
    1. query.prepare("SELECT *FROM Schedules WHERE ( StartDateTime<=:date AND EndDateTime>=:endTime ) ORDER BY ScheduleNo ASC");
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Sql Query Problem

    Again thanx Sir for your reply , but Sir it is still not working ................
    It provides all the value of database ..........
    I think may be the method to retrive the value is not right ......??????
    Why it is not working ??????????????????

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

    Default Re: Sql Query Problem

    so use qDebug() and show what you get from
    • query->lastQuery();
    • currentSystemStartDate
    • currentSystemEndTime
    • and what you have in this fields: StartDateTime, EndDateTime

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

    MrShahi (30th May 2008)

  8. #7
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Smile Re: Sql Query Problem

    Thanx mazurekwrc ,
    I solved my problem...................U r right I was doing mistake in Condition i.e currentSystemEndTime .............
    Thanx once again...........................

Similar Threads

  1. Problem building Firebird sql plugins
    By vieraci in forum Installation and Deployment
    Replies: 11
    Last Post: 12th September 2008, 01:28
  2. INSERT query with MySQL problem
    By timmyg in forum Qt Programming
    Replies: 10
    Last Post: 20th March 2008, 21:52
  3. QTreeView with results from an SQL query.
    By ederbs in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2007, 02:41
  4. SQL problem
    By nimmyj in forum Qt Programming
    Replies: 4
    Last Post: 25th December 2006, 18:43

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.