i am newbie in iOS Development i am working with sqllite database for my application i create one Database from SqlliteManager and Give name Personal.db and in my database i Create Table like as
CREATE TABLE "QpinPersonal" ("ID" INTEGER PRIMARY KEY AUTOINCREMENT, "UserName" TEXT, "QpinName" TEXT, "Address" TEXT, "Lat" DOUBLE, "Long" DOUBLE, "Type" TEXT)
And Add this Database in to My Xcode application Folder now i want to Fetch it Path To insert Value in to Database For this I write a Code like as
- (void)prepareDatabase
{
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = dirPaths[0];
_databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:@"Personal.db"]];
NSLog(@"DataBase PAth %@",_databasePath);
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: _databasePath ] == YES)
{
const char *dbpath = [_databasePath UTF8String];
if (sqlite3_open(dbpath, &_myDatabase) == SQLITE_OK)
{
char *errMsg;
const char *sql_stmt =
"CREATE TABLE IF NOT EXISTS QpinPersonal (ID INTEGER PRIMARY KEY AUTOINCREMENT, UserName TEXT, QpinName TEXT, Address TEXT, Lat DOUBLE, Long DOUBLE,Type TEXT)";
if (sqlite3_exec(_myDatabase, sql_stmt, NULL, NULL, &errMsg) != SQLITE_OK)
{
NSLog(@"Failed TO Create Table");
}
else
{
NSLog(@"DataBase Created");
}
}
else
{
NSLog(@"Failed to open/create database");
}
}
}
Then it is Running But create New Database but i want to Add the value in to my Document Directory Databse i mean i want to add Value in to my Already Created Personal.db file hoe to get its path in iOS Please Give me Solution for it.
Aucun commentaire:
Enregistrer un commentaire