背景: 执行mysql语句报错, Truncated incorrect DOUBLE value.
这是个非常奇怪的报错.因为实际错误和提示的并没啥关系,所以你很容易懵了,被提示误导.

这个错误经常是发生在UPDATE语句中

  • 原因1: 你将一个不能用数字表示的字符串与数字比较在where语句中. 原因是和数字比价时,mysql会字符串先转换为数字,转的时候出错就会报这个错. 如下

    UPDATE students 
    SET score = 5
    WHERE student_id = 87463298107;//student_id为字符串类型,存的值有数字或者英文字母, 所以当比到包含英文字母的行时就会出错
    • 解决方法: 字段什么类型就和什么类型值比较.改后如下

      UPDATE students 
      SET score = 5
      WHERE student_id = '87463298107';

      有趣的是,同样的where从句放在select语句中,能执行并不会报错.

  • 还有种错误是语法错误

    UPDATE students 
    SET name = 'Sarah' 
      AND score = 9
    WHERE id = '1';

    会报错ERROR 1292 (22007): Truncated incorrect DOUBLE value: 'Sarah'. 你可能会被误导是Sarah值是不是有什么问题.然而其实和他并没关系.
    实际错误是语法错误, update多个值不是用and连接而是要将and替换成,.如下

    UPDATE students 
    SET name = 'Sarah',
      score = 9
    WHERE id = '1';

ref: https://sebhastian.com/mysql-truncated-incorrect-double-value/

问题: Golang IDE在按下f8进行步进调试时, 发现一直显示connected, 卡住无法往下走.
怀疑: 最近有更新了go版本,怀疑可能和这个有关.
解决方案: 试了几个网上办法.发现这个办法管用,而且很简单, 30s搞定.
大体原因是delve版本太低可能不兼容.(delve是专门用于go调式的工具) 具体操作如下

  1. Install the latest delve (mac平台用brew命令安装即可很快,命令: brew install delve)
  2. then in IntelliJ: Help → Edit Custom Properties...
    Add the following as a new line
    dlv.path=/usr/local/bin/dlv
  3. Save, close and restart the IDE

这套下来30s, 遇到类似的情况, 强烈建议试试!

    /**
     * unset多维数组中指定的key
     * @param $arr
     * @param $name "a[b]" or "1[1]"
     * @return bool
     */
    public static function unsetByIndex(&$array, $name)
    {
        $matches = [];
        if(!preg_match_all('/\[?([\w-]+)\]?/', $name, $matches)) {
            return false;
        }
        if(!empty($matches) && !empty($matches[1])) {
            $indexToRemove = $matches[1];
            $lastIndex = array_pop($indexToRemove);
            foreach ($indexToRemove as $index) {
                if (isset($array[$index]) && is_array($array[$index])) {
                    $array = &$array[$index];
                } else {
                    // Element or index doesn't exist
                    return false;
                }
            }
            if (isset($array[$lastIndex])) {
                unset($array[$lastIndex]);
                return true;
            }
        }
        return false;
    }
测试demo
$multiArray = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];

unsetByIndex($multiArray, '1[1]');
print_r($multiArray);
//结果
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [1] => Array
        (
            [0] => 4
            [2] => 6
        )

    [2] => Array
        (
            [0] => 7
            [1] => 8
            [2] => 9
        )

)

docker decktop开始收费了,不过docker还是免费开源的. docker decktop做角色其实就是 虚拟机 + linux系统 + docker; 因为docker是利用linux内核来管理资源, 所以你的mac没法直接跑docker(mac系统是没有linux内核的). 因为docker还是免费开源,你自己搭建一个linux环境也是能直接使用docker的. 调研多种方案给出最推荐的方式.避免你选择困难症.
  1. 使用社区版
    推荐.除了没有像docker那样图形管理界面的能力,但其他都一样,要用时敲下命令是一样的.和docker一样,只要安装下安装包.
    社区版本下载地址
  2. 还有个不错的替代者: https://github.com/abiosoft/colima

注意: docker卸载后所有容器和镜像都会没掉,所以卸载前一定要记得备份
备份也很简单,步骤如下:

  1. Open Terminal on your Mac.
  2. In the Terminal window, type the following command to list all your Docker images:

    docker images
  3. Note the image ID or names of the images you want to keep.
  4. Type the following command to save the images to a .tar file:

    docker save -o /path/to/save/myimage.tar myimage

    Replace /path/to/save/ with the path to the directory where you want to save the .tar file, and myimage with the image name or ID you noted in step 3.

  5. Repeat step 4 for each image you want to save.
  6. Once you have saved all the images, you can uninstall Docker Desktop as you normally would.
  7. When you reinstall Docker Desktop, you can restore the saved images by typing the following commands:

    docker load -i /path/to/save/myimage.tar

    Replace /path/to/save/ with the path to the directory where you saved the .tar file, and myimage with the image name or ID you want to restore.
    Repeat this command for each saved image.