Skip to content

Commit 754ba18

Browse files
committed
refactoring
1 parent 6d35fd2 commit 754ba18

30 files changed

+2603
-1601
lines changed

README.md

Lines changed: 163 additions & 118 deletions
Large diffs are not rendered by default.

example/exam10_settings.php

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,76 @@
11
<?php
2-
include_once __DIR__.'/../include.php';
32

3+
include_once __DIR__ . '/../include.php';
44

55

6-
$config=['host'=>'x','port'=>'8123','username'=>'x','password'=>'x','settings'=>['max_execution_time'=>100]];
7-
$db=new ClickHouseDB\Client($config);
8-
if ($db->settings()->getSetting('max_execution_time')!==100) throw new Exception("Bad work settings");
6+
$config = [
7+
'host' => 'x',
8+
'port' => '8123',
9+
'username' => 'x',
10+
'password' => 'x',
11+
'settings' => ['max_execution_time' => 100]
12+
];
913

14+
$db = new ClickHouseDB\Client($config);
15+
16+
if ($db->settings()->getSetting('max_execution_time') !== 100) {
17+
throw new Exception("Bad work settings");
18+
}
1019

1120

1221
// settings via constructor
13-
$config=['host'=>'x','port'=>'8123','username'=>'x','password'=>'x'];
14-
$db=new ClickHouseDB\Client($config,['max_execution_time'=>100]);
15-
if ($db->settings()->getSetting('max_execution_time')!==100) throw new Exception("Bad work settings");
22+
$config = [
23+
'host' => 'x',
24+
'port' => '8123',
25+
'username' => 'x',
26+
'password' => 'x'
27+
];
1628

29+
$db = new ClickHouseDB\Client($config, ['max_execution_time' => 100]);
1730

31+
if ($db->settings()->getSetting('max_execution_time') !== 100) {
32+
throw new Exception("Bad work settings");
33+
}
1834

19-
//
20-
$config=['host'=>'x','port'=>'8123','username'=>'x','password'=>'x'];
21-
$db=new ClickHouseDB\Client($config);
22-
$db->settings()->set('max_execution_time',100);
23-
if ($db->settings()->getSetting('max_execution_time')!==100) throw new Exception("Bad work settings");
2435

36+
// set method
37+
$config = [
38+
'host' => 'x',
39+
'port' => '8123',
40+
'username' => 'x',
41+
'password' => 'x'
42+
];
2543

44+
$db = new ClickHouseDB\Client($config);
45+
$db->settings()->set('max_execution_time', 100);
2646

27-
$config=['host'=>'x','port'=>'8123','username'=>'x','password'=>'x'];
28-
$db=new ClickHouseDB\Client($config);
29-
$db->settings()->apply(['max_execution_time'=>100,'max_block_size'=>12345]);
47+
if ($db->settings()->getSetting('max_execution_time') !== 100) {
48+
throw new Exception("Bad work settings");
49+
}
3050

3151

52+
// apply array method
53+
$config = [
54+
'host' => 'x',
55+
'port' => '8123',
56+
'username' => 'x',
57+
'password' => 'x'
58+
];
3259

33-
if ($db->settings()->getSetting('max_execution_time')!==100) throw new Exception("Bad work settings");
34-
if ($db->settings()->getSetting('max_block_size')!==12345) throw new Exception("Bad work settings");
60+
$db = new ClickHouseDB\Client($config);
61+
$db->settings()->apply([
62+
'max_execution_time' => 100,
63+
'max_block_size' => 12345
64+
]);
3565

3666

67+
if ($db->settings()->getSetting('max_execution_time') !== 100) {
68+
throw new Exception("Bad work settings");
69+
}
3770

71+
if ($db->settings()->getSetting('max_block_size') !== 12345) {
72+
throw new Exception("Bad work settings");
73+
}
3874

3975

40-
echo "getSetting - OK\n";
76+
echo "getSetting - OK\n";

example/exam11_errors.php

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,70 @@
11
<?php
2-
include_once __DIR__.'/../include.php';
32

