首页 \ 问答 \ 如何执行复杂的sql语句并在数组中获取结果?(How to execute a complex sql statement and get the results in an array?)

如何执行复杂的sql语句并在数组中获取结果?(How to execute a complex sql statement and get the results in an array?)

我想使用SQLite.swift执行一个相当复杂的SQL语句,并将结果最好放在一个数组中,以用作tableview的数据源。 声明如下:

SELECT defindex, AVG(price) FROM prices WHERE quality = 5 AND price_index != 0 GROUP BY defindex ORDER BY AVG(price) DESC

我正在研究SQLite.swift文档,以了解如何正确地完成它,但我找不到办法。 我可以在数据库上调用prepare并遍历Statement对象,但这不是最佳的性能。

任何帮助,将不胜感激。


I would like to execute a fairly complex SQL statement using SQLite.swift and get the result preferably in an array to use as a data source for a tableview. The statement looks like this:

SELECT defindex, AVG(price) FROM prices WHERE quality = 5 AND price_index != 0 GROUP BY defindex ORDER BY AVG(price) DESC

I was studying the SQLite.swift documentation to ind out how to do it properly, but I couldn't find a way. I could call prepare on the database and iterate through the Statement object, but that wouldn't be optimal performance wise.

Any help would be appreciated.


原文:https://stackoverflow.com/questions/29986270
更新时间:2023-03-11 17:03

最满意答案

你只需声明你的List<moviemodel>moviemodelList = new ArrayList<>(); 在asynctask中使用相同的列表,并且在两个asynctask中使用相同的列表。如果使用在asynctask中声明列表,它将重新初始化,并且从第一个asynctask存储的以前的数据将从列表中清除。

只需声明您在create方法之上声明所有变量的列表。


you just Declare your List<moviemodel>moviemodelList = new ArrayList<>(); out of the asynctask and used the same list in both asynctask.If you use declare the list inside asynctask it re-initialized and the previous data which store from first asynctask clear from list.

Just declare the list where you declare all variable above the create method.

相关问答

更多
  • 你只需声明你的ListmoviemodelList = new ArrayList<>(); 在asynctask中使用相同的列表,并且在两个asynctask中使用相同的列表。如果使用在asynctask中声明列表,它将重新初始化,并且从第一个asynctask存储的以前的数据将从列表中清除。 只需声明您在create方法之上声明所有变量的列表。 you just Declare your ListmoviemodelList = new ArrayList ...
  • 试试这个(你在我发布这个答案之后更新了这个问题。我不知道如何在Android中这样做) //// this is your html content Try this (you updated the question after I posted t ...
  • u can do soemthing like this 让eventImages = MediaEventData [“eventImages”]为? [[String:Any]] if (eventImages?.count)! > 0 { for i in 0...eventImages.count{ let bannerImage = eventImages?[i]["bannerImage"] as? String self.imageUrl = self.url+"/imag ...
  • 从PHP手册 如果无法解码json或编码数据深于递归限制,则返回NULL 由于您没有指定递归限制,因此可能是您的JSON无效或者没有从您的URL中检索任何内容。 要尝试三件事: 确定是否存在json_decode错误 print_r(json_last_error()); // call after json_decode 检查是否正在返回数据 print_r($url); 查看数据是否将作为对象进行解码 $obj = json_decode($url); print_r($obj); From PHP M ...
  • 尝试以下内容: try { JSONArray main = new JSONArray(responsestring); for( i=0;i
  • JsonObject与Java中的Map接口类似: 它存储具有关联值的键。 例: JsonObject obj = new JsonObject(); JsonObject obj1 = new JsonObject(); obj1.put("obj1_key1","obj1_value1"); obj1.put("obj1_key2","obj1_value2"); obj1.put("obj1_key3","obj1_value3"); obj.put("obj1",obj1); JsonArray就 ...
  • 实际上对这个响应要非常小心,因为它可能看起来像JSON字典,但事实并非如此。 它是一个JSON字符串,其字符串本身就是JSON字典。 因此,检索它,使用带有.AllowFragments选项的.AllowFragments来处理字符串。 然后获取结果字符串,将其转换为数据,现在您可以解析实际的JSON: let url = NSURL(string: "http://www.claritin.com/weatherpollenservice/weatherpollenservice.svc/getforec ...
  • 只需逐个访问级别。 for i in r["response"]["blogs"]: print i["name"],i["url"],i["updated"] 所以这段代码可以用来打印blogs列表中的所有对象 解释这是如何工作的: Json对象被解码为Python中的dictionaries 。 字典是简单的键值对。 在你的例子中, r是一个包含以下键的字典: meta, response 您可以使用r [“meta”]来访问密钥的值。 现在元本身就是一本字典。 相关的键是: status, ...
  • 问题出在我的index.php文件中。 我有和标签。 除了我的 and tags. I removed all tags except for my
  • 尝试这个.. JSONArray new_array = new JSONArray(response); for(int i = 0; i < new_array.length; i++){ System.out.println("Values : "+new_array.getString(i)); } Try this.. JSONArray new_array = new JSONArray(response); for(int i = 0; i < new_array.length; ...

相关文章

更多

最新问答

更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)