Я пытаюсь выбрать данные из базы данных и у меня есть следующий код на месте: Код:SQLite Проблема - Путь к базе данных
// Setup the database object
sqlite3 *database;
// Init the animals Array
list = [[NSMutableArray alloc] init];
NSLog(@"documents path: ", documentsDir);
NSLog(@"database path: ", databasePath);
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select route_name from Route";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
// Add the animal object to the animals Array
//[list addObject:animal];
[list addObject:aName];
//[animal release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
я получаю сообщение об ошибке EXC_BAD_ACCESS на первой IF оператор. Любые мысли.
Также в документах NSLOGDir и databasePath пусты.
У меня есть следующий код в ViewDidLoad:
-(void)viewDidLoad
{
// Setup some globals
databaseName = @"xxxxxxCoreData.sqlite";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// NSString *documentsDir = [documentPaths objectAtIndex:0];
documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
Опубликовать вывод 'NSLog ("% @ ", databasePath);' –
Похоже, что существует проблема с документамиDir, здесь происходит ошибка EXC_BAD_ACCESS, и ничего не отображается в консоли. – Stephen
Я немного изменил код, и теперь я получаю путь к базе данных, но он не будет проходить через следующий оператор IF: if (sqlite3_open ([databasePath UTF8String] и база данных) == SQLITE_OK) – Stephen