home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / database / bfast / bfast.doc next >
Encoding:
Text File  |  1992-09-09  |  12.6 KB  |  440 lines

  1. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2.                       bFAST version 1.1
  3.                       Wed  09-09-1992
  4.  
  5.            C++ class library for Btrieve file manipulation
  6.  
  7.                   Copyright (c) 1992 by Chao Lin Chang
  8.  
  9.            Chao Lin Chang
  10.            34 Bettina Street, Clayton,
  11.            Vic., Australia, 3168
  12.  
  13.            Voice: +61 3 565-2360
  14.            Fax  : +61 3 565-5159
  15.  
  16.            Internet: chaolin@fcit-m1.fcit.monash.edu.au
  17.  
  18.           This library is distributed as is. The author assumes no
  19.           liability for any damages resulting from its use.
  20. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  21. !!README FIRST!!
  22.  
  23.           After months of thoughts, I decide to release bFast 1.1 into
  24.           public domain.  I would like to share it with you.
  25.  
  26.           You are FREE to use it any of your applications, provided
  27.           you would kindly inform me that.
  28.  
  29.           Though it is FREE, it is fully functioning.  No trick, no nagging
  30.           message.  It is the same code I used to write my app.
  31.  
  32.           No much is changed in the C++ part.  I only did some patch up
  33.           and add a new function to return the number of records.
  34.  
  35.           However, in this release I include some of my old
  36.           routines written in C, compiled in C++ though.
  37.  
  38.           Following is the function prototype.  You can use of course, but
  39.           I would not recommend it.
  40.  
  41.             // ------------------------------------------------------
  42.             //  btrieve function
  43.             // ------------------------------------------------------
  44.             int b_reset(void);
  45.             int b_begin(void)     ;
  46.             int b_end(void)       ;
  47.             int b_abort(void)     ;
  48.             int b_close(char *unit);
  49.             int b_unlock(char *unit);
  50.             int b_read(char *unit,int key_num,int op_num,void *key_value,void *key_buf);
  51.             int b_create(char *file,int key_num,void *key_buf);
  52.             int b_stat(char *unit,void *data_buf, char *key_buf);
  53.             int b_write(char *unit, int key_num, void *key_buf);
  54.             int b_rewrite(char *unit, int key_num, void *key_buf);
  55.  
  56.           Also one thing now I am working on is to allow bFast to read data
  57.           structure from DDF files (created by Xtrieve).  So the data
  58.           structure need not to be hard-coded.
  59.  
  60. THANKS FOR YOUR ATTENTION.
  61. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  62. FILES INCLUDED
  63. --------------
  64. The library included here is compiled by Borland C++ 3.0.
  65. If you are using different compiler, let me know.
  66. I see if I can create a specific library for you.
  67.  
  68. BFAST.DOC       // Documentation
  69. BFAST.LIB       // Borland C++ 3.0 library
  70. RDBMS.HPP       // where the class Rdbms is defined
  71. FIELD.HPP       // where the class Field is defined
  72. BTRIEVE.HPP     // where the class Btrieve is defined
  73.  
  74. DEMO.CPP        // demo file
  75. ORDER.DEF       // demo field definition file
  76. ORDER.DAT       // demo order data file
  77. ORDER.HPP       // demo field symbol file
  78. DEMO.EXE        // demonstration program
  79.  
  80. BROWSE.CPP      // demo of browse
  81. BROWSE.EXE      // browse demo program
  82.  
  83.  
  84. WHAT IS bFAST?
  85. --------------
  86. bFAST is not developed to meet the market needs.
  87. Instead, it is here because I need such a library for my project.
  88. My project has 10+ executable files and 100+ source files.
  89. This small library works fine for my project.
  90. So, I think it should work for your project as well.
  91. This library, by no means, has included all the functions offered by Btrieve.
  92. Yet, it is sufficient for almost any project.
  93. Given that you are not using transaction or external index.
  94.  
  95. If you happen to use those functions not included.
  96. Luckily, now we are in the world of C++.
  97. You can easily create a derived class from the class Btrieve to do whatever
  98. bFAST has not implemented.
  99.  
  100. bFAST has the following class hierarchy
  101.  
  102. Rdbms         Field
  103.    └─────┬──────┘
  104.       Btrieve
  105.  
  106. If you like, you can use the base class Rdbms to derive another class
  107. for accessing Xbase files.  In this way, you will be able to access
  108. different data files using the same source code.
  109.  
  110. I would like to share bFAST with anyone who is interesting in it.
  111. Any of your comments will be greatly appreciated.
  112.  
  113. --------------------------------------------------------------------------
  114. To use bFAST is simple, just follow the 4 steps below.
  115.  
  116. 4 STEPS TO USE bFAST
  117.  
  118. Step 0 - acquire rdbms.hpp field.hpp btrieve.hpp bfast.lib
  119. Step 1 - create file definition file            *.def
  120. Step 2 - create field symbol file               *.hpp
  121. Step 3 - include bFAST.LIB in your project file
  122.  
  123. Step 0
  124. I assume that you know where to put the *.hpp file and *.lib file.
  125. Therefore, let's skip the step 0.
  126.  
  127. Step 1
  128. CREATE FILE DEFINITION FILE     *.DEF
  129.  
  130.     structure for each field
  131.  
  132.     typedef struct
  133.     {
  134.         char* FldName;  // field title
  135.         char  FldType;
  136.         int   offset;
  137.         int   FldLen;
  138.     }Field;
  139.  
  140.     Eg. contents of a .def file
  141.  
  142.     #include "field.hpp"
  143.  
  144.     #define  ORDER_FIELD        17
  145.  
  146.     Field cord[]={
  147.     {"Order Reference"   ,'c',0                                         ,13},
  148.     {"Customer"          ,'c',13                                        ,13},
  149.     {"Date Ordered"      ,'c',13+13                                     ,9 },
  150.     {"Note"              ,'c',13+13+9                                   ,49},
  151.     {"Open/Close"        ,'c',13+13+9+49                                ,2 },
  152.     {"Customer branch"   ,'c',13+13+9+49+2                              ,13},
  153.     {"Time Ordered"      ,'c',13+13+9+49+2+13                           ,9 },
  154.     {"Personal contact"  ,'c',13+13+9+49+2+13+9                         ,21},
  155.     {"Service type"      ,'c',13+13+9+49+2+13+9+21                      ,13},
  156.     {"Contract reference",'c',13+13+9+49+2+13+9+21+13                   ,13},
  157.     {"Sales tax number"  ,'c',13+13+9+49+2+13+9+21+13+13                ,13},
  158.     {"Customer account"  ,'l',13+13+9+49+2+13+9+21+13+13+13             ,4 },
  159.     {"Salesman"          ,'c',13+13+9+49+2+13+9+21+13+13+13+4           ,13},
  160.     {"Sales area"        ,'c',13+13+9+49+2+13+9+21+13+13+13+4+13        ,13},
  161.     {"Sales code"        ,'c',13+13+9+49+2+13+9+21+13+13+13+4+13+13     ,13},
  162.     {"Deduct forecast"   ,'c',13+13+9+49+2+13+9+21+13+13+13+4+13+13+13  ,2 },
  163.     {"Text"              ,'c',13+13+9+49+2+13+9+21+13+13+13+4+13+13+13+2,59},
  164.     };
  165.  
  166. Step 2
  167. CREATE FIELD SYMBOL FILE        *.HPP
  168.  
  169. The field symbol file is used to accessed a field, either
  170. replace the contents of a field or retrieve the contents of a field.
  171. You can find example in the end of the function lists.
  172.  
  173.     eg. contents of a .hpp file
  174.  
  175.     #define ORDER_REFERENCE          0
  176.     #define CUSTOMER                 1
  177.     #define DATE_ORDERED             2
  178.     #define NOTE                     3
  179.     #define OPEN_CLOSE               4
  180.     #define CUSTOMER_BRANCH          5
  181.     #define TIME_ORDERED             6
  182.     #define PERSONAL_CONTACT         7
  183.     #define SERVICE_TYPE             8
  184.     #define CONTRACT_REFERENCE       9
  185.     #define SALES_TAX_NUMBER         10
  186.     #define CUSTOMER_ACCOUNT         11
  187.     #define SALESMAN                 12
  188.     #define SALES_AREA               13
  189.     #define SALES_CODE               14
  190.     #define DEDUCT_FORECAST          15
  191.     #define TEXT                     16
  192.  
  193.  
  194. FUNCTION LISTS
  195. --------------------------------------------------------------------------
  196. //
  197. // after any function call, you can always use
  198. // Err()
  199. // to check if the operation is successful.
  200. //
  201. Open a file
  202.     Btrieve(char* path, char *filename,Field xfld[],int fldNo,int keyNo=0);
  203.  
  204.     eg.
  205.         Btrieve f("", "ORDER.DAT", cord, ORDER_FIELD);
  206.  
  207.         This statement open file ORDER.DAT in current working directory.
  208.         Its field definition is defined in cord.
  209.         It has ORDER_FIELD number of fields.
  210.         The defualt key is used, whihc is key 0.
  211.  
  212.  
  213.         Btrieve f("C:\\DAT", "ORDER.DAT", cord, ORDER_FIELD);
  214.  
  215.         this statement open file ORDER.DAT in directory C:\DAT
  216.  
  217.  
  218. Deconstructor
  219.     ~Btrieve();
  220.  
  221.     ~Btrieve will automatically close a file
  222.  
  223. --------------------------------------------------------------------------
  224. FILE STATUS
  225. -----------
  226. Get the file name
  227.         char* FileName(void);
  228.  
  229. Get the current working directory
  230.         char* Path(void);
  231.  
  232. Return the error code
  233.         int Err(void);
  234.  
  235. Length of a index key
  236.     int KeyLength(int keyNo);
  237.     int KeyLength(void);
  238.  
  239. Index key currently used
  240.     int IndexNo(void);
  241.  
  242. Change index key
  243.     int UseIndex(int key=0);
  244.  
  245. Current index key value
  246.     char * KeyValue();
  247.  
  248. Length of record buffer
  249.     int DataLen(void);
  250.  
  251. Open a file (internal use)
  252.     int Open(void);
  253.  
  254. Close a file
  255.     int Close(void);
  256.  
  257. Check if end of a file
  258.     int Eof(void);
  259.  
  260. Check if beginning of a file
  261. 2    int Bof(void);
  262.  
  263. Check if a empty file
  264.     int Empty(void);
  265.  
  266. Unlock a record
  267.     int Unlock(void);
  268.  
  269.  Count the Number of records in file (new)
  270.     long RecCount();
  271.  
  272. ----------------------------------------------------------------------------
  273. RECORD ACCESSING
  274. ----------------
  275. Indexed file
  276. Get the first record
  277.     int GetFirst(int lock=0);
  278.  
  279. Get the record which the key is equal to specified value
  280.     int GetEqual(char* keyvalue, int lock=0);
  281.  
  282. Get the last record
  283.     int GetLast(int lock=0);
  284.  
  285. Get the next record
  286.     int GetNext(int lock=0);
  287.  
  288. Get the previous record
  289.     int GetPrev(int lock=0);
  290.  
  291. Get the record which the key is greater or equal to a specified value
  292.     int GetGEqual(char* keyvalue, int lock=0);
  293.  
  294.  
  295. Get the record which the key is greater to a specified value
  296.     int GetGreater(char* keyvalue, int lock=0);
  297.  
  298. Get the physical position of current record
  299.     long GetPost(int lock=0);
  300.  
  301. Go to specified physical position
  302.     int GoTo(long,int lock=0);
  303.     
  304. Sequential file
  305. ---------------
  306. Get the first record
  307.     int StepFirst(int lock=0);
  308.  
  309. Get the last record
  310.     int StepLast(int lock=0);
  311.  
  312. Get the next record
  313.     int StepNext(int lock=0);
  314.  
  315. Get the previous record
  316.     int StepPrev(int lock=0);
  317.  
  318. --------------------------------------------------------------------------
  319. FILE UPDATION
  320. -------------
  321. Rewrite the record
  322.     int Rewrite(void);
  323.  
  324. Inser a new record
  325.     virtual int Write(void);
  326.  
  327. Delete the current record
  328.     int Delete(void);
  329.  
  330.  
  331. --------------------------------------------------------------------------
  332. FIELD MANIPULATION
  333. ------------------
  334. //
  335. // In field manipulation, every field can be referenced either by
  336. //
  337. // 1. using its field name, which is defined in the structure Field
  338. //
  339. // eg.
  340. //    f.fReplace("Order Reference", "123456789012");
  341. //
  342. // 2. using its relative position from the first field, which is defined
  343. //    to zero.
  344. //
  345. // eg.
  346. //
  347. //    #define SALES_ORDER_REF   0
  348. //    #define CUSTOMER          1
  349. //
  350. //
  351. //    f.fReplace(SALES_ORDER_REF, "123456789012");
  352. //    f.fReplace(CUSTOMER,        "ABC Co.");
  353. //
  354. //
  355. UPDATE A FIELD
  356. --------------
  357. //
  358. // All fReplace() return
  359. // 1 - successful
  360. // 0 - error
  361. //
  362. Replace a string field
  363.     int fReplace(int ,char *  );
  364.     int fReplace(char* ,char *  );
  365.  
  366. Replace an integer field
  367.     int fReplace(int ,int  );
  368.     int fReplace(char*,int  );
  369.  
  370. Replace a long field
  371.     int fReplace(int ,long );
  372.     int fReplace(char*,long );
  373.  
  374. Replace a float field
  375.     int fReplace(int ,float);
  376.     int fReplace(char*,float);
  377.  
  378. Replace a double field
  379.     int fReplace(int ,double);
  380.     int fReplace(char*,double);
  381.  
  382. GET THE CONTENTS OF A FIELD
  383. ---------------------------
  384. //
  385. Get every type of field in string format
  386.  
  387.     char* fStr(int i=0, const char *ptemplate="%s");
  388.     char* fStr(char * str, const char *ptemplate="%s");
  389.  
  390.     eg.
  391.          #define SALES_ORDER_REF   0
  392.          #define CUSTOMER          1
  393.  
  394.          char salesOrder[13];
  395.  
  396.          strcpy(salesOredr, f.fStr(SALES_ORDER_REF));
  397.  
  398.          or
  399.  
  400.          strcpy(salesOredr, f.fStr("Order Reference"));
  401.  
  402.  
  403.  
  404. Get a character field
  405.  
  406.     char   fChar(int);
  407.     char   fChar(char *  );
  408.  
  409.     #define ORDER_REFERENCE     0
  410.     #define CUSTOMER            1
  411.     #define DATE_ORDERED        2
  412.     #define NOTE                3
  413.     #define OPEN_CLOSE          4
  414.  
  415.     if (f.fChar(OPEN_CLOSE)=='Y')
  416.        ...
  417.  
  418.  
  419. Get an integer field
  420.  
  421.     int   fInt(int);
  422.     int   fInt(char *  );
  423.  
  424.  
  425. Get a long field
  426.  
  427.     long  fLong(int);
  428.     long  fLong(char * );
  429.  
  430. Get a float field
  431.  
  432.     float fFloat(int);
  433.     float fFloat(char *);
  434.  
  435. Get a double field
  436.  
  437.     double  fDouble(int);
  438.     double  fDouble(char *);
  439.  
  440.