/ Published in: Objective C

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#pragma mark Sqlite access { } { NSLog(@"Fetching holidays from the database between %@ and %@...", fromDate, toDate); sqlite3 *db; if(sqlite3_open([[self databasePath] UTF8String], &db) == SQLITE_OK) { const char *sql = "select name, country, date_of_event from holidays where date_of_event between ? and ?"; sqlite3_stmt *stmt; if(sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) { [fmt setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; sqlite3_bind_text(stmt, 1, [[fmt stringFromDate:fromDate] UTF8String], -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 2, [[fmt stringFromDate:toDate] UTF8String], -1, SQLITE_STATIC); [fmt setDateFormat:@"yyyy-MM-dd"]; while(sqlite3_step(stmt) == SQLITE_ROW) { [holidays addObject:[Holiday holidayNamed:name country:country date:[fmt dateFromString:dateAsText]]]; } } sqlite3_finalize(stmt); } sqlite3_close(db); [delegate loadedDataSource:self]; }
Comments
