|
26 | 26 |
|
27 | 27 | namespace oatpp { namespace postgresql { namespace ql_template {
|
28 | 28 |
|
29 |
| -TemplateValueProvider::TemplateValueProvider(const orm::Executor::ParamsTypeMap* paramsTypeMap) |
30 |
| - : m_paramsTypeMap(paramsTypeMap) |
31 |
| -{ |
32 |
| - m_typeNames.resize(data::mapping::type::ClassId::getClassCount(), nullptr); |
33 |
| - |
34 |
| - setTypeName(data::mapping::type::__class::String::CLASS_ID, "text"); |
35 |
| - setTypeName(data::mapping::type::__class::Any::CLASS_ID, nullptr); |
36 |
| - |
37 |
| - setTypeName(data::mapping::type::__class::Int8::CLASS_ID, "int2"); |
38 |
| - setTypeName(data::mapping::type::__class::UInt8::CLASS_ID, "int2"); |
39 |
| - |
40 |
| - setTypeName(data::mapping::type::__class::Int16::CLASS_ID, "int2"); |
41 |
| - setTypeName(data::mapping::type::__class::UInt16::CLASS_ID, "int4"); |
42 |
| - |
43 |
| - setTypeName(data::mapping::type::__class::Int32::CLASS_ID, "int4"); |
44 |
| - setTypeName(data::mapping::type::__class::UInt32::CLASS_ID, "int8"); |
45 |
| - |
46 |
| - setTypeName(data::mapping::type::__class::Int64::CLASS_ID, "int8"); |
47 |
| - setTypeName(data::mapping::type::__class::UInt64::CLASS_ID, nullptr); |
48 |
| - |
49 |
| - setTypeName(data::mapping::type::__class::Float32::CLASS_ID, "float4"); |
50 |
| - setTypeName(data::mapping::type::__class::Float64::CLASS_ID, "float8"); |
51 |
| - setTypeName(data::mapping::type::__class::Boolean::CLASS_ID, "bool"); |
52 |
| - |
53 |
| - setTypeName(data::mapping::type::__class::AbstractObject::CLASS_ID, nullptr); |
54 |
| - setTypeName(data::mapping::type::__class::AbstractEnum::CLASS_ID, nullptr); |
55 |
| - |
56 |
| - setTypeName(data::mapping::type::__class::AbstractVector::CLASS_ID, nullptr); |
57 |
| - setTypeName(data::mapping::type::__class::AbstractList::CLASS_ID, nullptr); |
58 |
| - setTypeName(data::mapping::type::__class::AbstractUnorderedSet::CLASS_ID, nullptr); |
59 |
| - |
60 |
| - setTypeName(data::mapping::type::__class::AbstractPairList::CLASS_ID, nullptr); |
61 |
| - setTypeName(data::mapping::type::__class::AbstractUnorderedMap::CLASS_ID, nullptr); |
62 |
| - |
63 |
| -} |
64 |
| - |
65 |
| -void TemplateValueProvider::setTypeName(const data::mapping::type::ClassId& classId, const oatpp::String& name) { |
66 |
| - const v_uint32 id = classId.id; |
67 |
| - if(id < m_typeNames.size()) { |
68 |
| - m_typeNames[id] = name; |
69 |
| - } else { |
70 |
| - throw std::runtime_error("[oatpp::postgresql::ql_template::TemplateValueProvider::setTypeName()]: " |
71 |
| - "Error. Unknown classId. Class-Name=" + std::string(classId.name)); |
72 |
| - } |
73 |
| -} |
74 |
| - |
75 | 29 | oatpp::String TemplateValueProvider::getValue(const data::share::StringTemplate::Variable& variable, v_uint32 index) {
|
76 |
| - |
77 |
| - auto typeIt = m_paramsTypeMap->find(variable.name); |
78 |
| - if(typeIt == m_paramsTypeMap->end()) { |
79 |
| - throw std::runtime_error("[oatpp::postgresql::Executor::PGTemplateValueProvider::getValue()]: Error. " |
80 |
| - "Type info not found for variable " + variable.name->std_str()); |
81 |
| - } |
82 |
| - |
83 |
| - auto typeName = m_typeNames[typeIt->second->classId.id]; |
84 |
| - |
85 |
| - if(!typeName) { |
86 |
| - throw std::runtime_error("[oatpp::postgresql::Executor::PGTemplateValueProvider::getValue()]: Error. " |
87 |
| - "Unsupported type - " + std::string(typeIt->second->classId.name)); |
88 |
| - } |
89 |
| - |
90 | 30 | m_buffStream.setCurrentPosition(0);
|
91 |
| - m_buffStream << "$" << (index + 1);// << "::" << typeName; |
92 |
| - |
| 31 | + m_buffStream << "$" << (index + 1); |
93 | 32 | return m_buffStream.toString();
|
94 |
| - |
95 | 33 | }
|
96 | 34 |
|
97 | 35 | }}}
|
0 commit comments