问题标签 [qsqlquery]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
197 浏览

c++ - isSelect QSqlQuery not working as expected

I have the following code:

and I got something like this at execution:

And I keep getting "no next" no matter how many times I execute it. Then I copy and paste

into my favorite sql editor and execute it. It returns one cell ( one line/ one column ), column is named "bk_cod" and value is 'bk38'

Then I execute the program again and get:

And from there I keep getting "1300610792 ==> bk38" no matter how many times I execute it.

Some context

the query create_bsk is not re-entrant, It performs updates so that the result 'bk38' which is an identifier is either:

  1. created
  2. retrieved
  3. '' (the empty string) is the cell value to tell that basket will be ignored and no id was generated

But It always returns a cell. So according to here QSqlQuery::next() should be "true".

And as shown above, no matter how many times I execute my program, it always returns "no next" as long as it has not been executed in sql editor, and then as soon as I execute it in my editor, no matter how many times I execute my program, it will always return the same 'bk_cod' as ID.

What am I missing ? The problem occurs in most cases but not all the time and I haven't been able to figure out any pattern.

0 投票
0 回答
437 浏览

c++ - QT 5.01 QSqlDatabase 连接,QSqlQuery 执行,但是从 sqlite 数据库中找不到任何东西

如标题所述,我为 QT 编写了连接到 sqlite 数据库的代码。

数据库连接和打开都很好,但是在测试 query.first()、query.next()、query.isValid()、query.isActive() 和 query.isSelect() 的结果都是错误的。OMBI.db 已放置在 QT 的项目文件夹中,因为这是我第一次使用 QT,我不确定这是否是正确的协议。

我一直试图找到解决这个问题的方法太久了,我已经搜索了很多,但无济于事。希望你们中的一些大师可以阐明我做错了什么。

编辑:

我已经确定 exec() 失败并且 query.lastError() 报告“没有查询无法获取行”。我现在正试图确定是什么导致查询如此悲惨地失败。我检查了 _db->lastError() 但它是空的,我认为这是一件好事。

0 投票
1 回答
83 浏览

r - 在 data.frame 中获取用户指定变量的数据

我昨天问了这个问题并得到了回答,但我认为他们并没有真正理解我的问题。我需要从数据库中提取数据。但是用户提供了变量列表。我需要我的代码循环遍历每个请求的变量,提取与之关联的数据并将其放入 data.frame 中,以供分析。

0 投票
3 回答
154 浏览

sql - SQL。当我尝试执行类似“INSERT INTO Table VALUES(x1,x2,x3) - x1 x2 x3 可以是 sql 查询,例如 SELECT <...>

我想做这样的事情:

但它不起作用。当然对于显然错误在哪里的人来说,也许他会告诉我如何正确地做。

0 投票
4 回答
1252 浏览

java - 如何创建选择查询以获取树结构数据库表中任何特定节点的所有子节点

我的树结构是在此处输入图像描述

我创建的数据库表是在此处输入图像描述

如何创建选择查询以获取树结构数据库表中任何特定节点的所有子节点。

例如我通过superior_emp_id = 1然后它返回{2,3,4,5,6,7}

0 投票
0 回答
1292 浏览

qt - 为什么所有这些 QSqlQuery 属性都返回 false?

我已经设置了一个这样的数据库,并确认正在从名为“person”的表中成功添加和读取记录:

现在要了解有关 QSqlQuery 上各种属性的更多信息,我制作了这个目前仅用于调试的函数:

当我运行上述内容时,我得到:

在创建表之前和之后,这些属性都没有返回 true,这是为什么呢?

0 投票
1 回答
47 浏览

sql - 如何在sqlserver中比较记录并赋值

我的数据库中有两列“名称”和“ID”

例如

目前我已经为所有人分配了“id”0。我想编写一个存储过程或查询,将相同的 id(任何随机值)分配给多次发生的记录。其他记录的 ID 保持为 0 。例如 john 和 Alex 发生了两次。所以他们的 id 应该更新,否则其他记录的 ID 保持不变。这是我的样本和想要的输出

0 投票
1 回答
22124 浏览

c++ - Qt QSqlQuery bindValue 适用于?但不是 :placeholders

我正在使用 SQLite,插入到表中。跟随

有效,但是

不。testQuery.lastError().text() 返回无查询无法获取行

不知道为什么会这样,但真的很想知道。

0 投票
2 回答
1309 浏览

c++ - 使用 Qt 在 C++ 中编写函数

我大部分都知道如何在 C++ 中格式化函数,除了我以前从未见过的这种情况。

我目前有这个:

当然,它可以编译一切。它做的正是它应该做的——扫描 SQLite 数据库的内容并通过 QTableWidget 输出它,按员工姓氏排序,只要你点击“viewEmployees”按钮。没有问题。

但是我想把它转换成一个函数......比如说,DatabaseControl.refreshTableView()。

我将其复制/粘贴到 DatabaseControl 类中,并且我知道将所有 DatabaseControl 引用更改为“this”,但是我不知道如何处理“ui->”位,因为 ui-> 在我的 mainwindow.cpp:

结果,我无法更改 MainWindow 中的任何 UI 元素(据我所知)。我想要做的是能够通过 DatabaseControl 类编辑这些 UI 元素。更具体地说,我想通过 DatabaseControl 编辑该 QTableWidget 的内容。

0 投票
1 回答
3659 浏览

c++ - SQLite+Qt:从表中选择总是返回单行

我使用以下代码使用 Qt 从 SQLite DB 获取数据:

Words表确实包含ref_id字段等于所需值的行。我已经使用作为 Qt 演示应用程序提供的 sqlbrowser 进行了检查。但QSqlQuery::next( )仅第一次返回 true,我无法获取其余行。

顺便说一句,在这里我发现了类似的问题,但对我来说向后迭代不起作用

下面我把整个功能代码:

解决方案:我没有找到问题的原因,但以下变体似乎是有效的变体: