Creating a database for your iPhone application is a little longer, but it has many steps, but it is so simple:
First of all, you have to download mozilla fire fox and download your add-ons, and you can find the sqlite database by clicking "Tools". And you can create a new databse file with columns and rows. Its a simple process to create a database file, after which you can include this file in your X code project.
For example: - as an image that you usually include in your Xcode project.
after that write the following code, it works well for me :)
In your. m write the following sqlite code
#import "YourHeaderFile" static sqlite3 *database = nil; static sqlite3_stmt *addStmt = nil; static sqlite3_stmt *updateStmt = nil; @implementation 'YourImplementClass' - (NSString *) getDBPath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; return [documentsDir stringByAppendingPathComponent:@"YourDataBaseFileName.sqlite"]; } - (void) insertValueToDatabase { NSString *dbPath =[self getDBPath]; NSString *select_Meal = dummy_select_Meal; NSString *dateTime = dummy_date_Time; NSString *location = dummy_location; NSString *mealItem = dummy_mealItem; if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { const char *sqlDB = "Insert into iHad(Mealtype,DateAndTime,Location,Mealitem) VALUES (?,?,?,?)"; if(sqlite3_prepare_v2(database, sqlDB, -1, &addStmt, NULL) != SQLITE_OK) NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database)); sqlite3_bind_text(addStmt, 1, [select_Meal UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(addStmt, 2, [dateTime UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(addStmt, 3, [location UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(addStmt, 4, [mealItem UTF8String], -1, SQLITE_TRANSIENT); if(SQLITE_DONE != sqlite3_step(addStmt)) NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database)); //else //SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid //coffeeID = sqlite3_last_insert_rowid(database); //Reset the add statement. sqlite3_reset(addStmt); } else sqlite3_close(database); }
and for saving you can create such a method
-(void)saveButtonClick { if (![dummy_select_Meal length] || ![dummy_mealItem length]) { UIAlertView *alert = [[UIAlertView alloc] init]; [alert setTitle:@"Select Meal Type/Meal Item"]; [alert setDelegate:self]; [alert addButtonWithTitle:@"Ok"]; [alert show]; [alert release]; } else { indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(30,30,50,50)]; indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
If you have any problems, answer me, I will help you :)