Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To creat a data base for your iPhone app is a little bit lengthy but it has many steps but it is so simple :<br><br> First of all you should to download mozilla fire fox and download its add ons and you can find sqlite database option by clicking Tools Option. And you can creat a new Databse file with columns and rows . Its just simple process to creat a data base file and after that you can include that file into your X code project.<br> <br>For example :- just like an image which you commonly included in your Xcode project.</p> <p>after that write the following code it is working nice for me :)</p> <p>In your . m file write the following sqlite code</p> <pre><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], &amp;database) == SQLITE_OK) { const char *sqlDB = "Insert into iHad(Mealtype,DateAndTime,Location,Mealitem) VALUES (?,?,?,?)"; if(sqlite3_prepare_v2(database, sqlDB, -1, &amp;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); } </code></pre> <p>and for save you can creat a method like this</p> <pre><code>-(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;//UIActivityIndicatorViewStyleWhiteLarge;// [self insertValueToDatabase];-----------------------&gt; To insert data into data base iHadAppDelegate *delegate = [[UIApplication sharedApplication]delegate]; [delegate readMealsFromDatabase]; [rootController reloadTable_SaveButton]; } [rootController showTablePopupAction:nil]; } </code></pre> <p>Still if you have any problem then reply me i will do help you :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload