GnuCashew ~ GnuCash Enabled Web
GCW
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 
11 const char * GCW::Dbo::Slots::s_tableName = "slots";
12 
13 Wt::WFormModel::Field GCW::Dbo::Slots::Field::id = "id" ; // integer PRIMARY KEY AUTOINCREMENT NOT NULL,
14 Wt::WFormModel::Field GCW::Dbo::Slots::Field::obj_guid = "obj_guid" ; // text(32) NOT NULL,
15 Wt::WFormModel::Field GCW::Dbo::Slots::Field::name = "name" ; // text(4096) NOT NULL,
16 Wt::WFormModel::Field GCW::Dbo::Slots::Field::slot_type = "slot_type" ; // integer NOT NULL,
17 Wt::WFormModel::Field GCW::Dbo::Slots::Field::int64_val = "int64_val" ; // bigint,
18 Wt::WFormModel::Field GCW::Dbo::Slots::Field::string_val = "string_val" ; // text(4096),
19 Wt::WFormModel::Field GCW::Dbo::Slots::Field::double_val = "double_val" ; // float8,
20 Wt::WFormModel::Field GCW::Dbo::Slots::Field::timespec_val = "timespec_val" ; // text(19),
21 Wt::WFormModel::Field GCW::Dbo::Slots::Field::guid_val = "guid_val" ; // text(32),
22 Wt::WFormModel::Field GCW::Dbo::Slots::Field::numeric_val_num = "numeric_val_num" ; // bigint,
23 Wt::WFormModel::Field GCW::Dbo::Slots::Field::numeric_val_denom = "numeric_val_denom" ; // bigint,
24 Wt::WFormModel::Field GCW::Dbo::Slots::Field::gdate_val = "gdate_val" ; // text(8)
25 
26 
27 
30 get()
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 
52 get( 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
91 std::string
93 getVarString( const std::string & _field ) const
94 {
95  std::string retVal;
96 
97  if( _field != "" )
98  {
99  Wt::Json::Object jobj;
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 
116 int
118 getVarInt( 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 
141 void
143 setVar( 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 
149 void
151 setVar( 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 
157 void
159 setVar( 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 
185 void
187 setVar( 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
Wt::Dbo::ptr< Item > Ptr
Definition: BaseItem.h:39
Variables Item Class.
Definition: Item.h:54
int getVarInt(const std::string &_field) const
Definition: Vars.cpp:100
void setVar(const std::string &_field, const char *_value)
Definition: Vars.cpp:125
const std::string & varField() const
Definition: Vars.h:41
std::string getVarString(const std::string &_field) const
Definition: Vars.cpp:75
const Wt::WFormModel::Field id
Definition: Definition.h:17
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:67