7
7
#include " SqlPrepare.h"
8
8
9
9
10
- int _main ()
10
+ void sql_query_1 ()
11
11
{
12
- DBInterfaceMysql mysql (" 127.0.0.1" , " jw_test" , " root" , " 1111 " );
12
+ DBInterfaceMysql mysql (" 127.0.0.1" , " jw_test" , " root" , " 111111 " );
13
13
mysql.connect ();
14
14
15
15
@@ -25,15 +25,14 @@ int _main()
25
25
result >> id;
26
26
result >> num;
27
27
result >> name;
28
- }
29
28
30
- system ( " pause " );
31
- return 0 ;
29
+ printf ( " id:%d, num:%d, name:%s \n " , id, num, name. c_str () );
30
+ }
32
31
}
33
32
34
33
#include " SqlResultSet.h"
35
34
36
- int __main ()
35
+ void sql_query_2 ()
37
36
{
38
37
DBInterfaceMysql mysql (" 127.0.0.1" , " jw_test" , " root" , " 111111" );
39
38
mysql.connect ();
@@ -43,25 +42,22 @@ int __main()
43
42
pre.pushInt32 (1 );
44
43
pre.prepare (mysql.mysql ());
45
44
46
- std::shared_ptr< SqlResultSet> result = std::make_shared<SqlResultSet>() ;
47
- pre.execute (result. get () );
45
+ SqlResultSet result;
46
+ pre.execute (& result);
48
47
49
- while (result-> fetch ())
48
+ while (result. fetch ())
50
49
{
51
- int id = result-> getInt32 ();
52
- int num = result-> getInt32 ();
53
- std::string name = result-> getString ();
50
+ int id = result. getInt32 ();
51
+ int num = result. getInt32 ();
52
+ std::string name = result. getString ();
54
53
55
54
printf (" id:%d, num:%d, name:%s\n " , id, num, name.c_str ());
56
55
}
57
-
58
- system (" pause" );
59
- return 0 ;
60
56
}
61
57
62
58
#include < functional>
63
59
#include " DBThreadPool.h"
64
- int main ()
60
+ void sql_query_3 ()
65
61
{
66
62
DBConfig config;
67
63
config.dbname = " jw_test" ;
@@ -101,7 +97,21 @@ int main()
101
97
Sleep (10 );
102
98
pool.update ();
103
99
}
100
+ }
101
+
102
+ #include < iostream>
103
+ int main ()
104
+ {
105
+ MySQL::libraryInit ();
106
+ MySQL::threadSafe ();
107
+
108
+ sql_query_1 ();
109
+ std::cout << " **************************************" << std::endl;
110
+ sql_query_2 ();
111
+ std::cout << " **************************************" << std::endl;
112
+ sql_query_3 ();
113
+
114
+ MySQL::libraryEnd ();
104
115
105
- system (" pause" );
106
116
return 0 ;
107
117
}
0 commit comments