File: xbasetopg.patch

package info (click to toggle)
pgdbf 0.6.3%2Bgit20180121.4e84775-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,040 kB
  • sloc: sh: 3,884; ansic: 1,099; python: 198; makefile: 35
file content (718 lines) | stat: -rw-r--r-- 22,333 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
diff -urN xbase64-3.1.2-old/bin/dumprecspg.cpp xbase64-3.1.2/bin/dumprecspg.cpp
--- xbase64-3.1.2-old/bin/dumprecspg.cpp	1969-12-31 18:00:00.000000000 -0600
+++ xbase64-3.1.2/bin/dumprecspg.cpp	2008-01-11 13:17:01.000000000 -0600
@@ -0,0 +1,125 @@
+/*  dumprecs.cpp
+
+    This program dumps a dbf file contents 
+
+    Xbase64 project source code
+
+    This sample program dumps Xbase records
+
+    Copyright (C) 2006,2007,2008  Kirk Strauser <kirk@strauser.com>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Contact:
+    
+     Email:
+    
+      xbase64-devel@lists.sourceforge.net
+      xbase64-users@lists.sourceforge.net
+      
+      
+     Regular Mail:
+     
+       XBase Support
+       149C South Main St
+       Keller Texas, 76248     
+       USA
+
+*/
+#include <xbase64/xbase64.h>
+
+// next lines are helpful for debugging purposes
+#include <xbase64/xbdbf.cpp>
+#include <xbase64/xbexp.cpp>
+#include <xbase64/xbexpprc.cpp>
+#include <xbase64/xbexpfnc.cpp>
+#include <xbase64/xbfields.cpp>
+#include <xbase64/xbindex.cpp>
+#include <xbase64/xbmemo.cpp>
+#include <xbase64/xbndx.cpp>
+#include <xbase64/xbntx.cpp>
+#include <xbase64/xbase64.cpp>
+#include <xbase64/xbdate.cpp>
+#include <xbase64/xbfilter.cpp>
+#include <xbase64/xblock.cpp>
+#include <xbase64/xbstring.cpp>
+#include <xbase64/xbfile.cpp>
+#include <xbase64/xbcdx.cpp>
+
+
+
+int main(int ac,char** av)
+{
+  xbXBase x;
+  xbShort rc;  
+ 
+  if (ac <= 1) {
+    std::cout << "Usage: dumprecs filename [indexcolumn ...]" << std::endl;
+    return 1;
+  }
+
+  char* filename = av[1];
+
+  xbDbf MyFile( &x );
+
+  MyFile.SetVersion( 4 );
+  rc = MyFile.OpenDatabase(filename);
+  if( rc != XB_NO_ERROR) {
+    std::cout << "Could not open file " << filename << std::endl;
+    x.DisplayError( rc );
+    return 1;
+  }
+
+  char tablename[4096];
+  MyFile.GetTableName( tablename );
+
+  // Start a transaction, then drop the table and recreate it
+  std::cout << "begin;" << std::endl;
+  std::cout << "drop table " << tablename << ";" << std::endl;
+  MyFile.PgDumpHeader();
+
+  // Dump the database contents
+  std::cout << "\\copy " << tablename << " from stdin" << std::endl;
+
+  int row = 0;
+  while(row<MyFile.NoOfRecords()){
+    rc = MyFile.PgDumpRecord(++row);
+    if( rc != XB_NO_ERROR )
+      x.DisplayError( rc );
+  }
+  std::cout << "\\." << std::endl;
+
+  // Create requested indices
+  for( int i = 2; i < ac; i++ ){
+    std::cout << "create index " << tablename << "_";
+    for( int j = 0; av[i][j]; j++){
+      if( isalnum(av[i][j]) ){
+	std::cout << av[i][j];
+      }
+      else{
+	std::cout << "_";
+      }
+    }
+    std::cout << " on " << tablename << "(" << av[i] << ");\n";
+  }
+
+  // Commit the transaction and clean up
+  std::cout << "commit;" << std::endl;
+//   std::cout << "analyze " << tablename << ";" << std::endl;
+  MyFile.CloseDatabase();	/* close database */
+
+  return 0;
+}     
+
diff -urN xbase64-3.1.2-old/bin/Makefile.in xbase64-3.1.2/bin/Makefile.in
--- xbase64-3.1.2-old/bin/Makefile.in	2004-06-01 15:46:50.000000000 -0500
+++ xbase64-3.1.2/bin/Makefile.in	2008-01-11 13:17:01.000000000 -0600
@@ -95,8 +95,8 @@
 INCLUDES = -I$(topdir)
 LDADD = -L$(topdir)/xbase64 -lxbase64
 
