summaryrefslogtreecommitdiff
path: root/docs/html/xbc15.html
blob: fde33b8567dfd03221eaf667675332019e582ea1 (plain)
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

<!DOCTYPE HTML PUBLIC>
<HTML>
<TITLE>Xbase DBMS Chapter 15</TITLE>
<BODY BGCOLOR=#FFFFFF>
<H2><p align="center">Block Read Functionality</p></H2>
<p align="center">Chapter Updated 2/1/23</p><hr>


<h3>Block Reads</h3>

As of release 4.1.1, the Xbase library includes functionality for reading a DBF file in blocks, rather than one record at a time.<br><br>

This functionality can be used to improve application performance in situations where a data file is being read sequentially.
For situations where records are retrieved randomly from the file, enabling this probably won't help much.  In short, this 
can be turned on when accessing a file sequentially and should be left off when not processing sequentially.<br><br>

The logic is all handled internally within the library, all that is needed is to enable it and the library handles the rest.<br><br>

<h3>One Caveat</h3>
This functionality was originally designed with reporting in mind and doesn't currently have any auto locking associated with it.
<br><br>


<h3>Sample Code</h3>
See example code below for how to enable and disable the feature.


<hr>

#include "xbase.h"<br>
using namespace xb;<br>
<br>
int main(int ac,char** av)<br>
{<br>
  xbXBase x;<br>
  xbInt16 iRc;<br>
  x.EnableMsgLogging();<br>
  x.SetLogSize( 1000000L );<br>
<br>
  if (ac <= 1) {<br>
    std::cout << "Usage: xb_dumprecs filename..." << std::endl;<br>
    return 1;<br>
  }<br>
<br>
  xbDbf *MyFile = NULL;<br>
  if(( iRc = x.OpenHighestVersion( av[1], "", &MyFile )) != XB_NO_ERROR ){<br>
    std::cout << "Could not open file iRc = " << iRc  << " file = "  << av[1] << std::endl;<br>
    x.DisplayError( iRc );<br>
    return 0;<br>
  }<br>
<br>
//  std::cout << "Processing file sequentially from beginning..." << std::endl;<br>
<br>
<br>
<b>
  // turn on Block Read Processing<br>
  #ifdef XB_BLOCKREAD_SUPPORT<br>
  MyFile->EnableBlockReadProcessing();<br>
  #endif<br>
</b>
<br>
  xbUInt32 j = 0;<br>
  xbUInt32 ulRecCnt = 0;<br>
<br>
  iRc = MyFile->GetRecordCnt( ulRecCnt );<br>
<br>
  if( iRc < XB_NO_ERROR )<br>
    return iRc;<br>
  while( j < ulRecCnt ){<br>
    if( j == 0 )<br>
      iRc = MyFile->DumpRecord(++j, 2, 2 );<br>
    else<br>
      iRc = MyFile->DumpRecord(++j, 2, 1 );<br>
    if( iRc != XB_NO_ERROR ){<br>
      x.DisplayError( iRc );<br>
      return 1;<br>
    }<br>
  }<br>
  std::cout << j << " Records processed." << std::endl;<br>
<br>
<br><b>
  // optionally turn off Block Read Processing<br>
  #ifdef XB_BLOCKREAD_SUPPORT<br>
  MyFile->DisableBlockReadProcessing();<br>
  #endif<br></b>
<br>
  MyFile->Close();<br>
  return 0;<br>
}<br>
<br>

<hr>
<p><img src="xbase.jpg"><hr>
</BODY>
</HTML>