0
-(BOOL)createDB{
        NSString *docsDir;
        NSArray *dirPaths;
        // Get the documents directory
        dirPaths = NSSearchPathForDirectoriesInDomains
        (NSDocumentDirectory, NSUserDomainMask, YES);
        docsDir = dirPaths[0];
        // Build the path to the database file
        databasePath = [[NSString alloc] initWithString:
                    [docsDir stringByAppendingPathComponent: @"student.db"]];
        BOOL isSuccess = YES;
        NSFileManager *filemgr = [NSFileManager defaultManager];
        if ([filemgr fileExistsAtPath: databasePath ] == NO)
        {
            const char *dbpath = [databasePath UTF8String];
            if (sqlite3_open(dbpath, &database) == SQLITE_OK)
            {
                char *errMsg;
                const char *sql_stmt =
                "create table if not exists studentsDetail (regno integer
                primary key, name text, department text, year text)";
                if (sqlite3_exec(database, sql_stmt, NULL, NULL, &errMsg)
                    != SQLITE_OK)
                {
                    isSuccess = NO;
                    NSLog(@"Failed to create table");
                }
                sqlite3_close(database);
                return  isSuccess;
            }
            else {
                isSuccess = NO;
                NSLog(@"Failed to open/create database");
            }
        }
        return isSuccess;
}

这里出现语法错误

const char *sql_stmt = "create table if not exists studentsDetail (regno integer
                        primary key, name text, department text, year text)";
4

2 回答 2

0

如果要将字符串常量拆分为多个源代码行,则必须将 每个部分括在引号中:

const char *sql_stmt =
"create table if not exists studentsDetail (regno integer "
"primary key, name text, department text, year text)";

代替:

const char *sql_stmt =
"create table if not exists studentsDetail (regno integer
primary key, name text, department text, year text)";
于 2013-06-04T11:49:33.420 回答
-1

请用此行替换您的代码

const char *sql_stmt = [@"create table if not exists studentsDetail (regno integer primary key, name text, department text, year text)" UTF8String];
于 2013-06-04T11:37:46.050 回答