-bin_PROGRAMS = checkndx copydbf dbfxtrct deletall dumphdr dumprecs packdbf   \
-               reindex undelall zap dbfutil1
+bin_PROGRAMS = checkndx copydbf dbfxtrct deletall dumphdr dumprecs dumprecspg   \
+               packdbf reindex undelall zap dbfutil1
 
 
 noinst_PROGRAMS = dumpdbt
@@ -109,6 +109,7 @@
 dumpdbt_SOURCES = dumpdbt.cpp 
 dumphdr_SOURCES = dumphdr.cpp 
 dumprecs_SOURCES = dumprecs.cpp 
+dumprecspg_SOURCES = dumprecspg.cpp 
 packdbf_SOURCES = packdbf.cpp 
 reindex_SOURCES = reindex.cpp 
 undelall_SOURCES = undelall.cpp
@@ -127,8 +128,8 @@
 CONFIG_CLEAN_FILES =
 bin_PROGRAMS = checkndx$(EXEEXT) copydbf$(EXEEXT) dbfxtrct$(EXEEXT) \
 	deletall$(EXEEXT) dumphdr$(EXEEXT) dumprecs$(EXEEXT) \
-	packdbf$(EXEEXT) reindex$(EXEEXT) undelall$(EXEEXT) \
-	zap$(EXEEXT) dbfutil1$(EXEEXT)
+	dumprecspg$(EXEEXT) packdbf$(EXEEXT) reindex$(EXEEXT) \
+	undelall$(EXEEXT) zap$(EXEEXT) dbfutil1$(EXEEXT)
 noinst_PROGRAMS = dumpdbt$(EXEEXT)
 PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS)
 
@@ -172,6 +173,11 @@
 dumprecs_LDADD = $(LDADD)
 dumprecs_DEPENDENCIES =
 dumprecs_LDFLAGS =
+am_dumprecspg_OBJECTS = dumprecspg.$(OBJEXT)
+dumprecspg_OBJECTS = $(am_dumprecspg_OBJECTS)
+dumprecspg_LDADD = $(LDADD)
+dumprecspg_DEPENDENCIES =
+dumprecspg_LDFLAGS =
 am_packdbf_OBJECTS = packdbf.$(OBJEXT)
 packdbf_OBJECTS = $(am_packdbf_OBJECTS)
 packdbf_LDADD = $(LDADD)
@@ -204,8 +210,9 @@
 @AMDEP_TRUE@	./$(DEPDIR)/dbfutil1.Po ./$(DEPDIR)/dbfxtrct.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/deletall.Po ./$(DEPDIR)/dumpdbt.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/dumphdr.Po ./$(DEPDIR)/dumprecs.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/packdbf.Po ./$(DEPDIR)/reindex.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/undelall.Po ./$(DEPDIR)/zap.Po
+@AMDEP_TRUE@	./$(DEPDIR)/dumprecspg.Po ./$(DEPDIR)/packdbf.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/reindex.Po ./$(DEPDIR)/undelall.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/zap.Po
 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
 	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
 LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \
@@ -218,12 +225,12 @@
 DIST_SOURCES = $(checkndx_SOURCES) $(copydbf_SOURCES) \
 	$(dbfutil1_SOURCES) $(dbfxtrct_SOURCES) $(deletall_SOURCES) \
 	$(dumpdbt_SOURCES) $(dumphdr_SOURCES) $(dumprecs_SOURCES) \
