duanlou2917 2016-10-11 19:16
浏览 111
已采纳

在php中阻止数据库提交断言失败

For the sanity testing of my code I am putting asserts at various places in my code.

I want it to be the case that whenever an assert is hit, the database transaction should not be completed (i.e. the data should not be committed to database, instead it should be rolled back).

I could not find any clean way of achieving this.

I am using the code igniter framework.

Any idea how to achieve this?

  • 写回答

1条回答 默认 最新

  • duangu8264 2016-10-13 04:49
    关注

    The functionality should not be part of an assert. If it is the case then the functionality will be distorted in production mode when asserts are disabled.

    We can perform additional database operation on assert failure to record and track more details of the error, but should not abort/interfere with outside transactions.

    Assertions should be used as a debugging feature only. You may use them for sanity-checks that test for conditions that should always be TRUE and that indicate some programming errors if not or to check for the presence of certain features like extension functions or certain system limits and features.

    Assertions should not be used for normal runtime operations like input parameter checks. As a rule of thumb your code should always be able to work correctly if assertion checking is not activated.

    More details

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备