Results 1 to 6 of 6

Thread: Problem Executing Query from QT

  1. #1
    Join Date
    May 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem Executing Query from QT

    Hello, Im a newbie with QT, I'm having an existing application developed using QT 4.7 . I'm getting an error executing a select query from my QT application. The same query runs successfully and returns 1 row when i execute it from the PSQL Terminal. The error which i get is mentioned below:

    near "FROM": syntax error

    Kindly help me with the same.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem Executing Query from QT

    Quote Originally Posted by pranavpunjabi View Post
    Kindly help me with the same.
    We would if you post the relevant lines of code you are using. All we can say right now is, that you have a syntax error near "from" in your sql statement, but I guess you know that already...

  3. #3
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem Executing Query from QT

    could u post your query. this looks more like a error in query. May be your query is being arrived at after some manipulation with qstring methods. It can help if you look into that.

  4. #4
    Join Date
    May 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem Executing Query from QT

    First of all thanks for the support.

    Ya i know that theres some syntax error in the query but I'm not able to figure it out as i can run the same query successfully from the terminal. Anyways, I'm posting the relevant lines of code below :

    Qt Code:
    1. QSqlQuery query(mRemoteDB);
    2.  
    3. QString queryStr = QString("SELECT nsdqaohlcv.open, nsdqaohlcv.hightime, nsdqaohlcv.high, nsdqaohlcv.lowtime, nsdqaohlcv.low, nsdqaohlcv.close, nsdqaohlcv.volume, nsdqaohlcv.trades FROM \"nsdqaohlcv\", \"stock\", \"calendar\" WHERE nsdqaohlcv.stock_id = stock.stock_id AND nsdqaohlcv.date_id = calendar.date_id AND stock.symbol = '%1' AND calendar.date = ( SELECT MAX(date) FROM \"calendar\" WHERE EXTRACT (DOW FROM date) >= 1 AND EXTRACT(DOW FROM date) <= 5 AND date < 'today' AND isholiday IS NULL)").arg(mStockname);
    4.  
    5. bool retVal = query.exec(queryStr);
    6.  
    7. if(!retVal){
    8. QString errMsg = QString( "Error executing query: %1\n"
    9. "Error Message from Database: %2"
    10. ).arg(queryStr).arg(query.lastError().text());
    11. mpError->setMessage(errMsg, Error::Critical);
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 20th May 2011 at 09:47.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem Executing Query from QT

    SQL uses single quotes to delimit strings not double quotes.


    Edit: I reread the query. Disregard this comment.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  6. #6
    Join Date
    May 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem Executing Query from QT

    I just remover the double quotes from the table names but still the query does not gets executed

Similar Threads

  1. long query executing
    By banita in forum Qt Programming
    Replies: 11
    Last Post: 11th October 2010, 00:38
  2. problem while executing SQL query
    By sosanjay in forum Qt Programming
    Replies: 3
    Last Post: 9th October 2009, 12:52
  3. problem while executing Query
    By jjbabu in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2009, 11:46
  4. Error executing SELECT query with QSQLITE
    By garfield85 in forum Qt Programming
    Replies: 6
    Last Post: 25th May 2009, 18:05
  5. A problem with executing Qt 4.5.0
    By Dante in forum Installation and Deployment
    Replies: 20
    Last Post: 15th March 2009, 19: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.