-	$(packdbf_SOURCES) $(reindex_SOURCES) $(undelall_SOURCES) \
-	$(zap_SOURCES)
+	$(dumprecspg_SOURCES) $(packdbf_SOURCES) $(reindex_SOURCES) \
+	$(undelall_SOURCES) $(zap_SOURCES)
 HEADERS = $(noinst_HEADERS)
 
 DIST_COMMON = $(noinst_HEADERS) Makefile.am Makefile.in
-SOURCES = $(checkndx_SOURCES) $(copydbf_SOURCES) $(dbfutil1_SOURCES) $(dbfxtrct_SOURCES) $(deletall_SOURCES) $(dumpdbt_SOURCES) $(dumphdr_SOURCES) $(dumprecs_SOURCES) $(packdbf_SOURCES) $(reindex_SOURCES) $(undelall_SOURCES) $(zap_SOURCES)
+SOURCES = $(checkndx_SOURCES) $(copydbf_SOURCES) $(dbfutil1_SOURCES) $(dbfxtrct_SOURCES) $(deletall_SOURCES) $(dumpdbt_SOURCES) $(dumphdr_SOURCES) $(dumprecs_SOURCES) $(dumprecspg_SOURCES) $(packdbf_SOURCES) $(reindex_SOURCES) $(undelall_SOURCES) $(zap_SOURCES)
 
 all: all-am
 
@@ -294,6 +301,9 @@
 dumprecs$(EXEEXT): $(dumprecs_OBJECTS) $(dumprecs_DEPENDENCIES) 
 	@rm -f dumprecs$(EXEEXT)
 	$(CXXLINK) $(dumprecs_LDFLAGS) $(dumprecs_OBJECTS) $(dumprecs_LDADD) $(LIBS)
+dumprecspg$(EXEEXT): $(dumprecspg_OBJECTS) $(dumprecspg_DEPENDENCIES) 
+	@rm -f dumprecspg$(EXEEXT)
+	$(CXXLINK) $(dumprecspg_LDFLAGS) $(dumprecspg_OBJECTS) $(dumprecspg_LDADD) $(LIBS)
 packdbf$(EXEEXT): $(packdbf_OBJECTS) $(packdbf_DEPENDENCIES) 
 	@rm -f packdbf$(EXEEXT)
 	$(CXXLINK) $(packdbf_LDFLAGS) $(packdbf_OBJECTS) $(packdbf_LDADD) $(LIBS)
@@ -321,6 +331,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dumpdbt.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dumphdr.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dumprecs.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dumprecspg.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/packdbf.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reindex.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/undelall.Po@am__quote@
diff -urN xbase64-3.1.2-old/xbase64/xbdbf.cpp xbase64-3.1.2/xbase64/xbdbf.cpp
--- xbase64-3.1.2-old/xbase64/xbdbf.cpp	2006-07-17 11:54:42.000000000 -0500
+++ xbase64-3.1.2/xbase64/xbdbf.cpp	2008-01-11 13:17:01.000000000 -0600
@@ -56,6 +56,16 @@
 #endif
 #include <errno.h>
 
+char *reservedwords[] = {
+  "desc",
+  "from",
+  "group",
+  "to",
+  "user",
+  NULL,
+};
+
+
 /*! \file xbdbf.cpp
 */
 
@@ -739,8 +749,115 @@
   std::cout << std::endl;
   return XB_NO_ERROR;
 }
