I'm insert data into sqlite database and I've seen NSLog(#"DONE") on my console result, but I don't see the data update in my sqlite database file. Pls help me !!!
Here my code to save data:
- (void)saveData:(NSString *)_Id
{
sqlite3_stmt *statement;
NSString *_databasePath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:#"data.db"];
const char *dbpath = [_databasePath UTF8String];
if (sqlite3_open(dbpath, &db) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat:
#"INSERT INTO MyTable (id) VALUES (\"%#\")", _Id];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(db, insert_stmt,
-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(#"DONE");
} else {
NSLog(#"Failed to add contact");
}
sqlite3_finalize(statement);
sqlite3_close(db);
}
}
You are opening the database in your bundle. The bundle is read-only on the device. You must copy the database to your Documents folder (if it doesn't exist there already) and open it from there.
Also be aware that you're dealing with multiple copies of the database (the one in your project, the one in the bundle and now the one in the device/simulator's Documents folder). Make sure you're checking for the inserted record in the correct database (the one in Documents)
As an aside, you should also check to see that sqlite3_prepare_v2 returned SQLITE_OK and if not, log sqlite3_errmsg.
You should also use ? placeholder in your SQL and bind values using sqlite3_bind_text (or, if it's possibly nil, sqlite_bind_null):
- (void)saveData:(NSString *)_Id
{
sqlite3_stmt *statement;
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath ] stringByAppendingPathComponent:#"data.db"];
NSString *documentsFolder = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *documentsPath = [documentsFolder stringByAppendingPathComponent:#"data.db"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:documentsPath isDirectory:NO]) {
NSError *error;
if (![fileManager copyItemAtPath:bundlePath toPath:documentsPath error:&error]) {
NSLog(#"database copy failed: %#", error);
}
}
const char *dbpath = [documentsPath UTF8String];
if (sqlite3_open(dbpath, &db) == SQLITE_OK) {
const char *insertSql = "INSERT INTO MyTable (id) VALUES (?)";
if (sqlite3_prepare_v2(db, insertSql, -1, &statement, NULL) != SQLITE_OK) {
NSLog(#"prepare error: %s", sqlite3_errmsg(db));
}
// bind a value to the ? placeholder in the SQL
if (_Id) {
if (sqlite3_bind_text(statement, 1, [_Id UTF8String], -1, SQLITE_TRANSIENT) != SQLITE_OK) {
NSLog(#"bind text error: %s", sqlite3_errmsg(db));
}
} else {
if (sqlite3_bind_null(statement, 1) != SQLITE_OK) {
NSLog(#"bind null error: %s", sqlite3_errmsg(db));
}
}
if (sqlite3_step(statement) == SQLITE_DONE) {
NSLog(#"DONE");
} else {
NSLog(#"Failed to add contact: %s", sqlite3_errmsg(db));
}
sqlite3_finalize(statement);
sqlite3_close(db);
}
}
Most people move that "if database doesn't exist in documents, then copy it from the bundle and open it from there" logic inside a dedicated openDatabase method, but hopefully this illustrates the idea.
Related
I am using SqliteDatabase in my project.I am calling a function for data manuplation.
-(void)updateInspectionMapData2:(NSString *)clientid : (NSString *)inspectionid : (NSString *)status
{
NSLog(#"EIGHT");
NSLog(#"inside update data");
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
NSArray *checkVal = [self getSubClientDataByInspectionId:inspectionid :clientid];
NSLog(#"check is %#",checkVal);
if(checkVal == nil || [checkVal count] == 0)
{
NSString *querySql=[NSString stringWithFormat:
#"UPDATE inspectioninspectormap SET status=\"%#\" where inspectionid = \"%#\" and clientid =\"%#\" and (status = \"1\" or status = \"2\")",status,inspectionid,clientid];
NSLog(#"sql is %#",querySql);
const char *sql=[querySql UTF8String];
if(sqlite3_prepare_v2(database,sql, -1, &statement, NULL) == SQLITE_OK)
{
if(SQLITE_DONE != sqlite3_step(statement))
{
NSLog(#"Error while updating. '%s'", sqlite3_errmsg(database));
}
else
{
sqlite3_reset(statement);
NSLog(#"Update done successfully!");
}
}
sqlite3_finalize(statement);
}
}
sqlite3_close(database);
}
Please tell me is this the right way to close sqlite database.I am not sure i am right because later i get error unable to open database.?
There are many problems with your code. Here's what I see after just a quick glance:
You try to close the database even if it doesn't open.
You try to finalize the prepared statement even if the statement can't be prepared.
You needlessly call sqlite3_reset on the prepared statement.
You build your query using stringWithFormat: instead of properly binding values into the prepared statement.
You are using sqlite3_open instead of sqlite3_open_v2.
You don't log an error if sqlite3_open or sqlite3_prepare_v2 fail.
There is an issue in your code:
This code:
}
sqlite3_finalize(statement);
}
}
sqlite3_close(database);
should be changed to:
}
sqlite3_finalize(statement);
}
sqlite3_close(database);
}
Closing the sqlite should happen right after you finish your work with database, and also within the open connection if loop, but not after the open connection!!!!
When using sqlite, opening and closing should be taken care, else it could lead to lock the database. The problem occurs when you try to open another connection to sqlite without closing the previous one, then your database will be locked .To avoid this, you need make sure that every open connection should have the close connection at the end.
You can try FMDB which is an sqlite wrapper. By using the FMDB,you can simply create the sqlite database using:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *path = [docsPath stringByAppendingPathComponent:#"database.sqlite"];
FMDatabase *database = [FMDatabase databaseWithPath:path];
and you can open the database connection by:
[database open];
and close it by:
[database close];
and to execute a simple statement:
[database executeUpdate:#"create table user(name text primary key, age int)"];
There is a good tutorial out there:
+ (NSString*)setupDatabase
{
NSError *error;
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *dbFilePath = [cachePath stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.%#", DATABASENAME, DATABASETYPE]];
if (! [[NSFileManager defaultManager] fileExistsAtPath:dbFilePath])
{
// if installing the application very first time didn't find db, need to copy
NSString *backupDbPath = [[NSBundle mainBundle] pathForResource:DATABASENAME
ofType:DATABASETYPE];
BOOL copiedBackupDb = [[NSFileManager defaultManager] copyItemAtPath:backupDbPath
toPath:dbFilePath
error:&error];
if (! copiedBackupDb)
{
// copying backup db failed
NSAssert1(0, #"Failed to create writable database file with message '%#'.", [error localizedDescription]);
return nil;
}
}
return dbFilePath;
}
+ (NSString *)getDataBaseFilePath
{
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *dbFilePath = [cachePath stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.%#", DATABASENAME, DATABASETYPE]];
return dbFilePath;
}
+(NSString*)selectItem:(NSString*)itemID
{
NSString *name=nil;
NSString* _dataBasePath = [self getDataBaseFilePath];
sqlite3 *database;
if (sqlite3_open([_dataBasePath UTF8String], &database) == SQLITE_OK) {
NSString *query;
query= [NSString stringWithFormat:#"select ITEM_id from Table where IF ITEM_id='%#' ",itemID];
const char *sql=[query UTF8String];
sqlite3_stmt *selectstmt;
if (sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL)==SQLITE_OK) {
while (sqlite3_step(selectstmt)==SQLITE_ROW) {
if (sqlite3_column_text(selectstmt, 0))
name=[NSString stringWithUTF8String:(char*) sqlite3_column_text(selectstmt, 0)];
}
sqlite3_finalize(selectstmt);
}
}
sqlite3_close(database);
return (name) ;
}
+(BOOL)updateITEM:(ItemObj*)itemObj;
{
NSString* _dataBasePath = [self getDataBaseFilePath];
sqlite3 *database;
if (sqlite3_open([_dataBasePath UTF8String], &database) == SQLITE_OK) {
NSString *qs=[NSString stringWithFormat:#"UPDATE ITEM set User_ID = '%#',User_Name = '%#',Item_id = '%#',User_Status = '%#' WHERE Item_id = '%#'", itemObj.usersid, itemObj.user_name, itemObj.user_id, itemObj.user_status, itemObj.user_id];
const char *sql=[qs UTF8String];
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) != SQLITE_OK)
return FALSE;
int result = sqlite3_step(selectstmt);
if(result != SQLITE_DONE) return FALSE;
sqlite3_finalize(selectstmt);
}
sqlite3_close(database);
return TRUE;
}
this is what i am doing in header
static sqlite3 *database = nil;
static sqlite3_stmt *deleteStmt = nil;
#implementation SQLAppDelegate
#synthesize window;
#synthesize navigationController;
#synthesize coffeeArray;
this is what i am using for deleting raw
- (void) removeCoffee:(NSNumber *)coffeeObj {
NSLog(#"coffeeObj%#",coffeeObj);
int myInteger = [coffeeObj integerValue];
NSLog(#"myInteger%d",myInteger);
// print this myInteger0
NSLog(#"%#",coffeeArray);
//print object
if (sqlite3_open([self getDBPath], &database) == SQLITE_OK)
{
NSLog(#"myInteger%#",[self getDBPath]);
NSString *sql = [NSString stringWithFormat: #"delete from Coffee where CoffeeID =%d",myInteger];
const char *del_stmt = [sql UTF8String];
NSLog(#"%#",del_stmt); // getting print
// print this delete from Coffee where CoffeeID =0.
sqlite3_prepare_v2(database, del_stmt, -1, & deleteStmt, NULL);
NSLog(#"sqlite3_step(deleteStmt) == SQLITE_DONE%#",sqlite3_step(deleteStmt) == SQLITE_DONE);
// this print null
if (sqlite3_step(deleteStmt) == SQLITE_DONE)
{
//NSLog(#"hi") this is not getting print
} else {
//NSLog(#"hi") this is getting print
}
sqlite3_finalize(deleteStmt);
sqlite3_close(database);
[coffeeArray removeObjectAtIndex:myInteger];
NSLog(#"%#",coffeeArray);
// object is deleted
}
}
my table is like below
table name = Coffee
CoffeeID(INTEGER)=0
CoffeeName(VARCHAR)=Latte
Price(REAL)=2.99
where thing runs perfectly object get deleted from array and thats why its not appearing on table cell. but its not getting deleted from database table thats why it when i launch app again then it shows again please help what i am doing wrong.
Before start deleting the object just conform once the database is opened properly or not. Just try like this.
//Setting path
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: #"database.db"]];
const char *dbpath=[databasePath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
NSString *sql = [NSString stringWithFormat: #"delete from Coffee where CoffeeID =%d",myInteger];
const char *del_stmt = [sql UTF8String];
sqlite3_prepare_v2(database, del_stmt, -1, & deleteStmt, NULL);
if (sqlite3_step(deleteStmt) == SQLITE_DONE)
{
} else {
}
sqlite3_finalize(deleteStmt);
sqlite3_close(database);
[coffeeArray removeObjectAtIndex:myInteger];
NSLog(#"%#",coffeeArray);
// object is deleted
}
if(sqlite3_open([[self filepath] UTF8String], &db) == SQLITE_OK)
{
Deletestatement = nil;
if(Deletestatement == nil)
{
const char *sql = "delete from Sqlitemanager2;";
if(sqlite3_prepare_v2(db, sql, -1, &Deletestatement, NULL) != SQLITE_OK)
NSAssert1(0, #"Error while creating delete statement. '%s'", sqlite3_errmsg(db));
}
if (SQLITE_DONE != sqlite3_step(Deletestatement)) //prathibha for problem in if
NSAssert1(0, #"Error while deleting. '%s'", sqlite3_errmsg(db));
sqlite3_finalize(Deletestatement);
}
I hope this will help you.
I have two databases.
ch_coins.db is read-only data for tableview in [NSBundle mainBundle].
User_data.sqlite in Documents
I try to combine select from both databases and fill data to object. My method is like that:
-(NSMutableArray*)returnSubCountries
{
NSString *path = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:databaseName];
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *userDB = [documentsDir stringByAppendingPathComponent:user_data];
NSMutableArray *subCountiresArr=[[NSMutableArray alloc]init];
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK)
{
/*const char *sqlSubCountries="SELECT subCountryID,subCountryName,subCountryComment,image,priority,hasRegions,navigationKey\
FROM subCountries\
ORDER BY priority ASC";*/
const char *sqlSubCountries="SELECT subCountryID,subCountryName,subCountryComment,image,priority,hasRegions,navigationKey,usdb.quantity\
attach database 'userDB' as usdb\
INNER JOIN usdb on subCountries.subCountryID=usdb.refID\
FROM subCountries\
ORDER BY priority ASC";
sqlite3_stmt *statement;
int sqlResult = sqlite3_prepare_v2(database, sqlSubCountries, -1, &statement, NULL);
if ( sqlResult== SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
SubCountry *sbCountryObj=[[SubCountry alloc]init];
sbCountryObj.subCountryID=sqlite3_column_int(statement, 0);
char *subCountryName=(char *)sqlite3_column_text(statement, 1);
char *subCountryComment=(char *)sqlite3_column_text(statement, 2);
char *image=(char *)sqlite3_column_text(statement, 3);
sbCountryObj.priority=sqlite3_column_int(statement, 4);
sbCountryObj.hasRegions=(sqlite3_column_int(statement, 5)==1);
sbCountryObj.navigationKey=sqlite3_column_int(statement, 6);
sbCountryObj.quantity=sqlite3_column_int(statement, 7);
sbCountryObj.subCountryName=(subCountryName)?[NSString stringWithUTF8String:subCountryName]: #"";
sbCountryObj.subCountryComment=(subCountryComment)?[NSString stringWithUTF8String:subCountryComment]: #"";
sbCountryObj.image=(image)?[NSString stringWithUTF8String:image]: #"";
[subCountiresArr addObject:sbCountryObj];
}
sqlite3_finalize(statement);
sqlite3_close(database);
}
}
else
{
//[self dbConnectionError];
}
return subCountiresArr;
}
I must be doing something wrong. any help is much appreciated. Thanx.
EDIT:
-(NSMutableArray*)returnSubCountries
{
NSString *path = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:databaseName];
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *userDB = [documentsDir stringByAppendingPathComponent:user_data];
NSMutableArray *subCountiresArr=[[NSMutableArray alloc]init];
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK)
{
/*const char *sqlSubCountries="SELECT subCountryID,subCountryName,subCountryComment,image,priority,hasRegions,navigationKey\
FROM subCountries\
ORDER BY priority ASC";*/
NSString *userDBName = [NSString stringWithFormat:#"attach database '%#' as usdb", userDB];
const char *sqlAttachedDatabase = [userDBName UTF8String];
const char *sqlSubCountries="SELECT subCountryID,subCountryName,subCountryComment,image,priority,hasRegions,navigationKey,usdb.quantity\
sqlAttachedDatabase userDB as usdb\
INNER JOIN usdb on subCountries.subCountryID=usdb.refID\
FROM subCountries\
ORDER BY priority ASC";
sqlite3_stmt *statement;
int sqlResult = sqlite3_prepare_v2(database, sqlSubCountries, -1, &statement, NULL);
if ( sqlResult== SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
SubCountry *sbCountryObj=[[SubCountry alloc]init];
sbCountryObj.subCountryID=sqlite3_column_int(statement, 0);
char *subCountryName=(char *)sqlite3_column_text(statement, 1);
char *subCountryComment=(char *)sqlite3_column_text(statement, 2);
char *image=(char *)sqlite3_column_text(statement, 3);
sbCountryObj.priority=sqlite3_column_int(statement, 4);
sbCountryObj.hasRegions=(sqlite3_column_int(statement, 5)==1);
sbCountryObj.navigationKey=sqlite3_column_int(statement, 6);
sbCountryObj.quantity=sqlite3_column_int(statement, 7);
sbCountryObj.subCountryName=(subCountryName)?[NSString stringWithUTF8String:subCountryName]: #"";
sbCountryObj.subCountryComment=(subCountryComment)?[NSString stringWithUTF8String:subCountryComment]: #"";
sbCountryObj.image=(image)?[NSString stringWithUTF8String:image]: #"";
[subCountiresArr addObject:sbCountryObj];
}
sqlite3_finalize(statement);
sqlite3_close(database);
}
else
{
NSLog(#"%s: prepare failed: %s", __FUNCTION__, sqlite3_errmsg(database));
}
}
else
{
//[self dbConnectionError];
}
return subCountiresArr;
}
You're specifying the database path as userDB in your SQL, but that's not the name of the database file. That is, the name of the variable that has the full path name in it, but you presumably actually have to build your SQL with that filename. For example:
NSString *sql = [NSString stringWithFormat:#"attach database '%#' as usdb", userDB];
const char *sqlAttachedDatabase = [sql UTF8String];
Execute that. Then, as a separate statement, you can execute your SELECT SQL that uses the usdb alias. And when you're done, detach the database.
Also, I notice that you're checking to see if the result is SQLITE_OK (which is good). But you're not showing any diagnostic information if it's not. For example, your SQL is wrong, but you're not showing a meaningful error message. Thus, if your sqlite3_prepare_v2 fails to return SQLITE_OK, you should:
NSLog(#"%s: prepare failed: %s", __FUNCTION__, sqlite3_errmsg(database));
If you do this when you have an error, you'll be able to figure out what's wrong. Without that, you're flying blind.
A working example, where my "author" database is in the bundle, and my "book" database is in Documents:
int rc;
NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *bookFilename = [docsPath stringByAppendingPathComponent:#"book.sqlite"];
NSString *authorFilename = [[NSBundle mainBundle] pathForResource:#"author" ofType:#"sqlite"];
sqlite3 *database;
if ((rc = sqlite3_open([authorFilename UTF8String], &database)) != SQLITE_OK)
{
NSLog(#"%s: open failed: %s (%d)", __FUNCTION__, sqlite3_errmsg(database), rc);
return;
}
NSString *sql = [NSString stringWithFormat:#"attach database '%#' as userdb;", bookFilename];
if ((rc = sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL)) != SQLITE_OK)
NSLog(#"%s: attach failed: %s (%d)", __FUNCTION__, sqlite3_errmsg(database), rc);
sqlite3_stmt *statement;
sql = #"select book.*, author.* from userdb.book inner join author on author_id = book_author_id;";
if ((rc = sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL)) != SQLITE_OK)
NSLog(#"%s: prepare failed: %s (%d)", __FUNCTION__, sqlite3_errmsg(database), rc);
while ((rc = sqlite3_step(statement)) == SQLITE_ROW)
{
// do whatever you want row by row
NSLog(#"Row");
}
if (rc != SQLITE_DONE)
NSLog(#"%s: step failed: %s (%d)", __FUNCTION__, sqlite3_errmsg(database), rc);
sqlite3_finalize(statement);
sql = #"detach database userdb;";
if ((rc = sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL)) != SQLITE_OK)
NSLog(#"%s: detach failed: %s (%d)", __FUNCTION__, sqlite3_errmsg(database), rc);
sqlite3_close(database);
You should do the following:
Run SQL "attach database 'full db path' as usdb", where "full db path" is full path to database file
Prepare and execute SELECT statement (remove "attach database ..." from it)
Detach database when it's not needed "detach database 'full db path'"
I'm trying to access to my table in my SQLite using this code :
fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:#"movieData.sqlite"];
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK){
const char *sql = "SELECT movieName FROM myMovies";
sqlite3_stmt *sqlStatement;
if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
{
NSLog(#"Problem with prepare statement");
}
My output is "Problem with prepare statement". I'm pretty sure about my table name and other things in the *sql. But still doesn't work. any idea guys ?!
added
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(#"Cannot locate database file '%#'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(#"An error has occured.");
}
just before cont char *sql and it's working now :)
I am trying to insert text data into sqlite3 database in iOS.
I wrote following codes to save data into sqlite3 database.
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"MgDB.sqlite"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(#"File Not Found");
}
if((!sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK))
{
NSLog(#"Error in MyInfo");
}
const char *sql = "Insert into MyDB (name,address,email) values('%#','%#','%#')";
sqlite3_bind_text(sqlStmt, 0, [Name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(sqlStmt, 1, [Address UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(sqlStmt, 2, [Email UTF8String], -1, SQLITE_TRANSIENT);
if(sqlite3_prepare(database, sql, -1, &sqlStmt, NULL))
{
NSLog(#"Error in Loading database");
}
if (sqlite3_exec(database, sql, NULL, NULL, NULL) == SQLITE_OK)
{
return sqlite3_last_insert_rowid(database);
}
if(sqlite3_step(sqlStmt) == SQLITE_ROW)
{
NSLog(#"ERROR");
}
}
#catch (NSException *exception)
{
NSLog(#"%#",exception);
}
#finally
{
sqlite3_finalize(sqlStmt);
sqlite3_close(database);
}
according to my above code,I return the last insert ROWID to check that inserted or not.
After saved text data in View,the ROWID have increased.
However when i check my database with FireFox sqlite3 tools, there are no any data that i have inserted.
So i stop running and ReRun my app and add data again.
The last insert ROWID is the same with old count.Not increase even one.
I want to know why it's doesn't save any data into sqlite database.
Is there any problem in my code?
Please help me.
Thanks in advance.
NSString *dbPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"MgDB.sqlite"];
You can't write to files included in the application bundle. Create (or copy) the database in the Documents directory instead.
See QA1662.