Skip to content

Commit

Permalink
Add Test : Progress + Escape
Browse files Browse the repository at this point in the history
Fix Binding : sort array
  • Loading branch information
isublimity committed Dec 22, 2017
1 parent 158aaba commit 2bbbd38
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
19 changes: 16 additions & 3 deletions src/Query/Degenerations/Bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,27 @@ public function bindParam($column, $value)
$this->bindings[$column] = $value;
}

private function escape($string)
{
// $non_displayables = array(
// '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
// '/%1[0-9a-f]/', // url encoded 16-31
// '/[\x00-\x08]/', // 00-08
// '/\x0b/', // 11
// '/\x0c/', // 12
// '/[\x0e-\x1f]/' // 14-31
// );
// foreach ( $non_displayables as $regex ) $data = preg_replace( $regex, '', $data );
return addslashes($string);

}
/**
* @param $sql
* @return mixed
*/
public function process($sql)
{
asort($this->bindings);

arsort($this->bindings);
foreach ($this->bindings as $key => $value) {
$valueSet = null;
$valueSetText = null;
Expand All @@ -61,7 +74,7 @@ public function process($sql)

if (is_string($value)) {
$valueSet = $value;
$valueSetText = "'" . addslashes($value) . "'";
$valueSetText = "'" . $this->escape($value) . "'";
}

if ($valueSetText !== null) {
Expand Down
3 changes: 2 additions & 1 deletion src/Transport/CurlerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,9 @@ public function setFunctionProgress(callable $callback)
if (!is_callable($callback)) {
throw new \Exception('setFunctionProgress not is_callable');
}

$this->option(CURLOPT_NOPROGRESS,false);
$this->option(CURLOPT_PROGRESSFUNCTION,$callback);
$this->option(CURLOPT_PROGRESSFUNCTION,$callback); // version 5.5.0
}


Expand Down
16 changes: 10 additions & 6 deletions tests/02_ProgressAndEscapeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,31 @@ public function testEscape()
$bind['k'.$z]=chr($z);
$select[]=":k{$z} as k{$z}";
}
arsort($bind);


$rows=$this->db->select("SELECT ".implode(",\n",$select),$bind)->rows();
print_r($rows);
$row=$rows[0];

for($z=10;$z<100;$z++) {
$this->assertArrayHasKey('k'.$z,$row);
$this->assertEquals(chr($z),$row['k'.$z]);

}


}

public function testProgressFunction()
{
global $resultTest;


$this->db->settings()->set('max_block_size', 1);
$this->setUp();
$this->db->settings()->set('max_block_size', 1);

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

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

0 comments on commit 2bbbd38

Please sign in to comment.