+/************************************************************************/
+//! Print header information in the format of a PostgreSQL "create table" command
+/*!
+*/
+xbShort xbDbf::PgDumpHeader()
+{
+  char fieldname[4096];
+  char filename[4096];
+ 
+  GetTableName( filename );
+  std::cout << "create table " << filename << " (";
+
+  int printed = 0;
+  for( int i = 0; i <NoOfFields; i++ ){
+    if( SchemaPtr[i].Type != '0' ){
+      if( printed ){
+	std::cout << ", ";
+      }
+      else{
+	printed = 1;
+      }
+      strncpy( fieldname, SchemaPtr[i].FieldName, 4096 );
+      LowerCase( fieldname );
+
+      // If the fieldname is a reserved word, rename it to start with
+      // "filename_".
+      int reservedfieldname = 0;
+      for( int j = 0; reservedwords[j]; j++ ){
+	if( !strcmp( fieldname, reservedwords[j] ) ){
+ 	  std::cout << filename << "_" << fieldname << " ";
+ 	  reservedfieldname = 1;
+ 	  break;
+	}
+      }
+      if( !reservedfieldname ){
+	std::cout << fieldname << " ";
+      }
+      switch( SchemaPtr[i].Type ){
+      case 'C':
+	std::cout << "varchar(" << (int)SchemaPtr[i].FieldLen << ")";
+	break;
+      case 'D':
+	std::cout << "date";
+	break;
+      case 'I':
+	std::cout << "integer";
+	break;
+      case 'L':
+	std::cout << "boolean";
+// 	std::cout << "smallint";
+	break;
+      case 'M':
+	std::cout << "text";
+	break;
+      case 'N':
+	std::cout << "text";
+	// std::cout << "numeric(" << (int)SchemaPtr[i].FieldLen << ", " <<
+	//   (int)SchemaPtr[i].NoOfDecs << ")";
+	break;
+      case 'T':
+	std::cout << "timestamp";
+	break;
+      }
+    }
+  }
+  std::cout << ");" << std::endl;
+  return XB_NO_ERROR;
+}
 #endif
 /************************************************************************/
+//! Lowercase a string.  We don't do this often, so there's no point importing
+/*!
+  We don't do this very often, so it's probably not worth importing another
+  external library just for the sake of this one function.
+*/
+xbShort xbDbf::LowerCase( char * Buf )
+{
+  size_t length = strlen( Buf );
+  for( int j = 0; j < length; j++ ){
+    Buf[j] = towlower( Buf[j] );
+  }
+  return 0;
+}
+/************************************************************************/
+//! Return the name of this table, minus leading paths and trailing extensions
+/*!
+*/
+xbShort xbDbf::GetTableName( char * Buf )
+{
+  char filename[4096];
+
+  strncpy( filename, GetFileName(), 4096 );
+  LowerCase( filename );
+  size_t length = strlen( filename );
+  int lastslash = -1;
+  for( int i = length - 1; i >= 0; i-- ){
+    if( filename[i] == '.' ){
+      filename[i] = '\0';
+    }
+  }
+  for( int i = 0; i < length; i++ ){
+    if( filename[i] == '/' ){
+      lastslash = i;
+    }
+  }
+  strcpy( Buf, filename + lastslash + 1 );
+  return 0;
+}
+/************************************************************************/
 //! Open the DBF file.
 /*!
   This method attempts to open the DBF file with the specified
@@ -1471,6 +1588,107 @@
   return XB_NO_ERROR;
 }
 /************************************************************************/
