dongzhankou2090 2015-02-18 03:45
浏览 45

将MySQL EXACTLY ONCE中的信息显示给Android用户

suppose I have this MySQL table:

+-----+-------------+------+
| id  | info        | seen |
+-----+-------------+------+
| 1   | bla bla     | 0    |
+-----+-------------+------+

I want to build a RESTful API where an android client provides the rowID and gets to see the information. After I echo the Information I set seen=1 such that the user cannot access the information a second time.

Suppose I do all of this in one request like:

- $id = $_GET['id']
- SELECT * FROM table WHERE seen=0 and id=$id
- echo $info
- UPDATE table SET seen=1 WHERE id=$id

what happens if the user looses connection and 'seen' is updated 1 even if the user never received $info? how can I make sure this never happens/ how can I detect this?

I also thought about sending two requests, one to get the $info and one to approve that the information was received. But this way the user could just receive the information multiple times by not sending the received message.

thanks for any help :)

  • 写回答

1条回答 默认 最新

  • dszm02606009 2015-02-18 03:47
    关注

    You could assign the variable in the update statement:

    UPDATE table
       SET seen = if(@info := info, 1, 1)
       WHERE id = $id;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题