20 #ifdef ENABLE_XBASE_SUPPORT
24 int cp852from128idx_utf16value[] =
25 {199 ,252 ,233 ,226 ,228 ,367 ,263 ,231 ,322 ,235 ,336 ,337 ,238 ,377 ,196 ,262 ,201 ,313 ,314 ,244 ,
26 246 ,317 ,318 ,346 ,347 ,214 ,220 ,356 ,357 ,321 ,215 ,269 ,225 ,237 ,243 ,250 ,260 ,261 ,381 ,382 ,
27 280 ,281 ,172 ,378 ,268 ,351 ,171 ,187 ,9617,9618,9619,9474,9508,193 ,194 ,282 ,350 ,9571,9553,9559,
28 9565,379 ,380 ,9488,9492,9524,9516,9500,9472,9532,258 ,259 ,9562,9556,9577,9574,9568,9552,9580,164 ,
29 273 ,272 ,270 ,203 ,271 ,327 ,205 ,206 ,283 ,9496,9484,9608,9604,354 ,366 ,9600,211 ,223 ,212 ,323 ,
30 324 ,328 ,352 ,353 ,340 ,218 ,341 ,368 ,253 ,221 ,355 ,180 ,173 ,733 ,731 ,711 ,728 ,167 ,247 ,184 ,
31 176 ,168 ,729 ,369 ,344 ,345 ,9632,160 };
33 int cp850from128idx_utf16value[] =
34 {199 ,252 ,233 ,226 ,228 ,224 ,229 ,231 ,234 ,235 ,232 ,239 ,238 ,236 ,196 ,197 ,201 ,230 ,198 ,244 ,
35 246 ,242 ,251 ,249 ,255 ,214 ,220 ,248 ,163 ,216 ,215 ,402 ,225 ,237 ,243 ,250 ,241 ,209 ,170 ,186 ,
36 191 ,174 ,172 ,189 ,188 ,161 ,171 ,187 ,9617,9618,9619,9474,9508,193 ,194 ,192 ,169 ,9571,9553,9559,
37 9565,162 ,165 ,9488,9492,9524,9516,9500,9472,9532,227 ,195 ,9562,9556,9577,9574,9568,9552,9580,164 ,
38 240 ,208 ,202 ,203 ,200 ,305 ,205 ,206 ,207 ,9496,9484,9608,9604,166 ,204 ,9600,211 ,223 ,212 ,210 ,
39 245 ,213 ,181 ,254 ,222 ,218 ,219 ,217 ,253 ,221 ,175 ,180 ,173 ,177 ,8215,190 ,182 ,167 ,247 ,184 ,
40 176 ,168 ,183 ,185 ,179 ,178 ,9632,160 };
42 QString HCodepage852::conv_from(
char * from)
48 if((
unsigned int)(from[i]) < 128u)
49 f[i] = QChar((
unsigned int)from[i]);
51 f[i] = QChar(cp852from128idx_utf16value[(
unsigned char)from[i]-128u]);
55 void HCodepage852::conv_to(QString from,
char *buffer,
int bufflen)
57 int i,ii,l=from.length();
58 for(i=0;i<l && i<bufflen;++i)
59 if((
unsigned int)(from[i].unicode()) < 128u)
60 buffer[i] = (
unsigned char)from[i].unicode();
64 if((
int)cp852from128idx_utf16value[ii] == (int)from[i].unicode())
72 QString HCodepage850::conv_from(
char * from)
78 if((
unsigned int)(from[i]) < 128u)
79 f[i] = QChar((
unsigned int)from[i]);
81 f[i] = QChar(cp850from128idx_utf16value[(
unsigned char)from[i]-128u]);
85 void HCodepage850::conv_to(QString from,
char *buffer,
int bufflen)
87 int i,ii,l=from.length();
88 for(i=0;i<l && i<bufflen;++i)
89 if((
unsigned int)(from[i].unicode()) < 128u)
90 buffer[i] = (
unsigned char)from[i].unicode();
94 if((
int)cp850from128idx_utf16value[ii] == (int)from[i].unicode())
107 xbase =
new xbXBase();
108 dbf =
new xbDbf(xbase);
110 buffer=
new char[CPCONV_BUFFERLENGTH];
111 deleteconvertobject = deletecobj;
119 if(deleteconvertobject)
128 return dbf->FieldCount();
137 recs = dbf->NoOfRecords();
146 return dbf->GetFieldName((xbShort)n);
155 t = dbf->GetFieldType((xbShort)n);
158 case 'C':
return Char;
159 case 'D':
return Date;
160 case 'L':
return Logical;
161 case 'N':
return Numeric;
162 case 'F':
return Float;
163 case 'M':
return Memo;
164 default:
return Error;
188 emit
errorSignal(QString(
"HXBaseFileReader::open : A database file already opened!"));
192 if(( rc = dbf->OpenDatabase(name.toLocal8Bit().constData())) != XB_NO_ERROR )
194 emit
errorSignal(QString(
"HXBaseFileReader::open : Error opening \"%1\" file!").arg(name));
205 emit
errorSignal(QString(
"HXBaseFileReader::open : There is no opened database!"));
208 dbf->CloseDatabase();
218 rc = dbf->GetRecord(idx);
219 if(rc != XB_NO_ERROR)
221 emit
errorSignal(QString(
"HXBaseFileReader::toRecord: Cannot seek to record: !").arg(idx));
233 rc = dbf->GetFirstRecord();
234 if( rc == XB_NO_ERROR )
245 rc = dbf->GetLastRecord();
246 if( rc == XB_NO_ERROR )
257 rc = dbf->GetNextRecord();
258 if(rc == XB_NO_ERROR)
269 rc = dbf->GetPrevRecord();
270 if(rc == XB_NO_ERROR)
277 return dbf->GetCurRecNo();
285 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
287 dbf->GetField(no,buffer);
288 return c->conv_from(buffer).trimmed();
296 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
298 return dbf->GetLongField(no);
306 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
308 return dbf->GetDoubleField(no);
316 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
318 return (
bool)(dbf->GetLogicalField(no));
329 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
331 dbf->GetField(no,buffer);
333 date = QDate::fromString(c->conv_from(buffer),
"yyyyMMdd");
337 date = QDate::fromString(c->conv_from(buffer),
"yyyy.MM.dd");
341 date = QDate::fromString(c->conv_from(buffer),
"yyyy-MM-dd");
348 QString HXBaseFileReader::getCellStr(
long rec,QString fname)
355 long HXBaseFileReader::getCellDecimal(
long rec,QString fname)
362 double HXBaseFileReader::getCellFloat(
long rec,QString fname)
369 bool HXBaseFileReader::getCellBool(
long rec,QString fname)
376 QDate HXBaseFileReader::getCellDate(
long rec,QString fname)
390 schema =
new xbSchema[XBASESCHEMA_MAXFIELD];
391 setLastDefinedField(defined_fnum);
399 void HXBaseFileWriter::setLastDefinedField(
int idx)
401 strncpy(schema[idx].FieldName,
"",10);
402 schema[idx].Type = 0;
403 schema[idx].FieldLen = 0;
404 schema[idx].NoOfDecs = 0;
413 emit
errorSignal(QString(
"HXBaseFileWriter::open : A database file already opened!"));
417 if(( rc = dbf->OpenDatabase(name.toLocal8Bit().constData())) != XB_NO_ERROR )
419 emit
errorSignal(QString(
"HXBaseFileWriter::open : Error opening \"%1\" file!").arg(name));
430 emit
errorSignal(QString(
"HXBaseFileWriter::open : There is no opened database!"));
433 dbf->CloseDatabase();
442 emit
errorSignal(QString(
"HXBaseFileWriter::defineField : A database file already opened, You can ONLY define field before creation!"));
447 int locallength=length;
448 if(type == Numeric) { localtype = XB_NUMERIC_FLD; }
449 if(type == Char) { localtype = XB_CHAR_FLD; }
450 if(type == Date) { localtype = XB_DATE_FLD; locallength = 8; }
451 if(type == Float) { localtype = XB_FLOAT_FLD; }
452 if(type == Logical) { localtype = XB_LOGICAL_FLD; locallength = 1; }
455 emit
errorSignal(QString(
"HXBaseFileWriter::defineField : The field has \"Memo\" type! I don't support it, sorry :-("));
460 emit
errorSignal(QString(
"HXBaseFileWriter::defineField : The field has \"Error\" type!"));
464 strncpy(schema[defined_fnum].FieldName,name.toLocal8Bit().constData(),10);
465 schema[defined_fnum].Type = localtype;
466 schema[defined_fnum].FieldLen = locallength;
467 schema[defined_fnum].NoOfDecs = nofdecimals;
469 setLastDefinedField(++defined_fnum);
478 emit
errorSignal(QString(
"HXBaseFileWriter::open : A database file already opened!"));
481 dbf->SetVersion( version );
482 if(( rc = dbf->CreateDatabase( name.toLocal8Bit().constData() , schema , XB_OVERLAY )) != XB_NO_ERROR )
484 emit
errorSignal(QString(
"HXBaseFileWriter::open : Error opening \"%1\" file!").arg(name));
507 if(( rc = dbf->AppendRecord()) != XB_NO_ERROR )
509 emit
errorSignal(QString(
"HXBaseFileWriter::appendRecord : Append record is unsuccessful!"));
523 int max=CPCONV_BUFFERLENGTH;
525 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
526 if(dbf->GetFieldLen(no) < CPCONV_BUFFERLENGTH)
527 max = dbf->GetFieldLen(no);
528 c->conv_to(str,buffer,max);
529 dbf->PutField(no,buffer);
538 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
539 dbf->PutLongField(no,decimal);
549 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
550 dbf->PutDoubleField(no,val);
560 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
561 dbf->PutField(no,logical ?
"T" :
"F");
571 no = dbf->GetFieldNo(fname.toLocal8Bit().constData());
572 c->conv_to(date.toString(
"yyyyMMdd"),buffer,8);
573 dbf->PutField(no,buffer);
577 #endif // ENABLE_XBASE_SUPPORT
HXBaseFileWriter(HCodepageConvert *conv, bool deletecobj=false)
long getFieldDecimal(QString fname)
HXBaseFileReader(HCodepageConvert *conv, bool deletecobj=false)
QDate getFieldDate(QString fname)
int create(QString name, int version)
bool getFieldBool(QString fname)
HXBaseFileHandler(HCodepageConvert *conv, bool deletecobj=false)
int setFieldFloat(QString fname, double val)
long getCurrentRecordIdx(void)
void errorSignal(QString error)
HXBaseFieldType fieldType(int n)
QString getFieldStr(QString fname)
int setFieldBool(QString fname, bool logical)
int setFieldDecimal(QString fname, long decimal)
int setFieldDate(QString fname, QDate date)
void defineField(QString name, HXBaseFieldType type, int length=0, int nofdecimals=0)
double getFieldFloat(QString fname)
int setFieldStr(QString fname, QString str)