Skip to content

Commit 3981129

Browse files
committed
Correct example codes
1 parent 9782b5c commit 3981129

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

README.md

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,52 @@ $ make
3434
## Example
3535

3636
```cpp
37+
#include <iostream>
3738
#include <clickhouse/client.h>
3839

3940
using namespace clickhouse;
4041

41-
/// Initialize client connection.
42-
Client client(ClientOptions().SetHost("localhost"));
42+
int main()
43+
{
44+
/// Initialize client connection.
45+
Client client(ClientOptions().SetHost("localhost"));
4346

44-
/// Create a table.
45-
client.Execute("CREATE TABLE IF NOT EXISTS test.numbers (id UInt64, name String) ENGINE = Memory");
47+
/// Create a table.
48+
client.Execute("CREATE TABLE IF NOT EXISTS default.numbers (id UInt64, name String) ENGINE = Memory");
4649

47-
/// Insert some values.
48-
{
49-
Block block;
50+
/// Insert some values.
51+
{
52+
Block block;
5053

51-
auto id = std::make_shared<ColumnUInt64>();
52-
id->Append(1);
53-
id->Append(7);
54+
auto id = std::make_shared<ColumnUInt64>();
55+
id->Append(1);
56+
id->Append(7);
5457

55-
auto name = std::make_shared<ColumnString>();
56-
name->Append("one");
57-
name->Append("seven");
58+
auto name = std::make_shared<ColumnString>();
59+
name->Append("one");
60+
name->Append("seven");
5861

59-
block.AppendColumn("id" , id);
60-
block.AppendColumn("name", name);
62+
block.AppendColumn("id" , id);
63+
block.AppendColumn("name", name);
6164

62-
client.Insert("test.numbers", block);
63-
}
65+
client.Insert("default.numbers", block);
66+
}
6467

65-
/// Select values inserted in the previous step.
66-
client.Select("SELECT id, name FROM test.numbers", [] (const Block& block)
67-
{
68-
for (size_t i = 0; i < block.GetRowCount(); ++i) {
69-
std::cout << block[0]->As<ColumnUInt64>()->At(i) << " "
70-
<< block[1]->As<ColumnString>()->At(i) << "\n";
68+
/// Select values inserted in the previous step.
69+
client.Select("SELECT id, name FROM default.numbers", [] (const Block& block)
70+
{
71+
for (size_t i = 0; i < block.GetRowCount(); ++i) {
72+
std::cout << block[0]->As<ColumnUInt64>()->At(i) << " "
73+
<< block[1]->As<ColumnString>()->At(i) << "\n";
74+
}
7175
}
72-
}
73-
);
76+
);
7477

75-
/// Delete table.
76-
client.Execute("DROP TABLE test.numbers");
78+
/// Delete table.
79+
client.Execute("DROP TABLE default.numbers");
80+
81+
return 0;
82+
}
7783
```
7884

7985
## Thread-safety

0 commit comments

Comments
 (0)