Skip to content

Commit

Permalink
1.新增对于 int64, double, float 等类型支持; 2.修复了ps析构函数空指针问题;
Browse files Browse the repository at this point in the history
  • Loading branch information
garinyang committed Nov 6, 2022
1 parent e3eb7a4 commit 3d2d58d
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 214 deletions.
12 changes: 10 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified cmake-build-debug/.ninja_deps
Binary file not shown.
145 changes: 48 additions & 97 deletions cmake-build-debug/.ninja_log
Original file line number Diff line number Diff line change
@@ -1,101 +1,52 @@
# ninja log v5
5 36 1667486167355511033 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
5 1334 1667489778500339704 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
5 963 1667486168278549556 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
0 7 0 clean 3c8e6cc385ee00ba
1335 1412 1667489778580809598 cppbatis 5db4811c4c2804bf
0 79 1667483628383232137 build.ninja ab60c880bfc84404
4 1337 1667489820472426425 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
1337 1424 1667489820564252690 cppbatis 5db4811c4c2804bf
3 964 1667489885104328320 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
964 1033 1667489885177042224 cppbatis 5db4811c4c2804bf
4 950 1667490078695105886 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
951 1021 1667490078768435154 cppbatis 5db4811c4c2804bf
3 686 1667490113800012402 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
686 742 1667490113857682258 cppbatis 5db4811c4c2804bf
3 1084 1667490248502575246 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
1084 1189 1667490248614824381 cppbatis 5db4811c4c2804bf
4 1157 1667490584788608149 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
1158 1220 1667490584854102763 cppbatis 5db4811c4c2804bf
5 1580 1667490643039251521 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
1580 1703 1667490643171175714 cppbatis 5db4811c4c2804bf
4 1163 1667490657858294973 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
1163 1240 1667490657938202177 cppbatis 5db4811c4c2804bf
3 676 1667490671798478084 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
676 727 1667490671851801761 cppbatis 5db4811c4c2804bf
4 851 1667490696789135149 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
851 912 1667490696853426147 cppbatis 5db4811c4c2804bf
4 839 1667490719042376043 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
839 946 1667490719152526544 cppbatis 5db4811c4c2804bf
4 655 1667490731874829073 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
655 705 1667490731927950576 cppbatis 5db4811c4c2804bf
4 658 1667490740268371522 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
658 704 1667490740316916271 cppbatis 5db4811c4c2804bf
3 649 1667490746361224217 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
650 695 1667490746408833774 cppbatis 5db4811c4c2804bf
3 715 1667490762871553206 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
715 776 1667490762937253846 cppbatis 5db4811c4c2804bf
3 627 1667490814159685755 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
628 678 1667490814212677978 cppbatis 5db4811c4c2804bf
3 667 1667490836877055398 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
667 718 1667490836929695211 cppbatis 5db4811c4c2804bf
3 676 1667490860387285741 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
676 725 1667490860438865179 cppbatis 5db4811c4c2804bf
3 683 1667490877359122571 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
684 733 1667490877410744339 cppbatis 5db4811c4c2804bf
3 636 1667490882279778063 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
636 681 1667490882327547233 cppbatis 5db4811c4c2804bf
3 683 1667490913366611373 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
683 732 1667490913418514196 cppbatis 5db4811c4c2804bf
4 665 1667490924035724771 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
665 715 1667490924088225793 cppbatis 5db4811c4c2804bf
4 940 1667490953428392558 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
941 1034 1667490953526001473 cppbatis 5db4811c4c2804bf
3 1292 1667490988289078522 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
1293 1393 1667490988394647308 cppbatis 5db4811c4c2804bf
3 685 1667490997546595112 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
685 730 1667490997593815554 cppbatis 5db4811c4c2804bf
3 662 1667491006543541644 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
662 707 1667491006591258619 cppbatis 5db4811c4c2804bf
1 10 0 clean 3c8e6cc385ee00ba
4 777 1667491797716712491 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
3 963 1667491797904226567 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
0 7 0 clean 3c8e6cc385ee00ba
4 789 1667491933816530446 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
5 1098 1667491934130334399 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
4 1122 1667491934153786742 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
0 6 0 clean 3c8e6cc385ee00ba
5 800 1667492020382032109 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
5 1206 1667492020788665646 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
4 1233 1667492020814872559 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
0 6 0 clean 3c8e6cc385ee00ba
3 898 1667492109606082389 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
0 7 0 clean 3c8e6cc385ee00ba
4 786 1667492140384727571 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
4 1209 1667492140804534460 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
3 1210 1667492140805268832 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
0 6 0 clean 3c8e6cc385ee00ba
4 571 1667492218162961954 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
4 893 1667492218487566854 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
1278 1442 1667702267164256702 cppbatis 5db4811c4c2804bf
0 7 0 clean 3c8e6cc385ee00ba
4 585 1667492271338419095 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
4 1005 1667492271770024343 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
4 1057 1667492271820948925 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
1057 1137 1667492271905848048 cppbatis 5db4811c4c2804bf
4 768 1667492287600440533 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
768 820 1667492287654826515 cppbatis 5db4811c4c2804bf
4 617 1667492304981639081 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
617 668 1667492305034879902 cppbatis 5db4811c4c2804bf
3 624 1667492317693748889 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
624 674 1667492317745903049 cppbatis 5db4811c4c2804bf
3 1140 1667492449127287060 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
3 1176 1667492449165108957 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
1176 1272 1667492449265089590 cppbatis 5db4811c4c2804bf
3 584 1667492461267254865 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
585 635 1667492461320246687 cppbatis 5db4811c4c2804bf
3 575 1667492465961355369 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
576 622 1667492466010111170 cppbatis 5db4811c4c2804bf
4 1074 1667492564173186802 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
4 1118 1667492564217144537 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
1118 1229 1667492564333253573 cppbatis 5db4811c4c2804bf
5 1278 1667702266996432176 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
6 905 1667702266623964849 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
6 1240 1667702266953342172 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
7 437 1667702399223275777 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
437 487 1667702399275541715 cppbatis 5db4811c4c2804bf
3 428 1667702707034123193 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
428 479 1667702707087485572 cppbatis 5db4811c4c2804bf
4 433 1667702723018936461 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
434 484 1667702723070638407 cppbatis 5db4811c4c2804bf
3 389 1667702819798267859 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
389 439 1667702819850616795 cppbatis 5db4811c4c2804bf
3 487 1667703044333490711 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
487 545 1667703044393474532 cppbatis 5db4811c4c2804bf
4 589 1667703248245331199 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
3 629 1667703318326378459 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
3 691 1667703343087957408 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
691 753 1667703343151669675 cppbatis 5db4811c4c2804bf
4 431 1667703399655040527 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
431 478 1667703399703663876 cppbatis 5db4811c4c2804bf
3 370 1667703413895173726 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
370 417 1667703413943778283 cppbatis 5db4811c4c2804bf
4 371 1667703426167730194 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
372 420 1667703426218367850 cppbatis 5db4811c4c2804bf
3 595 1667703539533086400 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
595 658 1667703539598046489 cppbatis 5db4811c4c2804bf
3 424 1667703565420797469 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
425 475 1667703565473395794 cppbatis 5db4811c4c2804bf
3 387 1667703574277290926 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
387 434 1667703574325852891 cppbatis 5db4811c4c2804bf
4 628 1667703864079263076 CMakeFiles/cppbatis.dir/connection/connection.cpp.o 31231f150a53e866
4 834 1667703864286058445 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
4 868 1667703864319638228 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
868 946 1667703864400911185 cppbatis 5db4811c4c2804bf
3 615 1667703915172014656 CMakeFiles/cppbatis.dir/prepare_stmt/prepare_stmt.cpp.o a2fd2d0d81c1324e
616 672 1667703915230715904 cppbatis 5db4811c4c2804bf
3 671 1667703928796461906 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
671 724 1667703928851730938 cppbatis 5db4811c4c2804bf
3 596 1667703934556262786 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
596 643 1667703934605684713 cppbatis 5db4811c4c2804bf
4 608 1667703949652499048 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
608 655 1667703949701589074 cppbatis 5db4811c4c2804bf
3 631 1667704202757046486 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
631 685 1667704202812746540 cppbatis 5db4811c4c2804bf
3 649 1667704250791562019 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
649 703 1667704250847553726 cppbatis 5db4811c4c2804bf
4 637 1667704298164455598 CMakeFiles/cppbatis.dir/main.cpp.o 217d189bce8bacad
637 692 1667704298221810491 cppbatis 5db4811c4c2804bf
0 7 0 clean 3c8e6cc385ee00ba
4 changes: 2 additions & 2 deletions cmake-build-debug/Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Start testing: Nov 04 00:22 CST
Start testing: Nov 06 11:12 CST
----------------------------------------------------------
End testing: Nov 04 00:22 CST
End testing: Nov 06 11:12 CST
24 changes: 10 additions & 14 deletions connection/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,35 @@ Connection::Connection() {
// std::cout << ">>> construct connection" << std::endl;

// init
mysql_ = mysql_init(nullptr);

// connect (配置化)
mysql_ = mysql_real_connect(mysql_,
mysql_init(&mysql_);
auto res = mysql_real_connect(&mysql_,
"127.0.0.1",
"root",
"root",
"cppbatis",
3306,
nullptr,
0);
if (!mysql_) {
fprintf(stderr, "mysql_real_connect failed, error:%s\n", mysql_error(mysql_));
if (!res) {
fprintf(stderr, "mysql_real_connect failed, error_no:%d, err_info:%s\n",
mysql_errno(&mysql_), mysql_error(&mysql_));
exit(0); // 数据库异常中断
}

// 设置字符集
if (mysql_set_character_set(mysql_, "utf8")) {
fprintf(stderr, "mysql_set_character_set failed, error:%s\n", mysql_error(mysql_));
if (mysql_set_character_set(&mysql_, "utf8")) {
fprintf(stderr, "mysql_set_character_set failed, error:%s\n", mysql_error(&mysql_));
}
}


Connection::~Connection() {

// std::cout << ">>> construct connection" << std::endl;

if (mysql_) {
mysql_close(mysql_);
}
mysql_close(&mysql_);
}


MYSQL* Connection::GetMysqlInstance() {
MYSQL& Connection::GetMysqlInstance() {
return mysql_;
}

4 changes: 2 additions & 2 deletions connection/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Connection {

~Connection();

MYSQL* GetMysqlInstance();
MYSQL& GetMysqlInstance();

private:

Expand All @@ -26,7 +26,7 @@ class Connection {
std::string user;
std::string passwd;

MYSQL* mysql_;
MYSQL mysql_; // mysql 连接对象

};

Expand Down
13 changes: 9 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "data_struct/test.h"
#include <mysql/mysql.h>
#include <memory>
#include <string.h>
#include <sstream>

int main() {

Expand All @@ -39,10 +37,10 @@ int main() {
ps->Prepare(ss.str());

// 设置 where 条件 & 绑定
long limit_age = 19;
long limit_age = 16;
ps->SetInt(0, limit_age );
std::string name = "张三";
ps->SetString(1, name);
//ps->SetString(1, name);
// 绑定参数
ps->BindParam();

Expand All @@ -56,6 +54,13 @@ int main() {
// 查询结果处理(打印)
for (const auto user : users) {
printf("## %d,%s,%s,%d ##\n", user.id, user.name.data(), user.email.data(), user.age);

// easy_json 目前对于中文支持有点问题
// Json::FastWriter fw;
// Json::Value js_user;
// user.marshal(js_user);
// auto u = fw.write(js_user);
// printf("-> %s", u.c_str());
}

// 关闭prepare statement
Expand Down
Loading

0 comments on commit 3d2d58d

Please sign in to comment.