/ Published in: Objective C
Expand |
Embed | Plain Text
NSString *dayNameString[] = {@"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday"}; NSString *monthName[] = {@"January", @"February", @"March", @"April", @"May", @"June", @"July", @"August", @"September", @"October", @"November", @"Decemeber"}; #define GETCOLUMNSTRING(_TO_, _FROM_) NSString *_TO_; {const unsigned char *c = sqlite3_column_text(compiledStmt, _FROM_); _TO_ = c ? [NSString stringWithUTF8String:(char*)c] : @""; } #define PUTCOLUMNSTRING(_TO_, _FROM_) {NSString *str = [dObj valueForKey:_FROM_]; if (!str) str=@""; sqlite3_bind_text(compiledStmt, _TO_, [str UTF8String], -1, SQLITE_TRANSIENT);} @implementation Database +(Database *)sharedDatabase { if (sharedDatabase == nil) { sharedDatabase = [[Database alloc] init]; } return sharedDatabase; } - (id)init { if (self = [super init]) { NSString *dbPath=[basePath stringByAppendingPathComponent:[kDataBaseName stringByAppendingFormat:@".%@",kDataBaseExt]]; if(![fm fileExistsAtPath:dbPath]){ [fm copyItemAtPath:[[NSBundle mainBundle] pathForResource:kDataBaseName ofType:kDataBaseExt] toPath:dbPath error:nil]; } if (sqlite3_open([dbPath UTF8String], &database) != SQLITE_OK) NSLog(@"Error opening database!"); sqlite3_stmt *compiledStmt; NSUInteger err = sqlite3_prepare_v2(database, "PRAGMA count_changes=OFF; PRAGMA journal_mode = OFF; PRAGMA synchronous=OFF", -1, &compiledStmt, NULL); if (!err) { err = sqlite3_step(compiledStmt); if (!err) sqlite3_finalize(compiledStmt); } } return self; } { // NSString *tmpStr=[NSString stringWithFormat:@"select id, name, suburb FROM markets where verified is not null and name like '%@%' order by name asc",searchText]; const char *sqlStatement="select id, title, location_text_1 FROM pmd_listings where custom_15 is not null and title like ? order by name asc"; // const char *sqlStatement= [tmpStr UTF8String]; sqlite3_stmt *compiledStmt; if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStmt, NULL) == SQLITE_OK) { //sqlite3_bind_text(compiledStmt, 1, [[NSString stringWithFormat:@"%@%", searchText ] UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(compiledStmt, 1, [[NSString stringWithFormat:@"%%%@%%", searchText ] UTF8String], -1, SQLITE_TRANSIENT); while(sqlite3_step(compiledStmt)==SQLITE_ROW) { NSUInteger mNo=(NSUInteger)sqlite3_column_int(compiledStmt, 0); GETCOLUMNSTRING(mName, 1) //NSString *mName=[NSString stringWithFormat:@"%s",(char*)sqlite3_column_text(compiledStmt, 1)]; GETCOLUMNSTRING(mSuburb, 2) //NSString *mSuburb=[NSString stringWithFormat:@"%s",(char*)sqlite3_column_text(compiledStmt, 2)]; [facultiesArray addObject: mName,@"marketname", mSuburb,@"marketSuburb",nil ] ]; } } sqlite3_finalize(compiledStmt); } return facultiesArray; } { NSLog(@"START*************** category -%d items", dCategory.count ); sqlite3_stmt *compiledStmt; sqlite3_prepare_v2(database, "BEGIN TRANSACTION", -1, &compiledStmt, NULL); sqlite3_step(compiledStmt); sqlite3_finalize(compiledStmt); const char *sqlStatement="REPLACE INTO pmd_categories(id,title,description_short,description,keywords,friendly_url,friendly_url_path,title_override,meta_description,meta_keywords,link,hidden,count,level,left_,right_,hits,ip,import_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; if (sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStmt, NULL)== SQLITE_OK) { { NSUInteger cid = [[dObj objectForKey:@"id"] intValue]; if (cid) { sqlite3_bind_int(compiledStmt, 1, cid); PUTCOLUMNSTRING(2, @"title") PUTCOLUMNSTRING(3, @"description_short") PUTCOLUMNSTRING(4, @"description") PUTCOLUMNSTRING(5, @"keywords") PUTCOLUMNSTRING(6, @"friendly_url") PUTCOLUMNSTRING(7, @"friendly_url_path") PUTCOLUMNSTRING(8, @"title_override") PUTCOLUMNSTRING(9, @"meta_description") PUTCOLUMNSTRING(10, @"meta_keywords") PUTCOLUMNSTRING(11, @"link") PUTCOLUMNSTRING(12, @"hidden") PUTCOLUMNSTRING(13, @"count") PUTCOLUMNSTRING(14, @"level") PUTCOLUMNSTRING(15, @"left_") PUTCOLUMNSTRING(16, @"right_") PUTCOLUMNSTRING(17, @"hits") PUTCOLUMNSTRING(18, @"ip") PUTCOLUMNSTRING(19, @"import_id") NSUInteger err = sqlite3_step(compiledStmt); if (err != SQLITE_DONE) NSLog(@"replace error %d %s",err, sqlite3_errmsg(database)); sqlite3_reset(compiledStmt); [pool release]; } } sqlite3_finalize(compiledStmt); } sqlite3_prepare_v2(database, "END TRANSACTION", -1, &compiledStmt, NULL); sqlite3_step(compiledStmt); sqlite3_finalize(compiledStmt); NSLog(@"END*************** category"); }
You need to login to post a comment.
