diff --git a/a8/mysql.cc b/a8/mysql.cc index 1aefde4..8fc4550 100644 --- a/a8/mysql.cc +++ b/a8/mysql.cc @@ -80,7 +80,7 @@ namespace a8 impl_->passwd.c_str(), impl_->database.c_str(), impl_->port, - NULL, + nullptr, 0); } @@ -102,6 +102,31 @@ namespace a8 return new Query(impl_); } + std::string Connection::GetHost() + { + return impl_->host; + } + + int Connection::GetPort() + { + return impl_->port; + } + + std::string Connection::GetUser() + { + return impl_->username; + } + + std::string Connection::GetPasswd() + { + return impl_->passwd; + } + + std::string Connection::GetDataBase() + { + return impl_->database; + } + Query::Query(a8::mysql::ConnectionImpl* conn_impl) { impl_ = new QueryImpl(); diff --git a/a8/mysql.h b/a8/mysql.h index 2299d06..925cd65 100644 --- a/a8/mysql.h +++ b/a8/mysql.h @@ -23,6 +23,12 @@ namespace a8 std::string GetError(); a8::mysql::Query* CreateQuery(); + std::string GetHost(); + int GetPort(); + std::string GetUser(); + std::string GetPasswd(); + std::string GetDataBase(); + private: a8::mysql::ConnectionImpl* impl_ = nullptr; }; diff --git a/a8/xobject.cc b/a8/xobject.cc index de15fff..f875197 100644 --- a/a8/xobject.cc +++ b/a8/xobject.cc @@ -64,6 +64,68 @@ namespace a8 } } + void XObject::Reset() + { + switch (type_) { + case a8::XOT_SIMPLE: + { + } + break; + case a8::XOT_ARRAY: + { + delete value_.array_value; + type_ = XOT_SIMPLE; + value_.x_value = new a8::XValue(); + } + break; + case a8::XOT_OBJECT: + { + delete value_.object_value; + type_ = XOT_SIMPLE; + value_.x_value = new a8::XValue(); + } + break; + default: + abort(); + } + } + + void XObject::DeepCopy(a8::XObject& to) + { + to.Reset(); + switch (type_) { + case a8::XOT_SIMPLE: + { + value_.x_value->DeepCopy(*to.value_.x_value); + } + break; + case a8::XOT_ARRAY: + { + type_ = XOT_ARRAY; + value_.array_value = new std::vector>(); + for (auto& value : *value_.array_value) { + std::shared_ptr xobj_ptr = std::make_shared(); + value->DeepCopy(*xobj_ptr.get()); + value_.array_value->push_back(xobj_ptr); + } + } + break; + case a8::XOT_OBJECT: + { + type_ = XOT_OBJECT; + value_.object_value = new std::map>(); + for (auto& pair : *value_.object_value) { + std::shared_ptr xobj_ptr = std::make_shared(); + pair.second->DeepCopy(*xobj_ptr.get()); + (*(value_.object_value))[pair.first] = xobj_ptr; + } + } + break; + default: + abort(); + } + } + a8::XValue XObject::AsXValue() { assert(type_ == XOT_SIMPLE); diff --git a/a8/xobject.h b/a8/xobject.h index 61fb16a..c3cba0f 100644 --- a/a8/xobject.h +++ b/a8/xobject.h @@ -27,6 +27,8 @@ namespace a8 unsigned char GetType(); int Size(); + void Reset(); + void DeepCopy(a8::XObject& to); a8::XValue AsXValue(); std::shared_ptr operator[] (int i); diff --git a/a8/xparams.h b/a8/xparams.h index 088f31e..4381d7f 100644 --- a/a8/xparams.h +++ b/a8/xparams.h @@ -36,6 +36,11 @@ namespace a8 return *this; } + void DeepCopy(a8::XParams& to) + { + to = *this; + } + public: a8::XValue sender; a8::XValue param1; diff --git a/a8/xvalue.cc b/a8/xvalue.cc index 54909f2..4d68eda 100644 --- a/a8/xvalue.cc +++ b/a8/xvalue.cc @@ -213,6 +213,11 @@ namespace a8 value_.int_value = 0; } + void XValue::DeepCopy(a8::XValue& to) + { + to = *this; + } + int XValue::Type() const { return type_; @@ -311,7 +316,7 @@ namespace a8 } case XVT_WSTRING: { - double dwV = 0; + double dwV = 0; if (value_.wstr_value){ if (wcsstr(value_.wstr_value, L"-")){ assert(false); diff --git a/a8/xvalue.h b/a8/xvalue.h index fd2f164..cbc1fda 100644 --- a/a8/xvalue.h +++ b/a8/xvalue.h @@ -45,6 +45,7 @@ namespace a8 void SetUserData(void *userdata, int datasize); void Set(double v); void SetNull(); + void DeepCopy(a8::XValue& to); int Type() const; bool IsNull();