如何执行复杂的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.

相关问答

更多

解析多个JSON URL(parsing Multiple JSON Url)

你只需声明你的List<moviemodel>moviemodelList = new ArrayList<>(); 在asynctask中使用相同的列表,并且在两个asynctask中使用相同的列表。如果使用在asynctask中声明列表,它将重新初始化,并且从第一个asynctask存储的以前的数据将从列表中清除。 只需声明您在create方法之上声明所有变量的列表。 you just Declare your List<moviemodel>moviemodelList = new Arra...

Json从网址解析(Json Parsing from url)

试试这个(你在我发布这个答案之后更新了这个问题。我不知道如何在Android中这样做) <html> //// this is your html content </html> <script type="text/javascript"> $("a").each(function(){ alert(this.href); }); </script> Try this (you updated the question after I pos...

从JSON快速解析多个图像(Parsing multiple images in swift from JSON)

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+"...

使用PHP从URL解析JSON(Parsing JSON from URL with PHP)

从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 ...

Android JSON从URL解析(Android JSON Parsing from URL)

尝试以下内容: try { JSONArray main = new JSONArray(responsestring); for( i=0;i<main.length();i++){ JSONObject mainobj = main.getJSONObject(i); String uid = mainobj.getString("uid"); String uname = mainobj.getString("uname"); } } catch ...

从url获取json并解析信息(Get json from url and parsing information)

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); JsonA...

JSON使用此URL解析Swift In Swift(JSON Parsing In Swift with this URL)

实际上对这个响应要非常小心,因为它可能看起来像JSON字典,但事实并非如此。 它是一个JSON字符串,其字符串本身就是JSON字典。 因此,检索它,使用带有.AllowFragments选项的.AllowFragments来处理字符串。 然后获取结果字符串,将其转换为数据,现在您可以解析实际的JSON: let url = NSURL(string: "http://www.claritin.com/weatherpollenservice/weatherpollenservice.svc/get...

使用URL解析JSON与Python(Parsing JSON with Python from URL)

只需逐个访问级别。 for i in r["response"]["blogs"]: print i["name"],i["url"],i["updated"] 所以这段代码可以用来打印blogs列表中的所有对象 解释这是如何工作的: Json对象被解码为Python中的dictionaries 。 字典是简单的键值对。 在你的例子中, r是一个包含以下键的字典: meta, response 您可以使用r [“meta”]来访问密钥的值。 现在元本身就是一本字典。 相关的键是: st...

Android JSON解析URL(Android JSON Parsing URL)

问题出在我的index.php文件中。 我有<HTML>和<body>标签。 除了我的<?php之外我删除了所有标签,它加载得很好。 The problem was in my index.php file. I had <HTML> and <body> tags. I removed all tags except for my <?php and it loads up fine.

在Java中解析来自url的JSON(Parsing JSON from url in Java)

尝试这个.. 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.len...

相关文章

更多

JDBC系列教程之四:SQL注入PreparedStatement和Statement

在SQL中包含特殊字符或SQL的关键字(如:' or 1 or ')时Statement将出现不可预料 ...

SQL Server 压力测试

转自:http://www.cnblogs.com/Amaranthus/archive/2011/0 ...

sql问题

有表格如下: t_table 8 想得到这样的结果:(只取有重复的第一个,相同的排除,例如f) 1 a ...

Sql Support within Solr-类Sql的solr搜索实现(1)

尽管lucene、solr如此的频繁、如此的普遍被使用。仍然有许多人、需要开发者所见即所得的方式,将查 ...

Solrflux源码分析-Sql Support within Solr-类Sql的solr搜索实现(2)

Solrflux开源codegoogle地址http://code.google.com/p/solr ...

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

一个sql查询

数据库表A 有个字段a是int类型 a中有数据有1到9任意(有重复的) 想取得a中,当 a=1时 ...

关于mysql 的 sql

有两张表如下: a表: id name A a B b b表: cid cname 1 ...

请教一个SQL实现

因小弟第一次发帖,问题可能描述的不是很清楚,请大家谅解,现请教大家一个SQL实现(ORACLE),情况 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本