-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuery.cpp
More file actions
executable file
·53 lines (47 loc) · 1.92 KB
/
Query.cpp
File metadata and controls
executable file
·53 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Query.h"
// constructor from elements, given a direct SQL query string
Query::Query(zmq::message_t& client_id_in, zmq::message_t& msg_id_in, zmq::message_t& database_in, zmq::message_t& query_in, uint32_t query_ok_in, std::string response_in){
client_id.move(&client_id_in);
message_id.move(&msg_id_in);
// NOPE reinterpret_cast and copy construction doesn't work
//database = reinterpret_cast<const char*>(database_in.data());
// XXX instead use memcpy and trim
database.resize(database_in.size(),'\0');
memcpy((void*)database.data(),database_in.data(),database_in.size());
database = database.substr(0,database.find('\0'));
//query = reinterpret_cast<const char*>(query_in.data());
query.resize(query_in.size(),'\0');
memcpy((void*)query.data(),query_in.data(),query_in.size());
query = query.substr(0,query.find('\0'));
//std::cout<<"building query for db: '"<<database<<"', query_string: '"<<query<<"'"<<std::endl;
query_ok=query_ok_in;
if(response_in!="NULL"){
response = std::vector<std::string>{response_in};
}
retries=0;
recpt_time = boost::posix_time::microsec_clock::universal_time();
}
// copy constructor
Query::Query(const Query& in){
client_id.copy(&in.client_id);
message_id.copy(&in.message_id);
database = in.database;
query = in.query;
query_ok = in.query_ok;
response = in.response;
retries = in.retries;
recpt_time = in.recpt_time;
}
void Query::Print(){
std::string client(client_id.size(),'\0');
memcpy((void*)client.c_str(),client_id.data(),client_id.size());
uint32_t msgid;
memcpy(&msgid,message_id.data(),sizeof(msgid));
std::cout<<"query "<<msgid<<" from client "<<client<<": '"
<<query<<"', response '";
for(std::string& apart : response) std::cout<<"["<<apart<<"]";
std::cout<<"', sent "<<retries<<" times";
if(retries==0) std::cout<<". message received at ";
else std::cout<<" last send attempt at ";
std::cout<<to_simple_string(recpt_time)<<std::endl;
}