ios - 通过代码在sqlite3中启用foreign_keys=ON

标签 ios iphone ipad sqlite

我在几个表中添加了一对一,一对多的关系......

我以编程方式创建了数据库和表我想为我的表启用外键, 我为此开火 sqlite3_excec(db,PRAGMA foreign_keys=ON,0,0,&error)

这是行不通的!它正在创建文本文件而不是 sqlite3。

请告诉我是否有任何在 sqlite3 中启用 PRAGMA foreign_keys=ON; 的解决方案

最佳答案

在打开数据库的方法中编写这段代码

sqlite3_stmt *enableForeignKey;
NSString *strsql = [NSString stringWithFormat:@"PRAGMA foreign_keys = ON"];

const char *sql=(char *)[strsql UTF8String];
if (sqlite3_prepare_v2(database, sql,-1, &enableForeignKey, NULL) != SQLITE_OK) {
    NSLog(@"ERROR IN PRAGMA!");
}

关于ios - 通过代码在sqlite3中启用foreign_keys=ON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20189434/

相关文章:

iphone - 在 Xcode 中以编程方式创建文件夹 - Objective C

javascript - 如何使用 PhoneGap + Cordova 在 Android 应用程序中启用横向和纵向模式

iphone - 应用程序处于后台状态时的 CLLocationManager

iphone - 从 super View 中删除当前 View

ios - 在 unwind 中强制 segue

iphone - Objective-C 自定义属性 getter 无限递归

Html 5 [input type=Date] 控件,MAX 日期在 iPhone/Ipad 中不起作用

ios - 如何使用 2 个 View 从 IOS 应用程序发送电子邮件?

iOS在UIView上闪烁动画的次数有限

ios - 将文本从 UIAlertView 文本字段传递到自定义单元格标签