iphone xcode sqlite3_open удаленный хост - PullRequest
0 голосов
/ 28 декабря 2010

Я пытаюсь подключиться к моему серверу с помощью команды sqlite3_open!

мой вопрос ... это возможно? я получил следующий код ...

 // Get the path to the documents directory and append the databaseName
 databaseName = @"AnimalDatabase.sql";
 NSString *serverpath = @"http://localhost/app/";

 databasePath = [serverpath stringByAppendingPathComponent:databaseName];


and then this here

-(void) readAnimalsFromDatabase {
 // Setup the database object
 sqlite3 *database;

 // Init the animals Array
 animals = [[NSMutableArray alloc] init];

 // 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 * from animals";
  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)];
    NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
    NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];

    // Create a new animal object with the data from the database
    Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];

    // Add the animal object to the animals Array
    [animals addObject:animal];

    [animal release];
   }
  }
  // Release the compiled statement from memory
  sqlite3_finalize(compiledStatement);

 }
 sqlite3_close(database);

}

любое предложение ??

Ответы [ 2 ]

0 голосов
/ 28 декабря 2010

Ответ просто НЕТ , в вашем коде все равно много ошибок. Например:

databaseName = @"AnimalDatabase.sql";

Где ты это взял? iPhone работает с базой данных sqlite, он не имеет ничего общего с файлами sql:)

0 голосов
/ 28 декабря 2010

Откуда вы взяли, что SQLite может открывать базу данных по URL ??Он может открывать только файлы (или создавать временные БД в памяти).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...