0

I have two .sqlite files. One for full version and one for Lite version. I am choosing one .sqlite file for one condition with this code:

if (FULLVERSION) {
self.databaseName = @"Alpha.sqlite";
}
else {
self.databaseName = @"AlphaLite.sqlite";
}

Now when I query I want to use this self.databaseName in that. I am doing like this now:

-(NSMutableArray *) Alpha {
    sqlite3 *database;
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
        const char *sqlStatement = "SELECT * FROM Alpha";
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {

    }
        sqlite3_finalize(compiledStatement);
    }
    sqlite3_close(database);

    return alpha;   
}

In "SELECT * FROM Alpha" line, in place of Alpha I want to use self.databaseName, which will have database name according to the condition.

How to do this? Please help. Thanks.

1
  • do you want to select database or table?, in first line you have stated you have two different databases, and later in "select" statement you want to pass database name?, in select query you can pass <tablename> or <dbname>.<tableName> Commented Mar 29, 2013 at 10:08

2 Answers 2

1

In SELECT statement, replace const char *sqlStatement = "SELECT * FROM Alpha"; with following two lines:

NSString *sqlString = [NSString stringWithFormat:@"SELECT * FROM %@", self.databaseName];
const char *sqlStatement = [sqlString UTF8String];

OR

Replace const char *sqlStatement = "SELECT * FROM Alpha"; with

const char *sqlStatement;
if (FULLVERSION) {
    sqlStatement = "SELECT * FROM Alpha";
} else {
    sqlStatement = "SELECT * FROM AlphaLite";
}
Sign up to request clarification or add additional context in comments.

1 Comment

const char *sqlStatement is declared inside if block ... be aware of it
0

You could use Stringwithformat , then get utf8string

NSString *sql = [NSString stringWithFormat:@"SELECT * FROM %@",self.databaseName];
const char *sqlStatement = [sql UTF8String];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.