Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mysql client prepare field type identification #4238

Merged
merged 4 commits into from
May 26, 2021

Conversation

Yurunsoft
Copy link
Member

This problem may also affect the operation of JSON fields, resulting in values in JSON being strings

<?php

use Swoole\Coroutine\MySQL;
use function Swoole\Coroutine\run;

run(function () {
    $db = new MySQL();
    var_dump($db->connect([
        'host'     => '127.0.0.1',
        'port'     => 3306,
        'user'     => 'root',
        'password' => 'root',
        'database' => 'db_imi_test',
    ]));
    $stmt = $db->prepare('select ? as a, ? as b, ? as c, ? as d, ? + ? as e');
    if (false == $stmt)
    {
        var_dump($db->errno, $db->error);

        return;
    }
    else
    {
        $ret2 = $stmt->execute([123, 3.14, true, false, 11, 22]);
        var_dump($ret2);
    }
});

wrong:

bool(true)
array(1) {
  [0]=>
  array(5) {
    ["a"]=>
    string(3) "123"
    ["b"]=>
    string(4) "3.14"
    ["c"]=>
    string(1) "1"
    ["d"]=>
    string(0) ""
    ["e"]=>
    float(33)
  }
}

right:

bool(true)
array(1) {
  [0]=>
  array(5) {
    ["a"]=>
    int(123)
    ["b"]=>
    float(3.14)
    ["c"]=>
    int(1)
    ["d"]=>
    int(0)
    ["e"]=>
    int(33)
  }
}

@codecov
Copy link

codecov bot commented May 25, 2021

Codecov Report

Merging #4238 (1aa7c88) into master (7501396) will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4238      +/-   ##
==========================================
+ Coverage   50.76%   50.78%   +0.02%     
==========================================
  Files          70       70              
  Lines       14098    14098              
==========================================
+ Hits         7157     7160       +3     
+ Misses       6941     6938       -3     
Impacted Files Coverage Δ
src/os/wait.cc 74.11% <0.00%> (-7.06%) ⬇️
src/core/channel.cc 70.87% <0.00%> (-0.98%) ⬇️
src/network/client.cc 46.64% <0.00%> (-0.45%) ⬇️
src/server/port.cc 50.00% <0.00%> (-0.28%) ⬇️
src/os/async_thread.cc 70.17% <0.00%> (+0.43%) ⬆️
src/os/process_pool.cc 57.89% <0.00%> (+2.97%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7501396...1aa7c88. Read the comment docs.

@matyhtf matyhtf merged commit e4caad2 into swoole:master May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants