Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit conversion of an Objective-C pointer to 'const char *' is disallowed with 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";
}

On the "if(sqlite3_exe..." statement, I'm getting 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 do I fix it? (note: I copied the basic format from another example... the NSMutableArray does NOT have to be mutable, if that would help things)

like image 695
SpokaneDude Avatar asked Mar 10 '12 19:03

SpokaneDude


1 Answers

According to this page, sqlite3_exec() is defined as such:

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

However, you are invoking it as:

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 are converting your NSString into a const char *).

like image 95
Richard J. Ross III Avatar answered Sep 28 '22 08:09

Richard J. Ross III