PDA

View Full Version : Problem Executing Query from QT



pranavpunjabi
20th May 2011, 09:21
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.

Lykurg
20th May 2011, 09:29
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...

pkj
20th May 2011, 09:30
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.

pranavpunjabi
20th May 2011, 10:01
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 :


QSqlQuery query(mRemoteDB);

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);

bool retVal = query.exec(queryStr);

if(!retVal){
QString errMsg = QString( "Error executing query: %1\n"
"Error Message from Database: %2"
).arg(queryStr).arg(query.lastError().text());
mpError->setMessage(errMsg, Error::Critical);
}

ChrisW67
20th May 2011, 10:19
SQL uses single quotes to delimit strings not double quotes.


Edit: I reread the query. Disregard this comment.

pranavpunjabi
20th May 2011, 12:24
I just remover the double quotes from the table names but still the query does not gets executed