Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aimos

macrumors newbie
Original poster
Oct 3, 2009
1
0
Hi,i am newbee to iphone programming..
How to compare a dates in my database .sqlite(column "date" ,data type DATETIME) with the current iPhone and see the result?

Example: Today is October 3, 2009 (date current on Iphone)

CREATE TABLE city ( pk INTEGER PRIMARY KEY, name VARCHAR(50), description TEXT, date DATETIME );

INSERT INTO city (name, description, date) VALUES ('San Francisco', 'bla bla bla bla', '2009/11/15');
INSERT INTO city (name, description, date) VALUES ('Paris', 'bla bla bla bla', '2009/10/03');
INSERT INTO city (name, description, date) VALUES ('New York', 'bla bla bla bla', '2009/09/25');

What query should I use to display the columns on date of today?
My table view should return the result "Paris".

“cityAppDelegate.m":

-(void) readcityFromDatabase {
// Setup the database object
sqlite3 *database;

// Init the city Array
city = [[NSMutableArray alloc] init];

// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from city"; //What query should I use to display the columns on date of today?
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8Stringchar *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescription = [NSString stringWithUTF8Stringchar *)sqlite3_column_text(compiledStatement, 2)];
NSString *aDate = [NSString stringWithUTF8Stringchar *)sqlite3_column_text(compiledStatement, 3)];

// Create a new city object with the data from the database
City *city = [[City alloc] initWithName:aName description:aDescription url:aDate];

I followed the tutorial on sqlite here:
http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/

I can not see the city's that have the time now, hoping for your help..
Thanks and sorry for my English
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.