+//! PostgreSQL dump record
+/*!
+  Dump the contents of the specified record to stdout in a format compatible
+  with PostgreSQL's "copy from" command.
+
+  \param RecNo Record number of record to be dumped.
+  \returns An error code (same as GetRecord()).
+*/
+xbShort xbDbf::PgDumpRecord( xbULong RecNo )
+{
+  int  i, j, printed, rc;
+  char buf[4096];
+  char riskybuf[4096];
+
+  if( RecNo == 0 || RecNo > NoOfRecs )
+    return XB_INVALID_RECORD;
+
+  rc = GetRecord( RecNo );
+  if( rc != XB_NO_ERROR )
+    return rc;
+
+  if( RecordDeleted() )
+    return 0;
+
+  printed = 0;
+  for( i = 0; i < NoOfFields; i++ ){
+#ifdef XB_MEMO_FIELDS
+    switch( SchemaPtr[i].Type ){
+    case 'D':
+      // Handle datestamps
+      GetField( i, buf );
+      if( !strcmp( buf, "        " ) ){
+	buf[0] = '\\';
+	buf[1] = 'N';
+	buf[2] = 0x00;
+      }
+      break;
+    case 'I':
+      // Handle packed integers
+      snprintf( buf, 4096, "%d", GetLongPackedField( i ) );
+      break;
+    case 'L':
+      // Boolean values
+      GetField( i, buf );
+      switch( buf[0] ){
+      case 'T':
+	buf[0] = '1';
+	break;
+      default:
+	buf[0] = '0';
+      }
+      break;
+    case 'M':
+      // Handle memo fields
+      if( MemoFieldExists( i )){
+        // memset( riskybuf, 0x00, 4095 );
+        rc = GetMemoField(i, 4095, riskybuf, 0);
+        if(rc != XB_NO_ERROR)
+          return rc;
+      } else {
+	riskybuf[0] = 0x00;
+      }
+      PgEscapeField( riskybuf, buf, 4096 );
+      break;
+    case 'T':
+      // Handle datetime values
+      GetDatetimeField( i, buf );
+      if( !strcmp( buf, "11/25/1956 00:00:00" ) ){
+	buf[0] = '\\';
+	buf[1] = 'N';
+	buf[2] = 0x00;
+      }
+      break;
+    case '0':
+      continue;
+    default:
+      // Escape the values in string fields
+      char riskybuf[4096];
+      GetField( i, riskybuf );
+      PgEscapeField( riskybuf, buf, 4096 );
+      break;
+    }
+
+    // Print a tab separator before every field after the first
+    if( printed ){
+      std::cout << "\t";
+    }
+    else{
+      printed = 1;
+    }
+
+    std::cout << buf;
+#else
+    GetField( i, buf );
+    std::cout << buf;
+#endif
+  }
+  std::cout << std::endl;
+  return XB_NO_ERROR;
+}
+/************************************************************************/
 //! Write the current record buffer to the current record in the data file.
 /*!
   Attempts to write the contents of the record buffer to the current
diff -urN xbase64-3.1.2-old/xbase64/xbdbf.h xbase64-3.1.2/xbase64/xbdbf.h
--- xbase64-3.1.2-old/xbase64/xbdbf.h	2006-07-17 11:54:50.000000000 -0500
+++ xbase64-3.1.2/xbase64/xbdbf.h	2008-01-11 13:17:01.000000000 -0600
@@ -213,7 +213,11 @@
 #ifdef XBASE_DEBUG
   xbShort   DumpHeader( xbShort );
 #endif
+  xbShort   PgDumpHeader();
+  xbShort   LowerCase( char * Buf );
+  xbShort   GetTableName( char * Buf );
   xbShort   DumpRecord( xbULong );
+  xbShort   PgDumpRecord( xbULong );
   //! Return number of fields
   /*!
   */
@@ -294,6 +298,17 @@
   xbShort   ValidLogicalData( const char * );
   xbShort   ValidNumericData( const char * );
 
+  xbShort   GetDatetimeField( const char *FieldName, char *Buf) const;
+  xbShort   GetDatetimeField( xbShort FieldNo, char *Buf) const;
+
+  xbLong    UnpackLong( const char *PackedValue ) const;
+  xbShort   MakeDate( const xbLong DateValue, char *Buf ) const;
+  xbShort   MakeTime( const xbLong TimeValue, char *Buf ) const;
+  xbShort   EscapeCharacter( const char Src, char *Dest ) const;
+  xbShort   PgEscapeField( const char *Src, char *Dest, const int maxsize ) const;
+  xbLong    GetLongPackedField( const char *FieldName ) const;
+  xbLong    GetLongPackedField( const xbShort FieldNo ) const;
+
   xbLong    GetLongField( const char *FieldName) const;
   xbLong    GetLongField( const xbShort FieldNo) const;
   xbShort   PutLongField( const xbShort, const xbLong );
