Implicit conversion of Objective-C pointer to 'const char *' prohibited by ARC?

This is my code:

//--   check for d/b; create it if it doesn't exist
NSString *docsDir;
NSArray *dirPaths;

NSMutableArray *sqliteArray = [NSMutableArray array];
[sqliteArray addObject: @"CREATE TABLE IF NOT EXISTS SiteData (SITE_ID TEXT PRIMARY KEY NOT NULL, STA1 TEXT "
    "TBM TEST, SITE_DESC TEXT, REMARKS TEXT, LOOP_COUNT INTEGER, DATE TEXT)" ];
[sqliteArray addObject: @"INSERT INTO SiteData (SITE_ID, LOOP_COUNT) VALUES('','')"];
[sqliteArray addObject: @"CREATE TABLE Readings (SITE_ID TEXT REFERENCES SiteData, LOOP_NBR TEXT, LOOP_CLOSED BINARY, "
    "SEQ INTEGER, STA TEXT, BS TEXT, FS TEXT, DESC TEXT, SSBS TEXT, SSFS TEXT)" ];
[sqliteArray addObject: @"INSERT INTO Readings (SITE_ID, SEQ) VALUES ('','')"];
[sqliteArray addObject: @"CREATE TABLE EmailAddress (EMAIL_ADDRESS TEXT)"];
[sqliteArray addObject: @"INSERT INTO EmailAddress (EMAIL_ADDRESS) VALUES ('Enter email address here')" ];


//  get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
docsDir = [dirPaths objectAtIndex: 0];

//  build path to the d/b file
databasePath =[[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"r64.sdb"]];
NSFileManager *filemgr = [NSFileManager defaultManager];

if([filemgr fileExistsAtPath:databasePath] == NO)  {
    const char *dbpath = [databasePath UTF8String];
    if(sqlite3_open(dbpath, &dbLevelingData) == SQLITE_OK) {
        char *errMsg;
        int i;

        for(i = 0; i < [sqliteArray count]; i++)  {
        if(sqlite3_exec(dbLevelingData, [sqliteArray objectAtIndex:i] , NULL, NULL, &errMsg) != SQLITE_OK)  
            status.text = @"Failed to create table";
        }

        sqlite3_close(dbLevelingData);
    }
    else 
        status.text = @"Failed to open/create database";
}

      

In the if (sqlite3_exe ... "statement, I get the following build error:

Implicit conversion of an Objective-C pointer to 'const char *' is disallowed with ARC

      

Why (I don't see any "const" char)? and how can i fix this? (note: I copied the base format from another example ... NSMutableArray should NOT be mutable in case it helps something)

+3


source to share


1 answer


According to this page , it sqlite3_exec()

is defined as such:

int sqlite3_exec(sqlite3*,const char *, int (*)(void*,int,char**,char**), void *, char **);

      

However, you call it like:

int sqlite3_exec(sqlite3 *, id, int(*)(void *)(void *, int, char**, char **), void *, char **);

      



So, if you change your function call to this:

sqlite3_exec(dbLevelingData, [[sqliteArray objectAtIndex:i] UTF8String], NULL, NULL, &errMsg)

      

Your code should work fine (basically, we'll convert your NSString

to const char *

).

+5


source







All Articles