×

Discussion Board

Results 1 to 9 of 9

Hybrid View

  1. #1
    Regular Contributor
    Join Date
    Oct 2010
    Location
    chennai
    Posts
    97

    Exclamation problem with passing arguments to sqlite database

    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

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: problem with passing arguments to sqlite database

    Can you show us what you have tried.

    If you donot show us what you tried how we will know what is going wrong.

  3. #3
    Regular Contributor
    Join Date
    Oct 2010
    Location
    chennai
    Posts
    97

    Re: problem with passing arguments to sqlite database

    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

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: problem with passing arguments to sqlite database

    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()) {
    
        }

  5. #5
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Location
    Finland
    Posts
    327

    Re: problem with passing arguments to sqlite database

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

  6. #6
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: problem with passing arguments to sqlite database

    for me parameter validation is good for INSERT/MODIFY then in SELECT ... either way will work fine

  7. #7
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Location
    Finland
    Posts
    327

    Re: problem with passing arguments to sqlite database

    Quote Originally Posted by skumar_rao View Post
    for me parameter validation is good for INSERT/MODIFY then in SELECT ... either way will work fine
    Agreed - it's just that (even without validation) named parameters are IMHO less error prone than argument order based ones. The OP is certainly free to pick whichever solution he likes more

  8. #8
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: problem with passing arguments to sqlite database

    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.

  9. #9
    Regular Contributor
    Join Date
    Oct 2010
    Location
    chennai
    Posts
    97

    Re: problem with passing arguments to sqlite database

    thanks for ur discussion here.. I got my query..
    Thanks & Best Regards
    Srinivas

Similar Threads

  1. passing arguments to my qttestlib class
    By newtonianb in forum Qt
    Replies: 5
    Last Post: 2010-02-07, 12:53
  2. passing arguments
    By niff111 in forum Symbian
    Replies: 8
    Last Post: 2009-02-18, 12:18
  3. passing command line arguments
    By UncleOp in forum Open C/C++
    Replies: 0
    Last Post: 2008-06-10, 17:27
  4. passing arguments in asyncronous server
    By mearunsingh in forum Symbian
    Replies: 7
    Last Post: 2008-05-25, 22:18
  5. Passing arguments
    By franalegre in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-04-23, 11:30

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×