- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想获取如下结构的数据。
//像这样的媒体表::-
import UIKit
@objc(Media)
class Media: DBObject {
dynamic var media_id : NSNumber!;
dynamic var post_id : Post!;
dynamic var desc : String!;
dynamic var url : String!;
}
我想从“Post”表中获取数据,并从“Media”表中获取媒体列表。
一个帖子可能有多个媒体或它可能不是(媒体列表零)。
请建议 DBAccess 查询以在 Swift 中获取 DBResultSet。
最佳答案
您可以向查询添加一个参数,joinTo。
这是头文件中的条目。
/**
* Used to include "joined" data within the query string, you must use the tablename.columnname syntax within a where statement
*
* @param (Class)joinTo the class you would like to pwrform a SQL JOIN with
* @param (NSString*)leftParameter the property name that you would like to use within the local object to match against the target
* @param (NSString*)targetParameter the property within the class you wish to join with that will be matched with the left parameter.
* @return (DBQuery*) this value can be discarded or used to nest queries together to form clear and concise statements.
*/
- (DBQuery*)joinTo:(Class)joinClass leftParameter:(NSString*)leftParameter targetParameter:(NSString*)targetParameter;
下面是一个 swift 示例,链接两个表(员工和登录)。
Employee.query().joinTo(Login, leftParameter: "login", targetParameter: "Id")
显然,该类无法在运行时更改,因此您可以在 Dictionary 对象中找到结果,joinedResults
尽管您所描述的内容更多地与关系有关,但我建议您查看此处的一对多示例:
Relating two objects in DBAccess
因此,根据您的具体情况,您可以将以下方法添加到您的 Post 类中。
func media -> DBResultSet {
return Media.query().whereWithFormat("post_id = %@", withParameters: [self.post_id]).fetch()
}
这将从媒体表中查找并返回结果。
关于ios - 在 swift 中编写连接查询 DBAccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37161123/
我正在为我的项目使用 dbaccess。在我的项目中,一个 dbobject 的提交不起作用。我的 dbobject 是这样的消息: #import @interface MessageObject
我正在为我的项目使用 dbaccess。我想知道,dbaccess是否支持long long值? If I stored date timestamp 745665352687 than if I
我正在尝试使用委托(delegate)函数调试查询 - (void)queryPerformedWithProfile:(DBQueryProfile*)profile { NSLog(@"
我有像这样的 dbobject: #import #import @interface GroupMember : DBObject @property (strong) NSString *fi
假设我有: 一个名为“my_database”的 Informix 数据库 一个名为“my_table”的表,包含“col_1”、“col_2”和“col_3”列: 我可以通过创建 来提取表的内容my
我正在测试 DBAccess 以查看是否可以在项目中使用它。我在更改 sqlite 文件的位置时遇到问题,我希望它位于缓存目录中。这是我到目前为止在 AppDelegate.m 中编写的部分代码: -
我正在为我的 iOS 项目使用 dbaccess。如何将数组传递给 dbaccess 对象?例如:我有像这样的 dbobject: @interface Member : DBObject @prop
我想获取如下结构的数据。 //像这样的媒体表::- import UIKit @objc(Media) class Media: DBObject { dynamic var media
我正在研究我的数据库访问类,它试图使用 sqlite3 函数调用数据库,但我收到了所有这些错误,如果有人以前经历过这些错误或者他们有任何错误,我只是受伤了了解为什么它们可能会发生。 Undefined
我在更新现有记录 (DBAccess ORM) 时遇到问题。我想通过“ID”使用特定字段更新特定记录。 请查看以下 swift 代码。 func updatePostDataById(Post_id:
大家早上好, 你们中的一些人可能熟悉 Adrian Herridge 编写的“DBAccess”,它是 CoreData 的替代品。它是用 ObjC 编写的,虽然我已经成功地将对象的添加转换为 swi
我们计划在我们的 iOS 应用程序中使用 DBAccess。我们无法找到在应用程序运行时删除表格的方法。 我们的实际用例是找出数据库何时更新,然后删除或更改一些表。 DBAccess 似乎也没有将版本
我想确保以正确的方式格式化查询中的子句。例如,我有以下代码: int count = [[[MyDBObject query] whereWithFormat:@"url like '%%@%'",
我想更新多条记录(DBAccess ORM)。按特定字段的条件。比如 set city = "Goa"where name = "atul"。 请查看以下 swift 代码,它工作正常。但是如何在不使
我的问题是如何将 dbaccess 框架与现有的 sqlite 数据库一起使用?我的设备的文档文件夹中有“test.sqlite”文件。我什至将它重命名为“test.db”。当我尝试提交我的类 Wor
我要运行 dbaccess ,并将输出存储到 shell 变量。我知道有两种方法可以 (i) 输出到管道和 (ii) 卸载到文件。我想使用方法 (i) 种方法将查询输出存储到 shell 变量,但
我有两个类。第一个是 AbstractEntity.swift: class AbstractEntity : DBObject{ //... } 另外一个是User.swift,它继承了Ab
我正在尝试将 DBAccess 添加到我的 iOS 项目中。 从 AppDelegate 导入效果很好,但是当从 .mm 文件导入时,甚至在 .mm 文件中导入另一个导入 DBAccess.h 的类时
我正在尝试使用 id 初始化实体。 User *user = [[User alloc] initWithPrimaryKeyValue:userID]; 如果数据库中没有具有此 ID 的实体,它总是
我在使用声明 bool 类型和 Int 类型字段的 DBObject (DBAccess ORM) 中创建表时面临问题,而且我无法声明“描述”提交。 //Swift 代码:- 导入UIKit @obj
我是一名优秀的程序员,十分优秀!