关于FMDB和JOIN子句的问题
我使用 FMDB 作为 sqlite 包装器,这非常容易上手。 当我尝试连接两个(实际上是一个)表时遇到了问题。
为了区分连接的两个表的列,我必须使用 select aa as 'aa', ba as 'ba' from the_table as a join the_table as b on...
。然后我可以使用 [rs stringForColumn:@"aa"]
和 [rs stringForColumn:@"ba"]
来访问它们(其中 rs 属于 FMResultSet 类)。但我有大约 15 列,所以 sql 字符串看起来很长。我想知道是否有更简单的方法可以做到这一点?
使用select * from the_table as a join the_table as b...
,可以分别访问a和b的内容吗?可能类似于 [rs resultSetForRenamedTable:@"a"]
;
I'm using FMDB as the sqlite wrapper, which is pretty easy to get onto.
I encountered the problem when I try to join two (in fact one) table.
To distinguish the joined two table's columns, I have to use select a.a as 'a.a', b.a as 'b.a' from the_table as a join the_table as b on...
. Then I can use [rs stringForColumn:@"a.a"]
and [rs stringForColumn:@"b.a"]
to access them (Where rs is of class FMResultSet). But I have about 15 columns so the sql string seems really long. I'm wondering if there's any easier way to do this?
Using select * from the_table as a join the_table as b...
, can I access the content of a and b separately? May something like [rs resultSetForRenamedTable:@"a"]
;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,FMDB 只是 SQLite 之上的一个包装器,
我想如果在这种特殊情况下使用 *,SQLite 会引发错误。类似于:SQL 错误:不明确的列名:a
Well, FMDB is just a wrapper on top of SQLite,
I suppose SQLite will fire an error if you use * in this particular case. Something like: SQL error: ambiguous column name: a
使用 ATTACH DATABASE 查询 https://www.sqlite.org/lang_attach.html
例如:
Use ATTACH DATABASE query https://www.sqlite.org/lang_attach.html
For example: