I have one application in that i created the sqlite database and store in the document directory. Now i open other application from existing application and in that i want to access the existing database path. how can i do this can any one help me. I write the code below for open another application and calling the document directory. But it gets the the wrong document directory path.
==============
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *ourPath = @"POSRetail://";
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL])
{
databasePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@"databasePath : %@",databasePath);
NSString *filePath = [databasePath stringByAppendingPathComponent:@"testapp.sqlite"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
if(fileExists)
{
NSMutableString *strRecord =[[NSMutableString alloc]init];
//Retrieve the values of database
const char *dbpath = [filePath UTF8String];
if (sqlite3_open(dbpath, &sdatabase) == SQLITE_OK)
{
// NSString *querySQL = [NSString stringWithFormat:@"SELECT * FROM employee"];
// const char *query_stmt = [querySQL UTF8String];
const char *query_stmt = "Select * from info";
sqlite3_stmt *statement;
//const char *query_stmt = "Select * from sqlite_master where type='table'";
NSMutableArray *arrTemp = [[NSMutableArray alloc] init];
if(sqlite3_prepare_v2(sdatabase, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement)==SQLITE_ROW) {
[arrTemp addObject:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 0)]];
[strRecord appendFormat:@"%@,",[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 0)]];
[arrTemp addObject:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 1)]];
[strRecord appendFormat:@" %@,",[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 1)]];
[arrTemp addObject:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 2)]];
[strRecord appendFormat:@" %@,",[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 2)]];
[arrTemp addObject:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 3)]];
[strRecord appendFormat:@" %@\n",[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 3)]];
}
NSLog(@"arrTemp : %@",arrTemp);
sqlite3_finalize(statement);
}
else
{
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(sdatabase));
}
sqlite3_close(sdatabase);
}
else
{
sqlite3_close(sdatabase);
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(sdatabase));
}
}
else
{
NSLog(@"SQLITE DATABASE NOT AVAILABLE");
}
}
else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Receiver Not Found" message:@"The Receiver App is not installed. It must be installed." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}