Skip to content

Commit 840e3d8

Browse files
committed
增删改查msg
1 parent 1dbdb3e commit 840e3d8

5 files changed

Lines changed: 497 additions & 2 deletions

File tree

‎httpserver/compile.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
g++ -Wall ./src/main.cpp ./libs/*.a ./libs/*.so -I /usr/include/mysql -o ./output/httpserver -lpthread
1+
g++ -Wall ./src/ucenter.cpp ./libs/*.a ./libs/*.so -I /usr/include/mysql -o ./output/httpserver -lpthread

‎httpserver/compile.sh~‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎httpserver/output/httpserver‎

28.2 KB
Binary file not shown.

‎httpserver/src/main.cpp‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../include/mysql++.h"
1111
#include "../include/StreamResponse.h"
1212
#include "../include/options.h"
13+
#include "../include/row.h"
1314
//#include <tchar.h>
1415

1516
using namespace std;
@@ -124,11 +125,57 @@ class MyController : public WebController
124125
}
125126
};
126127

128+
void login(Request &request,StreamResponse &response) {
129+
string body = request.getData();
130+
cout << "body = " << body << endl;
131+
Json::Reader reader;
132+
Json::Value value;
133+
134+
if (reader.parse(body,value)) {
135+
string username = value["username"].asString();
136+
string passwd = value["passwd"].asString();
137+
138+
cout << "username = " << username << endl;
139+
cout << "passwd = " << passwd << endl;
140+
141+
Connection conn = Connection(false);
142+
conn.set_option(new SetCharsetNameOption("utf8"));
143+
conn.connect("cpp","127.0.0.1","root","root");
144+
145+
string sql = "select count(*) from t_user where username = '" + username + "' and passwd = '" + passwd + "'";
146+
cout << "sql = " << sql << endl;
147+
Query query = conn.query();
148+
query << sql;
149+
StoreQueryResult result = query.store();
150+
//mysqlpp::StoreQueryResult::list_type::size_type r = result.num_rows();
151+
// Row row = result.fetch_row();
152+
// Row::const_reference count = row.at(0);
153+
//cout << "count = " << count << endl;
154+
//string field_name = result.field_name(0);
155+
//cout << "field_name = " << field_name << endl;
156+
// Row row = result.fetch_row();
157+
// cout << row.begin() << endl;
158+
StoreQueryResult::const_iterator it = result.begin();
159+
160+
Row row = *it;
161+
if (it != result.end()) {
162+
if (row[0]) {
163+
response << "0" << endl;
164+
} else {
165+
response << "1" << endl;
166+
}
167+
//cout << "cout = " << row[0] << endl;
168+
}
169+
// cout << "count = " << *it[0] << endl;
170+
}
171+
}
172+
127173
void setup()
128174
{
129175
// addRoute("GET", "/hello", MyController, hello);
130176
addRoute("POST","/hello",MyController,hello);
131177
addRoute("POST","/reg",MyController,reg);
178+
addRoute("POST","/login",MyController,login);
132179
}
133180

134181

0 commit comments

Comments
 (0)