Skip to content

Commit 2bbbd38

Browse files
committed
Add Test : Progress + Escape
Fix Binding : sort array
1 parent 158aaba commit 2bbbd38

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/Query/Degenerations/Bindings.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,27 @@ public function bindParam($column, $value)
3333
$this->bindings[$column] = $value;
3434
}
3535

36+
private function escape($string)
37+
{
38+
// $non_displayables = array(
39+
// '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
40+
// '/%1[0-9a-f]/', // url encoded 16-31
41+
// '/[\x00-\x08]/', // 00-08
42+
// '/\x0b/', // 11
43+
// '/\x0c/', // 12
44+
// '/[\x0e-\x1f]/' // 14-31
45+
// );
46+
// foreach ( $non_displayables as $regex ) $data = preg_replace( $regex, '', $data );
47+
return addslashes($string);
48+
49+
}
3650
/**
3751
* @param $sql
3852
* @return mixed
3953
*/
4054
public function process($sql)
4155
{
42-
asort($this->bindings);
43-
56+
arsort($this->bindings);
4457
foreach ($this->bindings as $key => $value) {
4558
$valueSet = null;
4659
$valueSetText = null;
@@ -61,7 +74,7 @@ public function process($sql)
6174

6275
if (is_string($value)) {
6376
$valueSet = $value;
64-
$valueSetText = "'" . addslashes($value) . "'";
77+
$valueSetText = "'" . $this->escape($value) . "'";
6578
}
6679

6780
if ($valueSetText !== null) {

src/Transport/CurlerRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,9 @@ public function setFunctionProgress(callable $callback)
641641
if (!is_callable($callback)) {
642642
throw new \Exception('setFunctionProgress not is_callable');
643643
}
644+
644645
$this->option(CURLOPT_NOPROGRESS,false);
645-
$this->option(CURLOPT_PROGRESSFUNCTION,$callback);
646+
$this->option(CURLOPT_PROGRESSFUNCTION,$callback); // version 5.5.0
646647
}
647648

648649

tests/02_ProgressAndEscapeTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,31 @@ public function testEscape()
7676
$bind['k'.$z]=chr($z);
7777
$select[]=":k{$z} as k{$z}";
7878
}
79-
arsort($bind);
80-
8179

8280
$rows=$this->db->select("SELECT ".implode(",\n",$select),$bind)->rows();
83-
print_r($rows);
81+
$row=$rows[0];
82+
83+
for($z=10;$z<100;$z++) {
84+
$this->assertArrayHasKey('k'.$z,$row);
85+
$this->assertEquals(chr($z),$row['k'.$z]);
86+
87+
}
88+
8489

8590
}
8691

8792
public function testProgressFunction()
8893
{
8994
global $resultTest;
9095

91-
92-
$this->db->settings()->set('max_block_size', 1);
9396
$this->setUp();
97+
$this->db->settings()->set('max_block_size', 1);
9498

9599
$this->db->progressFunction(function ($data) {
96100
global $resultTest;
97101
$resultTest=$data;
98102
});
99-
$st=$this->db->select('SELECT number,sleep(0.2) FROM system.numbers limit 5');
103+
$st=$this->db->select('SELECT number,sleep(0.1) FROM system.numbers limit 4');
100104

101105
// read_rows + read_bytes + total_rows
102106
$this->assertArrayHasKey('read_rows',$resultTest);

0 commit comments

Comments
 (0)