home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / basic / bltq18.zip / !Q&A.TXT < prev    next >
Text File  |  1993-08-04  |  10KB  |  214 lines

  1. Questions & Answers
  2. BULLET v1.0
  3.  
  4. Q: What is BULLET?
  5.  
  6. A: BULLET is a library of program modules that together let the programmer
  7.    develop and create software that can manage huge amounts of data on
  8.    disk using the industry-standard DBF data file format. It also uses high-
  9.    speed b-tree index files to manage keyed data file access.
  10.  
  11.  
  12. Q: What compiler is BULLET for?
  13.  
  14. A: BULLET can be used by nearly all DOS compilers. It's written entirely in
  15.    assembly language. Because of this, it does not require any particular
  16.    programming language or compiler vendor. The 4 requirements are listed
  17.    in the !WHATIS.TXT file.
  18.  
  19.  
  20. Q: Why do I need BULLET when all I need to handle are small amounts of data?
  21.  
  22. A: BULLET can deal with a database as small as 1 record or as large as several
  23.    million. While your current needs may be small, your future needs are bound
  24.    to expand. BULLET can work with you now, and later, even if you switch
  25.    development platforms by moving to another compiler. And BULLET is fast,
  26.    it can deal with a database with millions of records as easily as it can
  27.    with just a few.
  28.  
  29.  
  30. Q: But b-tree stuff, isn't that hard?
  31.  
  32. A: Everything associated with maintaining the database, its data files and its
  33.    index files, is done behind-the-scenes by BULLET. You just specify how the
  34.    data record is to look by specifying the number of fields, their lengths and
  35.    types, and then specify how you want your index files to be based.
  36.  
  37.  
  38. Q: So how do I design my data record?
  39.  
  40. A: You probably have a pretty good idea, already. A good way to determine what
  41.    should go into a database is what you want to come out of it. For example,
  42.    if you're doing a mailing list program, you'll want to have at least the
  43.    name, perhaps broken into first name and last. Also you'll need the mailing
  44.    address--4 lines is usually enough, so you'll want 4 separate address line
  45.    fields. Then there's the State and ZIP, possibly even country. That's the
  46.    minimum. It would look something like this:
  47.  
  48.    FIRSTNAME field of 15 characters; LASTNAME field of 19 characters; ADDR1
  49.    field of 34 characters, ADDR2, ADDR3, ADDR4 as ADDR1; State field of 2
  50.    characters, and ZIP a field of 5 (or 9 if ZIP+4) characters. You could
  51.    specify the ZIP as a numeric field if you wanted.
  52.  
  53.    You'll notice that the longest field is 34 characters. Why? Because most
  54.    mailing labels are 3.5 inches, about 34 characters across. Since the first
  55.    name and last are usually put on the same line, their total should be 34.
  56.  
  57.    You'll probably want to add more fields like telephone number, last time
  58.    written to, oh, just about anything that you'd think would be important to
  59.    know. There you go, you've just designed your data record.
  60.  
  61.  
  62. Q: Then what?
  63.  
  64. A: Then decide how you need to access this data. You'll want to access it at
  65.    least by name, so one index you'll want is on the name. While you could
  66.    specify the entire name be used as a key, say LASTNAME+FIRSTNAME, this is
  67.    a bit of overkill. Instead, you may want to use just a portion of the name.
  68.    A good candidate would be SUBSTR(LASTNAME,1,5)+SUBSTR(FIRSTNAME,1,1). This
  69.    sets up a key that's only 6 bytes long. The first method, using all the
  70.    name, would be 34 bytes long. By keeping your keys short you'll keep your
  71.    index files small and your index performance high. And yes, you can also
  72.    mix numeric field types with character field types in your key expressions.
  73.  
  74.  
  75. Q: But what if I have two or more names that are identical, or very similar
  76.    but have these parts of the names the same?
  77.  
  78. A: BULLET lets you specify if your index files allow only unique key entries or
  79.    whether duplicate keys are permitted. When keying on a name you should have
  80.    your index file allow duplicate keys. What BULLET does is number these
  81.    identical keys by adding a suffix to each key (called an enumerator). This
  82.    enumerator allows the index algorithm to treat each key as a different key.
  83.    If you search the index for all matches in the first 6 characters of the
  84.    key (the enumerators will always be different) these similar names will
  85.    be found in consecutive order. To find out if the key you've just accessed
  86.    is the actual person you had in mind, you'd scan the data record associated
  87.    with that key for other information, such as middle initial, address,
  88.    anything that would make that person recognizable from another with a
  89.    similar key. If it isn't what you're looking for, get the next key and data
  90.    record, and so on until the first 6 characters of the key no longer are the
  91.    6 you're looking for.
  92.  
  93.  
  94. Q: So I've got my data record designed and also my primary index file. What
  95.    else should I do?
  96.  
  97. A: Now that the database is designed most of the "unknown" is taken care of.
  98.    What comes next depends on how you, yourself, program. What I often do
  99.    next is detail exactly what I want the output to be. That way, I've got
  100.    the front and the back and just need to do the middle. The middle is where
  101.    the fun's at. You'll be amazed at just how few of your in-the-middle coding
  102.    is spent on managing the database. BULLET takes care of all the little
  103.    details. You just need to give it the data and tell it what to do with
  104.    it. Or you tell it what to get and it comes back with what you requested.
  105.    You then do whatever you want with that data.
  106.  
  107.  
  108. Q: I've looked at the header file and it sure has a lot of commands. You're
  109.    telling me that this is simple?
  110.  
  111. A: Yes. Once you've created your data and index files, those mid-level
  112.    routines are not often used. Almost everything you do in your in-the-middle
  113.    coding will use the high-level routines. The InsertXB and UpdateXB routines
  114.    handle adding new or changing existing data, and the GetFirstXB, GetNextXB,
  115.    etc., routines handle getting the data. 90% of the time these are the
  116.    routines your program will be using.
  117.  
  118.  
  119. Q: What about all those packs? How can I keep them straight?
  120.  
  121. A: The good thing about modern programming langauges is that they let you
  122.    build reusable code. The ideal way to use BULLET is to build reusable
  123.    code objects in your programming langauge of choice and hide the down-and-
  124.    dirty aspects of dealing with the various packs in those objects. For
  125.    example, a create key routine could be written once and that object used
  126.    for all your other programming projects:
  127.  
  128.       DECLARE FUNCTION CreateNewIndex% (filen$, kx$, kflags%, XBlink%)
  129.  
  130.       FUNCTION CreateNewIndex(filename$, kx$, keyflags, XBlink)
  131.  
  132.       DIM CKP AS CreateKeyPack
  133.       DIM TmpFile AS STRING * 80
  134.       DIM TmpExp AS STRING * 136
  135.  
  136.       TmpFile = filename$ + CHR$(0)
  137.       TmpExp = kx$ + CHR$(0)
  138.  
  139.       CKP.Func = CreateKXB
  140.       CKP.FilenamePtrOff = VARPTR(TmpFile)
  141.       CKP.FilenamePtrSeg = VARSEG(TmpFile)
  142.       CKP.KeyExpPtrOff = VARPTR(TmpExp)
  143.       CKP.KeyExpPtrSeg = VARSEG(TmpExp)
  144.       CKP.XBlink = XBlink
  145.       CKP.keyflags = keyflags
  146.       CKP.CodePageID = -1
  147.       CKP.CountryCode = -1
  148.       CKP.CollatePtrOff = 0
  149.       CKP.CollatePtrSeg = 0
  150.       stat = BULLET(CKP)
  151.       CreateNewIndex = stat
  152.  
  153.       END FUNCTION
  154.  
  155.    The TmpFile and TmpExp were used in this QuickBASIC example so that the
  156.    string data is assigned to a fixed-length string. VARSEG/VARPTR operate
  157.    on fixed-length strings identically in both BASIC 7 and QuickBASIC 4.5.
  158.    If you want to forgo this compatibility you could use a var-len string
  159.    and the BASIC SADD() function instead of VARPTR. I find using the
  160.    temporary fixed-length strings just as easy since a CHR$(0) needs to
  161.    be appended to the string in any case. And they are temporary strings--
  162.    as soon as the CreateNewIndex() routine exits, the memory assigned to the
  163.    Tmp strings is released.
  164.  
  165.    So, once you write this create index object, you can reuse it over and
  166.    over again without needing to recode it every time. Just a simple
  167.  
  168.    stat = CreateNewIndex(filename$,keyexpression$,keyflags,XBlink)
  169.  
  170.    is all you need to put in your in-the-middle code. Oh, the key expression,
  171.    keyflags, and XBlink are all explained under CreateKXB in CZ.
  172.  
  173.  
  174. Q: I think I'm getting the hang of it. What's next?
  175.  
  176. A: Jump in and start coding. You may want to look over, maybe even print out,
  177.    one of the example programs. The BB_CAI10.BAS is straight forward, try
  178.    that. If you have any questions, just pop-up CZ. It's all in there.
  179.  
  180.  
  181. Q: Sounds good. But, tell me, what is the first thing I'm likely to muff?
  182.  
  183. A: Nothing serious. Just make sure that your record structure in memory
  184.    reserves the first byte for the delete tag. Also, make sure that the field
  185.    descriptors you assigned when you created the data file match your in-memory
  186.    structure, i.e., if you've created a data file (using CreateDXB) with say, 3
  187.    fields, each 25 characters long, make sure that your in-memory structure is
  188.    also 3 fields, each 25 characters:
  189.  
  190.       TYPE ExampleRecordTYPE
  191.       tag AS STRING * 1
  192.       Field1 AS STRING * 25
  193.       Field2 AS STRING * 25
  194.       Field3 AS STRING * 25
  195.       END TYPE
  196.  
  197.    Note: it is allowable to alias your physical fields but the total length
  198.    must match the total length of the DBF data record. (Alias meaning that
  199.    instead of using Field1 AS STRING * 25, you use Field1a AS STRING 13 and
  200.    Field1b AS STRING 12. Be sure you know what you're doing!--the IDEMO.BAS
  201.    program uses this technique (not in the strict sense of alias) by using a
  202.    single 4000-byte in-memory record since it can't know beforehand what
  203.    structure a random DBF file has.)
  204.  
  205.    Also, the transaction routines (InsertXB, UpdateXB, ReindexXB, and the
  206.    LockXBs) return a transaction index rather than a completion code. Be sure
  207.    to check the documentation for the routines.
  208.  
  209. Q: I'm off.
  210.  
  211. A: So am I, but be sure to...
  212.  
  213.    ...Read the manual! Until you do you can't take full advantage of BULLET.
  214.