gSAFE  1.3.8
xbioconn.cpp
1 /*
2  gSAFE - LIB
3  general Sql dAtabase FrontEnd
4 
5  (C) 2011 Peter Deak (hyper80@gmail.com)
6 
7  License: GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
8 
9  XBase Connection to gDAFE datelib (based on XBase Import/Export lib)
10  xbioconn.cpp
11 */
12 
13 /*
14  * WARNING: This file's is depends on xbio.h/xbio.cpp which requires XBase library
15  * (http://linux.techass.com/projects/xdb/)
16  * If you don't want to use the XBase support just remove
17  * the xbio* files from your project, or undefine (remove) the ENABLE_XBASE_SUPPORT macro!
18  */
19 
20 #include "xbioconn.h"
21 #include "dconsole.h"
22 
23 #ifdef ENABLE_XBASE_SUPPORT
24 
25 
27 {
28  whoami = "HXBaseRecordSync";
29  fieldconn.clear();
30 }
31 
32 HXBaseRecordSync::~HXBaseRecordSync(void)
33 {
34  fieldconn.clear();
35 }
36 
37 void HXBaseRecordSync::assign(QString htablefieldsqlname, QString xbasefieldname)
38 {
39  fieldconn.push_back(HFieldPairs(htablefieldsqlname,xbasefieldname));
40 }
41 
43 {
44  fieldconn.clear();
45 }
46 
48 {
49  QList<HFieldPairs>::iterator i;
50  for(i=fieldconn.begin();i!=fieldconn.end();++i)
51  {
52  QString gsafetype;
53  HDataField *d;
54  d = record->fieldBySqlName(i->gsafefieldname);
55  if(d == NULL)
56  {
57  sdebug(QString("ERROR in HXBaseRecordSync::syncHTableToXBase :\n"
58  "Can't find datafield in HTable with name \"%1\" (Passed with assign) SKIPPING!")
59  .arg(i->gsafefieldname));
60  continue;
61  }
62  gsafetype = d->getWhoami();
63 
64  if(gsafetype == "HKey" ||
65  gsafetype == "HSmallText" ||
66  gsafetype == "HLargeText" ||
67  gsafetype == "HCharHash" ||
68  gsafetype == "HSqlChoose" )
69  dbf->setFieldStr(i->xbasefieldname,d->getValue().toString() );
70 
71  if(gsafetype == "HNumHash" ||
72  gsafetype == "HNumber" )
73  dbf->setFieldDecimal(i->xbasefieldname,d->getValue().toInt() );
74 
75  if(gsafetype == "HFloating")
76  dbf->setFieldFloat(i->xbasefieldname,d->getValue().toDouble());
77 
78  if(gsafetype == "HDate")
79  dbf->setFieldDate(i->xbasefieldname,d->getValue().toDate());
80 
81  if(gsafetype == "HCheck")
82  dbf->setFieldBool(i->xbasefieldname,d->getValue().toBool());
83 
84  if(gsafetype == "HTimestamp")
85  dbf->setFieldStr(i->xbasefieldname,d->getValue().toString());
86 
87  if(gsafetype == "HStatic")
88  continue;
89  }
90 
91  return 0;
92 }
93 
95 {
96  QList<HFieldPairs>::iterator i;
97  for(i=fieldconn.begin();i!=fieldconn.end();++i)
98  {
99  QString gsafetype;
100  HDataField *d;
101  d = record->fieldBySqlName(i->gsafefieldname);
102 
103  if(d == NULL)
104  {
105  sdebug(QString("ERROR in HXBaseRecordSync::syncXBaseToHTable :\n"
106  "Can't find datafield in HTable with name \"%1\" (Passed with assign) SKIPPING!")
107  .arg(i->gsafefieldname));
108  continue;
109  }
110 
111  gsafetype = d->getWhoami();
112 
113  if(gsafetype == "HKey" ||
114  gsafetype == "HSmallText" ||
115  gsafetype == "HLargeText" ||
116  gsafetype == "HCharHash" ||
117  gsafetype == "HSqlChoose" )
118  d->setValue(QVariant( dbf->getFieldStr(i->xbasefieldname) ));
119 
120  if(gsafetype == "HNumHash" ||
121  gsafetype == "HNumber" )
122  d->setValue(QVariant( (int) dbf->getFieldDecimal(i->xbasefieldname) ));
123 
124  if(gsafetype == "HFloating")
125  d->setValue(QVariant( dbf->getFieldFloat(i->xbasefieldname) ));
126 
127  if(gsafetype == "HDate")
128  d->setValue(QVariant( dbf->getFieldDate(i->xbasefieldname) ));
129 
130  if(gsafetype == "HCheck")
131  d->setValue(QVariant( dbf->getFieldBool(i->xbasefieldname) ));
132 
133  if(gsafetype == "HTimestamp")
134  d->setValue(QVariant( dbf->getFieldStr(i->xbasefieldname) ));
135 
136  if(gsafetype == "HStatic")
137  continue;
138  }
139 
140  return 0;
141 
142 }
143 
144 
145 
146 #endif // ENABLE_XBASE_SUPPORT
147 
148 //end code.
HDataField * fieldBySqlName(QString sqln, bool all=false, QString containerSqlTable="")
Definition: datalib.cpp:2342
virtual int setValue(QVariant v, bool sdisabled=false)
Definition: datalib.cpp:5390
long getFieldDecimal(QString fname)
Definition: xbio.cpp:291
void assign(QString htablefieldsqlname, QString xbasefieldname)
Definition: xbioconn.cpp:37
void clearAssigns(void)
Definition: xbioconn.cpp:42
QDate getFieldDate(QString fname)
Definition: xbio.cpp:321
bool getFieldBool(QString fname)
Definition: xbio.cpp:311
int setFieldFloat(QString fname, double val)
Definition: xbio.cpp:543
int syncHTableToXBase(HTable *record, HXBaseFileWriter *dbf)
Definition: xbioconn.cpp:47
QString getFieldStr(QString fname)
Definition: xbio.cpp:280
void sdebug(QString s)
Definition: dconsole.cpp:48
int setFieldBool(QString fname, bool logical)
Definition: xbio.cpp:554
QString getWhoami(void)
Definition: datalib.cpp:774
int setFieldDecimal(QString fname, long decimal)
Definition: xbio.cpp:533
virtual QVariant getValue(void)
Definition: datalib.cpp:5418
QString whoami
Definition: datalib.h:318
int setFieldDate(QString fname, QDate date)
Definition: xbio.cpp:565
double getFieldFloat(QString fname)
Definition: xbio.cpp:301
int setFieldStr(QString fname, QString str)
Definition: xbio.cpp:517
int syncXBaseToHTable(HXBaseFileReader *dbf, HTable *record)
Definition: xbioconn.cpp:94