Hi..
I need to pass to dates to sqlite table dynamically and according to that dates i need to fetch information.. could any one help me..
Hi..
I need to pass to dates to sqlite table dynamically and according to that dates i need to fetch information.. could any one help me..
Thanks & Best Regards
Srinivas
Can you show us what you have tried.
If you donot show us what you tried how we will know what is going wrong.
GS_STR_SELECT_SCHEDULE_MONTHLY_LIST="select col_start_datetime, col_end_datetime from tab_cb_schedule_eventdatetimes where datetime(col_start_datetime) >= datetime('2010-12-01T00:00:00Z') or datetime(col_end_datetime) <= datetime('2010-12-31T00:00:00Z')";
this is my query... here i am giving two datetimes.. i need to fetch data between these dates.. its working fine.. but my need is.. i need to give the dates dynamically... for every month start date to end date i need the data..so i need to pass every month start and end timings..
this is the dynamic thing.. can't be done statically ... how to do it..
Thanks & Best Regards
Srinivas
you might want to try like this
Code://select col_start_datetime, col_end_datetime from tab_cb_schedule_eventdatetimes where datetime(col_start_datetime) >= //datetime('2010-12-01T00:00:00Z') or datetime(col_end_datetime) <= datetime('2010-12-31T00:00:00Z') QString queryString = QString("SELECT col_start_datetime, col_end_datetime from %1 " "WHERE (datetime(col_start_datetime) >= datetime('%2') OR " "datetime(col_end_datetime) <= datetime('%3'))" ).arg(KScheduleTableName).arg(startDateTime).arg(endDateTime); QSqlQuery query(queryString, m_db); query.exec(); if(query.next()) { }
I would rather suggest parameter binding instead of string level parametrization, makes the code less PHP-looking, and might help input parameter validation (sqlite is a bit braindead in that regard, but still).
Code:QSqlQuery query; query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (:id, :forename, :surname)"); query.bindValue(":id", 1001); query.bindValue(":forename", "Bart"); query.bindValue(":surname", "Simpson"); query.exec();
for me parameter validation is good for INSERT/MODIFY then in SELECT ... either way will work fine
You can either construct the query string dynamically (and QString makes this easy), or you can "bind" parameters to the query (using either names or numbers). Both are straight-forward techniques you should master before you go writing phone stuff. Play around with desktop Qt until you understand how they work.
thanks for ur discussion here.. I got my query..
Thanks & Best Regards
Srinivas