Skip to content

Commit 45f134a

Browse files
authored
Merge pull request #2 from wsjcpp/version-0.2.0
Version 0.2.0
2 parents 78d6d38 + e8fd1f4 commit 45f134a

File tree

11 files changed

+1040
-277
lines changed

11 files changed

+1040
-277
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# wsjcpp-sql-builder Changelog
22

3+
## [v0.2.0] - 2026-01-31 (2026 Jan 31)
4+
5+
- Implemented a select, update, insert, delete with chain concept
6+
37
## [v0.1.0] - 2025-08-10 (2025 Aug 10)
48

59
- Added first implementation from fhq-server

README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,32 @@ Example main func:
2323
#include <wsjcpp_sql_builder.h>
2424

2525
int main(int argc, const char* argv[]) {
26-
WsjcppSqlBuilderInsert sql("TABLE_NAME");
27-
sql.add("COL1", "val1"); // will be escaped
28-
sql.add("COL2", 1);
29-
// sql.add("COL3", 1.1);
30-
if (!sql.isValid()) {
31-
std::cerr << "Something wrong with query: " << sql.getErrorMessage() << std::endl;
32-
return -1;
33-
}
34-
std::cout << sql.getTextQuery() << std::endl;
35-
return 0;
26+
wsjcpp::SqlBuilder builder;
27+
builder.selectFrom("table1")
28+
.colum("col1")
29+
.colum("col2", "c3")
30+
.colum("col3")
31+
.colum("col4")
32+
.where()
33+
.equal("col1", "1")
34+
.or_()
35+
.notEqual("col2", "2")
36+
.or_()
37+
.subCondition()
38+
.equal("c3", "4")
39+
// .and_() // be default must be added and
40+
.equal("col2", "5")
41+
.finishSubCondition()
42+
.or_()
43+
.lessThen("col4", 111)
44+
.endWhere() // need only for groupBy havingBy and etc
45+
;
46+
std::cout << builder.sql() << std::endl;
3647
}
3748
```
3849
3950
Example output:
4051
```
4152
$ ./wsjcpp-sql-builder
42-
INSERT INTO TABLE_NAME(COL1, COL2) VALUES ('val1', 1);
53+
SELECT col1, col2 AS c3, col3, col4 FROM table1 WHERE col1 = '1' OR col2 <> '2' OR (c3 = '4' AND col2 = '5') OR col4 < 111
4354
```

src.wsjcpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Automaticly generated by wsjcpp@v0.2.5
1+
# Automaticly generated by wsjcpp@v0.2.7
22
cmake_minimum_required(VERSION 3.0)
33

4-
add_definitions(-DWSJCPP_APP_VERSION="v0.1.0")
4+
add_definitions(-DWSJCPP_APP_VERSION="v0.2.0")
55
add_definitions(-DWSJCPP_APP_NAME="wsjcpp-sql-builder")
66

77
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

src/main.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
#include <wsjcpp_sql_builder.h>
33

44
int main(int argc, const char* argv[]) {
5-
WsjcppSqlBuilderInsert sql("TABLE_NAME");
6-
sql.add("COL1", "val1"); // will be escaped
7-
sql.add("COL2", 1);
8-
// sql.add("COL3", 1.1);
9-
if (!sql.isValid()) {
10-
std::cerr << "Something wrong with query: " << sql.getErrorMessage() << std::endl;
11-
return -1;
12-
}
5+
// WsjcppSqlBuilderInsert sql("TABLE_NAME");
6+
// sql.add("COL1", "val1"); // will be escaped
7+
// sql.add("COL2", 1);
8+
// // sql.add("COL3", 1.1);
9+
// if (!sql.isValid()) {
10+
// std::cerr << "Something wrong with query: " << sql.getErrorMessage() << std::endl;
11+
// return -1;
12+
// }
1313

14-
std::string expectedIns = "INSERT INTO TABLE_NAME(COL1, COL2) VALUES ('val1', 1);";
15-
if (expectedIns != sql.getTextQuery()) {
16-
std::cerr << "Expeceted sql: " << expectedIns << ", but got " << sql.getTextQuery() << std::endl;
17-
return -1;
18-
}
19-
std::cout << sql.getTextQuery() << std::endl;
14+
// std::string expectedIns = "INSERT INTO TABLE_NAME(COL1, COL2) VALUES ('val1', 1);";
15+
// if (expectedIns != sql.getTextQuery()) {
16+
// std::cerr << "Expeceted sql: " << expectedIns << ", but got " << sql.getTextQuery() << std::endl;
17+
// return -1;
18+
// }
19+
// std::cout << sql.getTextQuery() << std::endl;
2020

2121
return 0;
2222
}

src/tests/test_delete.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**********************************************************************************
2+
* MIT License
3+
*
4+
* Copyright (c) 2025-2026 Evgenii Sopov <mrseakg@gmail.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
*all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
* Official Source Code: https://github.com/wsjcpp/wsjcpp-sql-builder
25+
*
26+
***********************************************************************************/
27+
28+
#include <iostream>
29+
#include <wsjcpp_sql_builder.h>
30+
31+
int main() {
32+
wsjcpp::SqlBuilder builder;
33+
builder.deleteFrom("table4")
34+
.where()
35+
.equal("col1", "1")
36+
.or_()
37+
.notEqual("col2", "2")
38+
.or_()
39+
.subCondition()
40+
.equal("c3", "4")
41+
// .and_() // be default must be added and
42+
.equal("col2", "5")
43+
.finishSubCondition()
44+
.or_()
45+
.lessThen("col4", 111)
46+
;
47+
48+
if (builder.hasErrors()) {
49+
std::cerr << "Select builder has some errors" << std::endl;
50+
return -1;
51+
}
52+
std::string sqlQuery = builder.sql();
53+
std::string sqlQueryExpected = "DELETE FROM table4 WHERE col1 = '1' OR col2 <> '2' OR (c3 = '4' AND col2 = '5') OR col4 < 111";
54+
if (sqlQuery != sqlQueryExpected) {
55+
std::cerr
56+
<< "Expected:" << std::endl
57+
<< " {" << sqlQueryExpected << "}" << std::endl
58+
<< ", but got:" << std::endl
59+
<< " {" << sqlQuery << "}" << std::endl
60+
;
61+
return -1;
62+
}
63+
64+
return 0;
65+
}

src/tests/test_insert.cpp

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,49 @@
2929
#include <wsjcpp_sql_builder.h>
3030

3131
int main() {
32-
WsjcppSqlBuilderInsert sql("TABLE_NAME");
33-
sql.add("COL1", "val1"); // will be escaped
34-
sql.add("COL2", 1);
35-
// sql.add("COL3", 1.1);
36-
if (!sql.isValid()) {
37-
std::cerr << "Something wrong with query: " << sql.getErrorMessage() << std::endl;
38-
return -1;
39-
}
40-
if (sql.getTextQuery() != "INSERT INTO TABLE_NAME(COL1, COL2) VALUES ('val1', 1);") {
41-
return -1;
42-
}
43-
return 0;
32+
wsjcpp::SqlBuilder builder;
33+
builder.insertInto("table2")
34+
.colum("col1")
35+
.addColums({"col2", "col3"})
36+
.val("val1")
37+
.val(1)
38+
.val(2.0)
39+
;
40+
41+
if (builder.hasErrors()) {
42+
std::cerr << "Select builder has some errors" << std::endl;
43+
return -1;
44+
}
45+
std::string sqlQuery = builder.sql();
46+
std::string sqlQueryExpected = "INSERT INTO table2(col1, col2, col3) VALUES('val1', 1, 2.000000)";
47+
if (sqlQuery != sqlQueryExpected) {
48+
std::cerr
49+
<< "Expected:" << std::endl
50+
<< " {" << sqlQueryExpected << "}" << std::endl
51+
<< ", but got:" << std::endl
52+
<< " {" << sqlQuery << "}" << std::endl
53+
;
54+
return -1;
55+
}
56+
57+
builder.findInsertOrCreate("table2")
58+
.clearValues()
59+
.val("val2")
60+
.val(2)
61+
.val(10.0)
62+
;
63+
64+
sqlQuery = builder.sql();
65+
sqlQueryExpected = "INSERT INTO table2(col1, col2, col3) VALUES('val2', 2, 10.000000)";
66+
if (sqlQuery != sqlQueryExpected) {
67+
std::cerr
68+
<< "Expected:" << std::endl
69+
<< " {" << sqlQueryExpected << "}" << std::endl
70+
<< ", but got:" << std::endl
71+
<< " {" << sqlQuery << "}" << std::endl
72+
;
73+
return -1;
74+
}
75+
76+
return 0;
4477
}

src/tests/test_select.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**********************************************************************************
2+
* MIT License
3+
*
4+
* Copyright (c) 2025-2026 Evgenii Sopov <mrseakg@gmail.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
*all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
* Official Source Code: https://github.com/wsjcpp/wsjcpp-sql-builder
25+
*
26+
***********************************************************************************/
27+
28+
#include <iostream>
29+
#include <wsjcpp_sql_builder.h>
30+
31+
int main() {
32+
wsjcpp::SqlBuilder builder;
33+
builder.selectFrom("table1")
34+
.colum("col1")
35+
.colum("col2", "c3")
36+
.colum("col3")
37+
.colum("col4")
38+
.where()
39+
.equal("col1", "1")
40+
.or_()
41+
.notEqual("col2", "2")
42+
.or_()
43+
.subCondition()
44+
.equal("c3", "4")
45+
// .and_() // be default must be added and
46+
.equal("col2", "5")
47+
.finishSubCondition()
48+
.or_()
49+
.lessThen("col4", 111)
50+
.endWhere() // need only for groupBy havingBy and etc
51+
;
52+
if (builder.hasErrors()) {
53+
std::cerr << "Select builder has some errors" << std::endl;
54+
return -1;
55+
}
56+
std::string sqlQuery = builder.sql();
57+
std::string sqlQueryExpected =
58+
"SELECT col1, col2 AS c3, col3, col4 "
59+
"FROM table1 "
60+
"WHERE col1 = '1' OR col2 <> '2' OR (c3 = '4' AND col2 = '5') OR col4 < 111";
61+
if (sqlQuery != sqlQueryExpected) {
62+
std::cerr
63+
<< "Expected:" << std::endl
64+
<< " " << sqlQueryExpected << std::endl
65+
<< ", but got:" << std::endl
66+
<< " " << sqlQuery << std::endl
67+
;
68+
return -1;
69+
}
70+
71+
builder.clear();
72+
sqlQuery = builder.sql();
73+
if (sqlQuery != "") {
74+
std::cerr
75+
<< "Expected empty, but got: " << std::endl
76+
<< " " << sqlQuery << std::endl
77+
;
78+
return -1;
79+
}
80+
81+
return 0;
82+
}

src/tests/test_update.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**********************************************************************************
2+
* MIT License
3+
*
4+
* Copyright (c) 2025-2026 Evgenii Sopov <mrseakg@gmail.com>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
*all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
* Official Source Code: https://github.com/wsjcpp/wsjcpp-sql-builder
25+
*
26+
***********************************************************************************/
27+
28+
#include <iostream>
29+
#include <wsjcpp_sql_builder.h>
30+
31+
int main() {
32+
wsjcpp::SqlBuilder builder;
33+
builder.update("table3")
34+
.set("col1", "val uuu")
35+
.set("col2", 1)
36+
.set("col3", 1.000)
37+
.where()
38+
.equal("col1", "1")
39+
.or_()
40+
.notEqual("col2", "2")
41+
.or_()
42+
.subCondition()
43+
.equal("c3", "4")
44+
// .and_() // be default must be added and
45+
.equal("col2", "5")
46+
.finishSubCondition()
47+
.or_()
48+
.lessThen("col4", 111)
49+
;
50+
51+
if (builder.hasErrors()) {
52+
std::cerr << "Select builder has some errors" << std::endl;
53+
return -1;
54+
}
55+
std::string sqlQuery = builder.sql();
56+
std::string sqlQueryExpected = "UPDATE table3 SET col1 = 'val uuu', col2 = 1, col3 = 1.000000 WHERE col1 = '1' OR col2 <> '2' OR (c3 = '4' AND col2 = '5') OR col4 < 111";
57+
if (sqlQuery != sqlQueryExpected) {
58+
std::cerr
59+
<< "Expected:" << std::endl
60+
<< " {" << sqlQueryExpected << "}" << std::endl
61+
<< ", but got:" << std::endl
62+
<< " {" << sqlQuery << "}" << std::endl
63+
;
64+
return -1;
65+
}
66+
67+
return 0;
68+
}

0 commit comments

Comments
 (0)