核心数据如何保存在SQLite文件中
我将核心数据保存在 SQLite 文件中,但我想知道 coredata 中的表名是什么我有三个实体,其中之一是学生。
在尝试使用 SQLite 语句读取它时,它不输入 while
const char *sqlStatement = "SELECT * FROM students";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSLog(aName);
}
}
有什么建议为什么不输入 if 语句?
I saved core data in SQLite file but I am wonder what's the table name in coredata I have three entities one of them is students.
While trying to using SQLite statement to read it it not enter the while
const char *sqlStatement = "SELECT * FROM students";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSLog(aName);
}
}
Any suggestion why not enter the if statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,您不应该直接查询 CoreData 表,CoreData 是从代码中抽象存储的。您应该使用 NSFetchRequest。但为了回答您的问题,该表通常称为 zstudents。
Well, you shouldn't be querying your CoreData tables directly, CoreData is there to abstract the storage from the code. You should use NSFetchRequest. But to answer your question, the table will normally be called zstudents.
您确定该表实际上称为“学生”吗? sqlite数据库底层的核心数据通常有类似ZStudents的表名。您可以使用免费的 SQLite 数据库浏览器来查看 .sqlite 文件中的架构,但我想知道,如果您使用的是 Core Data,为什么还要编写 SQL 语句呢?
Are you sure the table is actually called students? The core data underlying sqlite database generally has something like ZStudents as table names. You can use the free SQLite Database browser to view the schema in .sqlite files, but I have to wonder, why are writing SQL statements if you are using Core Data?