我的数据库没有立即插入

发布于 2024-08-09 09:46:18 字数 361 浏览 4 评论 0原文

我正在尝试应用测试驱动开发来生成网页,但在使用我的数据库时遇到问题。我正在使用 Cake 1.1、PHP5 和 SimpleTest 进行单元测试。

我的问题是我有一个测试:

  1. 使用直接 SQL 语句插入一行
  2. 测试该行是否已插入(通过使用主程序中的函数)。
  3. 删除已插入的行。

步骤 1 和 3 都工作正常,但步骤 2 失败。

重要的是要认识到,如果我运行测试而不删除该行(我将其注释掉),然后再次运行测试,但首先消除步骤 1(再次简单地注释该行),并且测试顺利通过。

我还尝试在 PHPMyAdmin 中直接运行 SQL 语句(在编辑器中一个接一个),它们工作得很好。

I am a trying to apply Test Driven Development to producing a web page and am having trouble using my database. I am developing using Cake 1.1, PHP5 and SimpleTest to unit test.

My problem is that I have a test that:

  1. Inserts a row using a direct SQL statement
  2. Tests if that row was inserted (by using a function in my main program.)
  3. Deletes the row that was inserted.

Both steps 1 and 3 work fine but step 2 fails.

It's important to realize that if I run the test without deleting the row (I commented that out) and then ran the test again but first eliminating step 1 (once again simply commenting that line) and the test passed without a problem.

I also tried running the SQL statements directly (one after another in the editor) in PHPMyAdmin and they work perfectly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烂人 2024-08-16 09:46:18

所有步骤都在同一个事务中执行吗?

如果不是,则在步骤 1 提交之前,步骤 2 无法看到步骤 1 的结果。

Are all steps executed in the same transaction?

When not, step 2 isn't able to see the result of step 1 until step 1 commits.

飘落散花 2024-08-16 09:46:18

听起来确实像是您的插入发生在您尝试测试时尚未提交的事务内。

你能给出一些示例代码吗?

It does sound like your insert is happening inside a transaction that has not yet been committed when you attempt the test.

Can you give some sample code?

向日葵 2024-08-16 09:46:18

您确定要在步骤 1 中提交交易吗?

Are you sure you are committing the transaction in step 1?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文