GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Slots.cpp
Go to the documentation of this file.
1#line 2 "src/Dbo/Slots.cpp"
2
3#include <Wt/Json/Parser.h>
4#include <Wt/Json/Object.h>
5#include <Wt/Json/Serializer.h>
6
7#include "../App.h"
8#include "Slots.h"
9
10
11const char * GCW::Dbo::Slots::s_tableName = "slots";
12
13Wt::WFormModel::Field GCW::Dbo::Slots::Field::id = "id" ; // integer PRIMARY KEY AUTOINCREMENT NOT NULL,
14Wt::WFormModel::Field GCW::Dbo::Slots::Field::obj_guid = "obj_guid" ; // text(32) NOT NULL,
15Wt::WFormModel::Field GCW::Dbo::Slots::Field::name = "name" ; // text(4096) NOT NULL,
16Wt::WFormModel::Field GCW::Dbo::Slots::Field::slot_type = "slot_type" ; // integer NOT NULL,
25
26
27
30get()
31{
33
34 /*
35 **
36 */
37 auto resultList =
38 GCW::app()-> gnucashew_session().find< GCW::Dbo::Slots::Item >()
39 .resultList()
40 ;
41
42 for( auto & result : resultList )
43 retVal.push_back( result );
44
45 return retVal;
46
47} // endget()
48
49
52get( const std::string & _guid, const std::string & _name )
53{
55
56 /*
57 ** Build a 'where' that has both the key and cfy
58 ** fields represented.
59 **
60 */
61 auto where =
62 Wt::WString( "\"obj_guid\" = '{1}'" )
63 .arg( _guid )
64 .toUTF8()
65 ;
66
67 if( _name != "*"
68 && _name != ""
69 )
70 where +=
71 Wt::WString( " AND \"name\" = '{1}'" )
72 .arg( _name )
73 .toUTF8()
74 ;
75
76 /*
77 ** find the item (or try to)
78 **
79 */
80 retVal =
81 GCW::app()-> gnucashew_session().find< GCW::Dbo::Slots::Item >()
82 .where( where )
83 .resultValue()
84 ;
85
86 return retVal;
87
88} // endget( const std::string & _keyValue, const std::string & _cfyValue )
89
90#ifdef NEVER
91std::string
93getVarString( const std::string & _field ) const
94{
95 std::string retVal;
96
97 if( _field != "" )
98 {
100 try {
101 Wt::Json::parse( varField(), jobj );
102 }
103 catch( std::exception & e )
104 {
105 std::cout << __FILE__ << ":" << __LINE__ << " id:" << this-> id() << " " << e.what() << std::endl;
106 }
107
108 retVal = jobj.get( _field ).orIfNull("");
109
110 }
111
112 return retVal;
113
114} // endgetVarString( const std::string & _field ) const
115
116int
118getVarInt( const std::string & _field ) const
119{
120 int retVal = 0;
121
122 if( _field != "" )
123 {
124 Wt::Json::Object jobj;
125 try {
126 Wt::Json::parse( varField(), jobj );
127 }
128 catch( std::exception & e )
129 {
130 std::cout << __FILE__ << ":" << __LINE__ << " id:" << this-> id() << " " << e.what() << std::endl;
131 }
132
133 retVal = jobj.get( _field ).orIfNull( 0 );
134
135 }
136
137 return retVal;
138
139} // endgetVarInt( const std::string & _field ) const
140
141void
143setVar( const std::string & _field, const char * _value )
144{
145 setVar( _field, std::string( _value ) );
146
147} // endsetVar( const std::string & _field, const std::string & _value )
148
149void
151setVar( const std::string & _field, const Wt::WString & _value )
152{
153 setVar( _field, _value.toUTF8() );
154
155} // endsetVar( const std::string & _field, const std::string & _value )
156
157void
159setVar( const std::string & _field, const std::string & _value )
160{
161 /*
162 ** If there is no field specified, then there's nothing
163 ** to do.
164 **
165 */
166 if( _field == "" )
167 return;
168
169 Wt::Json::Object jobj;
170 try {
171 Wt::Json::parse( varField(), jobj );
172
173 }
174 catch( std::exception & e )
175 {
176 std::cout << __FILE__ << ":" << __LINE__ << " id:" << this-> id() << " " << e.what() << std::endl;
177 }
178
179 jobj[_field] = Wt::WString( _value );
180
181 setVarField( Wt::Json::serialize( jobj ) );
182
183} // endsetVar( const std::string & _field, const std::string & _value )
184
185void
187setVar( const std::string & _field, int _value )
188{
189 /*
190 ** If there is no field specified, then there's nothing
191 ** to do.
192 **
193 */
194 if( _field == "" )
195 return;
196
197 Wt::Json::Object jobj;
198 try {
199 Wt::Json::parse( varField(), jobj );
200 }
201 catch( std::exception & e )
202 {
203 std::cout << __FILE__ << ":" << __LINE__ << " id:" << this-> id() << " " << e.what() << std::endl;
204 }
205
206 jobj[_field] = _value;
207
208 setVarField( Wt::Json::serialize( jobj ) );
209
210} // endsetVar( const std::string & _field, int & _value )
211
212
213#endif
214
std::vector< Ptr > Vector
Definition BaseItem.h:41
Variables Item Class.
int getVarInt(const std::string &_field) const
Definition Vars.cpp:120
void setVar(const std::string &_field, const char *_value)
Definition Vars.cpp:145
const std::string & varField() const
Definition Vars.h:41
std::string getVarString(const std::string &_field) const
Definition Vars.cpp:95
dbo_traits< C >::IdType id() const
const Value & get(const std::string &name) const
const WString & orIfNull(const WString &v) const
const char * Field
std::string toUTF8() const
WString & arg(const std::wstring &value)
void parse(const std::string &input, Value &result, bool validateUTF8=true)
std::string serialize(const Object &obj, int indentation=1)
Wt::WFormModel::Field id
Definition Customers.cpp:10
Wt::WFormModel::Field gdate_val
Definition Slots.cpp:24
Wt::WFormModel::Field double_val
Definition Slots.cpp:19
Wt::WFormModel::Field obj_guid
Definition Slots.cpp:14
Wt::WFormModel::Field id
Definition Slots.cpp:13
Wt::WFormModel::Field int64_val
Definition Slots.cpp:17
Wt::WFormModel::Field string_val
Definition Slots.cpp:18
Wt::WFormModel::Field timespec_val
Definition Slots.cpp:20
Wt::WFormModel::Field numeric_val_num
Definition Slots.cpp:22
Wt::WFormModel::Field name
Definition Slots.cpp:15
Wt::WFormModel::Field slot_type
Definition Slots.cpp:16
Wt::WFormModel::Field guid_val
Definition Slots.cpp:21
Wt::WFormModel::Field numeric_val_denom
Definition Slots.cpp:23
auto get() -> GCW::Dbo::Slots::Item::Vector
Definition Slots.cpp:30
const char * s_tableName
Definition Slots.cpp:11
Wt::WFormModel::Field varField
Definition Var.cpp:7
App * app()
Definition App.cpp:75