3+
include_once __DIR__ . '/../include.php';
44

55

6-
$config=['host'=>'x','port'=>'8123','username'=>'x','password'=>'x'];
7-
$db=new ClickHouseDB\Client($config);
6+
$config = [
7+
'host' => 'x',
8+
'port' => '8123',
9+
'username' => 'x',
10+
'password' => 'x'
11+
];
812

9-
try
10-
{
13+
$db = new ClickHouseDB\Client($config);
14+
15+
try {
1116
$db->ping();
1217
}
13-
catch (ClickHouseDB\QueryException $E)
14-
{
15-
echo "ERROR:".$E->getMessage()."\nOK\n";
18+
catch (ClickHouseDB\QueryException $E) {
19+
echo "ERROR:" . $E->getMessage() . "\nOK\n";
1620
}
1721

1822

19-
$config=['host'=>'192.168.1.20','port'=>'8123','username'=>'x','password'=>'x'];
20-
$db=new ClickHouseDB\Client($config);
21-
try
22-
{
23+
// ------------------
24+
25+
26+
$config = [
27+
'host' => '192.168.1.20',
28+
'port' => '8123',
29+
'username' => 'x',
30+
'password' => 'x'
31+
];
32+
33+
$db = new ClickHouseDB\Client($config);
34+
35+
try {
2336
$db->ping();
2437
}
25-
catch (ClickHouseDB\QueryException $E)
26-
{
27-
echo "ERROR:".$E->getMessage()."\nOK\n";
38+
catch (ClickHouseDB\QueryException $E) {
39+
echo "ERROR:" . $E->getMessage() . "\nOK\n";
2840
}
2941

3042

31-
$config=['host'=>'192.168.1.20','port'=>'8123','username'=>'default','password'=>''];
32-
$db=new ClickHouseDB\Client($config);
33-
try
34-
{
43+
// ------------------
44+
45+
46+
$config = [
47+
'host' => '192.168.1.20',
48+
'port' => '8123',
49+
'username' => 'default',
50+
'password' => ''
51+
];
52+
53+
$db = new ClickHouseDB\Client($config);
54+
55+
try {
3556
$db->ping();
3657
echo "PING : OK!\n";
3758
}
38-
catch (ClickHouseDB\QueryException $E)
39-
{
40-
echo "ERROR:".$E->getMessage()."\nOK\n";
59+
catch (ClickHouseDB\QueryException $E) {
60+
echo "ERROR:" . $E->getMessage() . "\nOK\n";
4161
}
42-
try
43-
{
44-
$db->select("SELECT xxx as PPPP FROM ZZZZZ ")->rows();
4562

63+
try {
64+
$db->select("SELECT xxx as PPPP FROM ZZZZZ ")->rows();
4665
}
4766
catch (ClickHouseDB\DatabaseException $E) {
48-
echo "ERROR : DatabaseException : ".$E->getMessage()."\n"; // Table default.ZZZZZ doesn't exist.
67+
echo "ERROR : DatabaseException : " . $E->getMessage() . "\n"; // Table default.ZZZZZ doesn't exist.
4968
}
5069

5170
// ----------------------------

example/exam12_array.php

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,54 @@
11
<?php
2-
include_once __DIR__.'/../include.php';
3-
$config=['host'=>'192.168.1.20','port'=>'8123','username'=>'default','password'=>''];
4-
$db=new ClickHouseDB\Client($config);
2+
3+
include_once __DIR__ . '/../include.php';
4+
5+
$config = [
6+
'host' => '192.168.1.20',
7+
'port' => '8123',
8+
'username' => 'default',
9+
'password' => ''
10+
];
11+
12+
$db = new ClickHouseDB\Client($config);
513

614

715
$db->write("DROP TABLE IF EXISTS arrays_test");
8-
$res=$db->write('
9-
CREATE TABLE IF NOT EXISTS arrays_test
10-
(
11-
s_key String,
12-
s_arr Array(UInt8)
13-
) ENGINE = Memory
16+
17+
$res = $db->write('
18+
CREATE TABLE IF NOT EXISTS arrays_test (
19+
s_key String,
20+
s_arr Array(UInt8)
21+
) ENGINE = Memory
1422
');
23+
1524
//------------------------------------------------------------------------------
25+
26+
1627
echo "Insert\n";
17-
$stat=$db->insert('arrays_test',
18-
[
19-
['HASH1',[11,22,33]],
20-
['HASH1',[11,22,55]],
21-
]
22-
,
23-
['s_key','s_arr']
24-
);
28+
$stat = $db->insert('arrays_test', [
29+
['HASH1', [11, 22, 33]],
30+
['HASH1', [11, 22, 55]],
31+
], ['s_key', 's_arr']);
2532
echo "Insert Done\n";
2633

2734
print_r($db->select('SELECT s_key, s_arr FROM arrays_test ARRAY JOIN s_arr')->rows());
2835

36+
2937
$db->write("DROP TABLE IF EXISTS arrays_test_string");
30-
$res=$db->write('
31-
CREATE TABLE IF NOT EXISTS arrays_test_string
32-
(
33-
s_key String,
34-
s_arr Array(String)
35-
) ENGINE = Memory
38+
39+
$res = $db->write('
40+
CREATE TABLE IF NOT EXISTS arrays_test_string (
41+
s_key String,
42+
s_arr Array(String)
43+
) ENGINE = Memory
3644
');
45+
46+
3747
echo "Insert\n";
38-
$stat=$db->insert('arrays_test_string',
39-
[
40-
['HASH1',["a","dddd","xxx"]],
41-
['HASH1',["b'\tx"]],
42-
]
43-
,
44-
['s_key','s_arr']
45-
);
48+
$stat = $db->insert('arrays_test_string', [
49+
['HASH1', ["a", "dddd", "xxx"]],
50+
['HASH1', ["b'\tx"]],
51+
], ['s_key', 's_arr']);
4652
echo "Insert Done\n";
4753

4854

example/exam1_select.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
<?php
22

3-
include_once __DIR__.'/../include.php';
3+
include_once __DIR__ . '/../include.php';
44

5-
$config=['host'=>'192.168.1.20','port'=>'8123','username'=>'default','password'=>''];
5+
$config = [
6+
'host' => '192.168.1.20',
7+
'port' => '8123',
8+
'username' => 'default',
9+
'password' => ''
10+
];
611

7-
$db=new ClickHouseDB\Client($config);
12+
$db = new ClickHouseDB\Client($config);
813
//$db->verbose();
914
$db->settings()->readonly(false);
1015

1116

12-
$result=$db->select('SELECT 12 as {key} WHERE {key}=:value',['key'=>'ping','value'=>12]);
17+
$result = $db->select(
18+
'SELECT 12 as {key} WHERE {key} = :value',
19+
['key' => 'ping', 'value' => 12]
20+
);
1321

14-
if ($result->fetchOne('ping')!=12)
15-
{
22+
if ($result->fetchOne('ping') != 12) {
1623
echo "Error : ? \n";
1724
}
25+
1826
print_r($result->fetchOne());
27+
1928
// ---------------------------- ASYNC SELECT ----------------------------
20-
$state1=$db->selectAsync('SELECT 1 as {key} WHERE {key}=:value',['key'=>'ping','value'=>1]);
21-
$state2=$db->selectAsync('SELECT 2 as ping');
29+
$state1 = $db->selectAsync('SELECT 1 as {key} WHERE {key} = :value', ['key' => 'ping', 'value' => 1]);
30+
$state2 = $db->selectAsync('SELECT 2 as ping');
2231
$db->executeAsync();
32+
2333
print_r($state1->fetchOne());
2434
print_r($state1->rows());
2535
print_r($state2->fetchOne('ping'));
26-
27-
//----------------------------------------//----------------------------------------
28-
36+
//----------------------------------------//----------------------------------------

0 commit comments

Comments
 (0)