diff -urN xbase64-3.1.2-old/xbase64/xbfields.cpp xbase64-3.1.2/xbase64/xbfields.cpp
--- xbase64-3.1.2-old/xbase64/xbfields.cpp	2006-07-17 11:54:42.000000000 -0500
+++ xbase64-3.1.2/xbase64/xbfields.cpp	2008-01-11 13:17:01.000000000 -0600
@@ -480,6 +480,166 @@
   return GetField(FieldNo, buf, 0);
 }
 /************************************************************************/
+//! Get the value of the specified field, where the value
+//! in the field is a datetime string.
+/*!
+*/
+xbShort xbDbf::GetDatetimeField( xbShort FieldNo, char *Buf) const
+{
+  char localbuf[12];
+  xbLong unpacked;
+  memset( localbuf, 0x00, 12 );
+  GetField( FieldNo, localbuf );
+  unpacked = UnpackLong( localbuf );
+  MakeDate( unpacked, Buf );
+  Buf[10] = ' ';
+  unpacked = UnpackLong( localbuf + 4 );
+  MakeTime( unpacked, Buf + 11 );
+  return 0;
+}
+/************************************************************************/
+//! Get the value of the specified field, where the value
+//! in the field is a datetime string.
+/*!
+*/
+xbShort xbDbf::GetDatetimeField( const char *FieldName, char *Buf) const
+{
+  return( GetDatetimeField( GetFieldNo( FieldName ), Buf ));
+}
+/************************************************************************/
+//! Convert a 4-byte packed little-endian value into a long.
+/*!
+*/
+xbLong xbDbf::UnpackLong( const char *PackedValue ) const
+{
+  xbLong a = (PackedValue[3] & 255) << 24 |
+             (PackedValue[2] & 255) << 16 |
+             (PackedValue[1] & 255) << 8  |
+             (PackedValue[0] & 255);
+  return a;
+}
+/************************************************************************/
+//! Convert a long number of days since Jan. 1, 4713BC (?!?!?) to YYYY/MM/DD.
+/*!
+*/
+xbShort xbDbf::MakeDate( const xbLong DateValue, char *Buf ) const
+{
+  // XBase has the screwiest time base I've ever seen.  So, subtract the
+  // number of days from XBase epoch to the Unix epoch and use POSIX
+  // time functions to calculate dates.
+  time_t SecondsSinceEpoch;
+  SecondsSinceEpoch = (DateValue - 2440588) * 86400;
+  strftime( Buf, 11, "%m/%d/%Y", gmtime( &SecondsSinceEpoch ) );
+  return 0;
+}
+/************************************************************************/
+//! Convert a long number of milliseconds since midnight to HH:MM:SS.
+/*!
+*/
+xbShort xbDbf::MakeTime( const xbLong TimeValue, char *Buf ) const
+{
+  // FoxPro rounds down one millisecond, so account for that.
+  xbLong msec = TimeValue + 1;
+  xbShort hours = msec / 3600000;
+  msec = msec - hours * 3600000;
+  xbShort minutes = msec / 60000;
+  xbShort seconds = (msec - minutes * 60000) / 1000;
+  sprintf( Buf, "%02d:%02d:%02d", hours, minutes, seconds);
+  return 0;
+}
+/************************************************************************/
+//! Escape an entire string of untrusted data by removing characters
+//! that might interfere with PostgreSQL's COPY FROM.
+/*!
+*/
+xbShort xbDbf::PgEscapeField( const char *Src, char *Dest, const int maxcopy ) const
+{
+  // An escaped character and its length
+  char       escaped;
+  xbShort    esclength = 0;
+  // Length of the new target string
+  xbShort    destlength = 0;
+  // Convert a length to an index (length - 1) and leave room for the
+  // terminating zero.
+  xbShort    highestindex = maxcopy - 2;
+  // Pointers to the source and target strings
+  const char *sp = Src;
+  char       *tp = Dest;
+
+  while( *sp != 0x00 ){
+    switch( *sp ){
+    case '\\':
+      escaped = '\\';
+      esclength = 1;
+      break;
+    case '\n':
+      escaped = 'n';
+      esclength = 1;
+      break;
+    case '\r':
+      escaped = 'r';
+      esclength = 1;
+      break;
+    case '\t':
+      escaped = 't';
+      esclength = 1;
+      break;
+    }
+
+    // If the resulting string would be too long, exit
+    if( destlength + esclength > highestindex ){
+      break;
+    }
+
+    // If the character was not escaped, write it verbatim
+    if( !esclength ){
+      *tp++ = *sp;
+      destlength += 1;
+    } else {
+      // Otherwise, write the escaped version
+      *tp++ = '\\';
+      *tp++ = escaped;
+      destlength += 2;
+      // Reset esclength for the remaining iterations
+      esclength = 0;
+    }
+    sp++;
+  }
+
+  // Terminate the string
+  *tp = 0x00;
+
+  // Strip off trailing spaces by replacing them with end-of-string
+  // until we reach a non-space or the beginning of the string
+  while( tp != Dest && *--tp == ' ' ){
+    *tp = 0x00;
+    destlength--;
+  }
+
+  return destlength;  
+}
+/************************************************************************/
+//! Get the long value of the specified field, where the value
+//! in the field is a packed integer.
+/*!
+*/
+xbLong xbDbf::GetLongPackedField( xbShort FieldNo ) const
+{
+  char buf[18];
+  memset( buf, 0x00, 18 );
+  GetField( FieldNo, buf );
+  return UnpackLong ( buf );
+}
+/************************************************************************/
+//! Get the long value of the specified field, where the value
+//! in the field is a packed integer.
+/*!
+*/
+xbLong xbDbf::GetLongPackedField( const char * FieldName ) const
+{
+  return( GetLongPackedField( GetFieldNo( FieldName )));
+}
+/************************************************************************/
 //! Get the long value of the specified field.
 /*!
 */
diff -urN xbase64-3.1.2-old/xbase64/xbmemo.cpp xbase64-3.1.2/xbase64/xbmemo.cpp
--- xbase64-3.1.2-old/xbase64/xbmemo.cpp	2006-07-17 11:54:42.000000000 -0500
+++ xbase64-3.1.2/xbase64/xbmemo.cpp	2008-01-11 13:17:01.000000000 -0600
@@ -1096,10 +1096,23 @@
 */
 xbShort xbDbf::MemoFieldExists( xbShort FieldNo ) const
 {
-  if( GetLongField( FieldNo ) == 0L )
-     return 0;
-  else
-     return 1;
+  xbLong BlockNo;
+  char buf[18];
+
+  if( Version == (char)0x30 ) {
+    memset( buf, 0x00, 18 ) ;
+    GetField( FieldNo, buf );
+    BlockNo = xbase->GetLong((char*) buf);
+  } else {
+    BlockNo = GetLongField(FieldNo);
+  }  
+
+  if( BlockNo == 0L ){
+    return 0;
+  }
+  else{
+    return 1;
+  }
 }
 /***********************************************************************/
 //! Short description
diff -urN xbase64-3.1.2-old/xbase64/xbnode.cpp xbase64-3.1.2/xbase64/xbnode.cpp
--- xbase64-3.1.2-old/xbase64/xbnode.cpp	2006-07-17 11:54:42.000000000 -0500
+++ xbase64-3.1.2/xbase64/xbnode.cpp	2008-01-11 13:17:01.000000000 -0600
@@ -1,4 +1,4 @@
-#include "xbNode.h"
+#include "xbnode.h"
 
 void xbNodeLink::AddNode(xbNodeLink* node)
 {
diff -urN xbase64-3.1.2-old/xbase64/xbtypes.h xbase64-3.1.2/xbase64/xbtypes.h
--- xbase64-3.1.2-old/xbase64/xbtypes.h	2006-07-17 11:54:50.000000000 -0500
+++ xbase64-3.1.2/xbase64/xbtypes.h	2008-01-11 13:17:01.000000000 -0600
@@ -40,6 +40,7 @@
 #define __XB_XTYPES_H__
 
 #include <stdio.h>
+#include <sys/types.h>
 
 /*! \file xbtypes.h
 */