home *** CD-ROM | disk | FTP | other *** search
/ Datatid 1999 #6 / Datatid_1999-06.iso / internet / Tango352Promo / P.SQL / PTKPKG.1 / BTR32VBFieldMap.bas < prev    next >
Encoding:
BASIC Source File  |  1998-09-15  |  11.0 KB  |  391 lines

  1. Attribute VB_Name = "BTR32VBFieldMap"
  2. '{*************************************************************************
  3. '**
  4. '**  Copyright 1998 Pervasive Software Inc. All Rights Reserved
  5. '**
  6. '*************************************************************************}
  7. '{*************************************************************************
  8. '**
  9. '**  BTR32VBFieldMap.bas
  10. '**
  11. '**  This software is part of the Pervasive Software Developer Kit.
  12. '**
  13. '**  This source code is only intended as a supplement to the
  14. '**  Pervasive.SQL documentation; see that documentation for detailed
  15. '**  information regarding the use of Pervasive.SQL.
  16. '**
  17. '*************************************************************************}
  18.  
  19. Option Explicit
  20.  
  21. Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
  22.  
  23. '**************************************************************************
  24. 'When compiling a 32-bit application, Visual Basic aligns members of a
  25. 'user-defined data type (UDT) on 8-, 16-, or 32-bit boundaries, depending
  26. 'on the size of that particular member. Unlike structures, database rows
  27. 'are packed, meaning there is no unused space between fields. Because there
  28. 'is no way to turn alignment off, there must be some method to pack and
  29. 'unpack structures so that Visual Basic applications can access a database.
  30. 'The Pervasive Btrieve Alignment DLL, or PAln32.DLL, is designed to handle
  31. 'this structure alignment issue.
  32. '***************************************************************************
  33.  
  34. '**************************************************************************
  35. 'The Pervasive Btrieve Alignment library (PAln32.DLL) is provided in the
  36. 'Pervasive Software Developer's Kit. This library is used for packing aligned
  37. 'structures and unpacking database rows.
  38. '**************************************************************************
  39.  
  40. 'First, before the database can be accessed, there first must exist the
  41. 'required data structures needed to manipulate the data.
  42. 'Here we create structures to hold the data.
  43.  
  44. '**************************************************************************
  45. 'Person Position Block
  46. '**************************************************************************
  47.  
  48. Public Type PosBlock
  49.   buf(0 To 127) As Byte
  50. End Type
  51.  
  52. '***************************************************************************
  53. ' Record type definitions for Version operation
  54. '****************************************************************************
  55.  
  56. Public Type Version_BaseStruct
  57.     version    As Integer
  58.     revision   As Integer
  59.     MKDEId     As String * 1
  60. End Type
  61.  
  62. Public Type Version_Struct
  63.     ver(0 To 2) As Version_BaseStruct
  64. End Type
  65.  
  66.  
  67. Public Type Client_ID
  68.     networkandnode(0 To 11) As Byte
  69.     applicationID(0 To 2)   As Byte
  70.     threadID                As Integer
  71. End Type
  72.  
  73. '***************************************************************************
  74. '  Record type definitions for Stat and Create operations
  75. '****************************************************************************
  76.  
  77. Public Type BtrFileSpec
  78.     length     As Integer
  79.     PageSize   As Integer
  80.     NumIndexes As Integer
  81.     Reserved   As Long
  82.     FileFlags  As Integer
  83.     NumDupPtr  As Byte
  84.     NotUsed    As Byte
  85.     Allocation As Integer
  86. End Type
  87.  
  88. '***************************************************************************
  89. '  Definition of record from 'sample.btr'
  90. '****************************************************************************
  91.  
  92. Public Type PersonRecType
  93.     ID          As Long
  94.     FirstName   As String * 16
  95.     LastName    As String * 26
  96.     Street      As String * 31
  97.     City        As String * 31
  98.     State       As String * 3
  99.     Zip         As String * 11
  100.     Country     As String * 21
  101.     Phone       As String * 14
  102.  End Type
  103.  
  104. '***************************************************************************
  105. '  Record type definitions for Get Next Extended operation
  106. '****************************************************************************
  107.  
  108. Public Type GNE_HEADER
  109.     descriptionLen  As Integer
  110.     currencyConst   As String * 2
  111.     rejectCount     As Integer
  112.     numberTerms     As Integer
  113. End Type
  114.  
  115. Public Type TERM_HEADER
  116.     fieldType       As Byte
  117.     fieldLen        As Integer
  118.     fieldOffset     As Integer
  119.     comparisonCode  As Byte
  120.     connector       As Byte
  121.     value           As String * 3
  122. End Type
  123.   
  124. Public Type RETRIEVAL_HEADER
  125.     maxRecsToRetrieve   As Integer
  126.     noFieldsToRetrieve  As Integer
  127. End Type
  128.  
  129. Public Type FIELD_RETRIEVAL_HEADER
  130.     fieldLen    As Integer
  131.     fieldOffset As Integer
  132. End Type
  133.   
  134. Public Type PRE_GNE_BUFFER
  135.     gneHeader As GNE_HEADER
  136.     term1     As TERM_HEADER
  137.     term2     As TERM_HEADER
  138.     retrieval As RETRIEVAL_HEADER
  139.     recordRet As FIELD_RETRIEVAL_HEADER
  140. End Type
  141.  
  142. Public Type RETURNED_REC
  143.     recLen        As Integer
  144.     recPos        As Long
  145.     personRecord  As PersonRecType
  146. End Type
  147.  
  148. Public Type POST_GNE_BUFFER
  149.     numReturned    As Integer
  150.     recs(0 To 19)  As RETURNED_REC
  151. End Type
  152.   
  153. '***************************************************************
  154. ' Define FieldMaps.  Create structure for holding file structure.
  155. '***************************************************************
  156.  
  157. Global Version_StructMap(0 To 8) As FieldMap
  158. Const Versionsize = 15
  159.  
  160. Global ClientIDFldMap(0 To 16) As FieldMap
  161. Const ClientIDsize = 17
  162.  
  163. Global PersonFldMap(0 To 8) As FieldMap
  164. Const PersonRowSize = 157
  165.  
  166. Global gneheaderMap(0 To 3) As FieldMap
  167. Const gneheadersize = 8
  168.  
  169. Global termheaderMap(0 To 5) As FieldMap
  170. Const termheadersize = 10
  171.  
  172. Global retrievalheaderMap(0 To 1) As FieldMap
  173. Const retrievalheadersize = 4
  174.  
  175. Global fieldretrievalMap(0 To 1) As FieldMap
  176. Const fieldretrievalsize = 4
  177.  
  178. Global pregnebufferMap(0 To 23) As FieldMap
  179. Const pregnebuffersize = 36
  180.  
  181. Global returnrecMap(0 To 12) As FieldMap
  182. Const returnrecsize = 163
  183.  
  184. Global Post_GNE_BUFFERFieldMap(0 To 281) As FieldMap
  185. Const postgnebuffersize = 3262
  186.  
  187.  
  188. '**************************************************************
  189. '  Define FldMapTypes.  Create structures needed to store a packed
  190. '  database row.
  191. '**************************************************************
  192.  
  193. Public Type PersonRowType
  194.     buf(1 To PersonRowSize) As Byte
  195. End Type
  196.  
  197. Public Type VersionType
  198.   buf(1 To Versionsize) As Byte
  199. End Type
  200.  
  201. Public Type ClientIDType
  202.   buf(1 To ClientIDsize) As Byte
  203. End Type
  204.  
  205. Public Type gneheaderType
  206.   buf(1 To gneheadersize) As Byte
  207. End Type
  208.  
  209. Public Type termheaderType
  210.    buf(1 To termheadersize) As Byte
  211. End Type
  212.  
  213. Public Type retrievalheadertype
  214.   buf(1 To retrievalheadersize) As Byte
  215. End Type
  216.  
  217. Public Type fieldretrievaltype
  218.   buf(1 To fieldretrievalsize) As Byte
  219. End Type
  220.  
  221. Public Type pregnebuffertype
  222.   buf(1 To pregnebuffersize) As Byte
  223. End Type
  224.  
  225. Public Type returnrectype
  226.   buf(1 To returnrecsize) As Byte
  227. End Type
  228.  
  229. Public Type postgnebuffertype
  230.   buf(1 To postgnebuffersize) As Byte
  231. End Type
  232.  
  233. Public Const FLD_PAD32 = 42
  234.  
  235.  
  236.  
  237.  
  238. '*******************************************************************
  239. 'Build FieldMaps.  Load the file structure into memory.
  240. '*******************************************************************
  241.  
  242. Sub AddField(map() As FieldMap, ByRef ctr As Integer, dataType As Long, _
  243.             length As Long)
  244.   
  245.   SetField map(ctr), dataType, length
  246.   ctr = ctr + 1
  247.   
  248. End Sub
  249.  
  250.  
  251. Sub AddgneHeaderFldMap(map() As FieldMap, ByRef ctr As Integer)
  252.   
  253.   AddField map, ctr, FLD_INTEGER, 2 ' descriptionLen
  254.   AddField map, ctr, FLD_STRING, 2   ' currencyConst
  255.   AddField map, ctr, FLD_INTEGER, 2 ' rejectCount
  256.   AddField map, ctr, FLD_INTEGER, 2 ' numberTerms
  257.  
  258. End Sub
  259.  
  260.  
  261. Sub AddTERM_HEADERFldMap(map() As FieldMap, ByRef ctr As Integer)
  262.   
  263.   AddField map, ctr, FLD_BYTE, 1    ' fieldType
  264.   AddField map, ctr, FLD_INTEGER, 2 ' fieldLen
  265.   AddField map, ctr, FLD_INTEGER, 2 ' fieldOffset
  266.   AddField map, ctr, FLD_BYTE, 1    ' comparisonCode
  267.   AddField map, ctr, FLD_BYTE, 1    ' connector
  268.   AddField map, ctr, FLD_STRING, 3  ' value
  269.  
  270. End Sub
  271.  
  272.  
  273. Sub AddPersonFieldMap(map() As FieldMap, ByRef ctr As Integer)
  274.   
  275.   AddField map, ctr, FLD_INTEGER, 4 'ID
  276.   AddField map, ctr, FLD_STRING, 16 'FirstName
  277.   AddField map, ctr, FLD_STRING, 26 'LastName
  278.   AddField map, ctr, FLD_STRING, 31 'Street
  279.   AddField map, ctr, FLD_STRING, 31 'City
  280.   AddField map, ctr, FLD_STRING, 3  'State
  281.   AddField map, ctr, FLD_STRING, 11 'Zip
  282.   AddField map, ctr, FLD_STRING, 21 'Country
  283.   AddField map, ctr, FLD_STRING, 14 'Phone
  284.  
  285. End Sub
  286.  
  287.  
  288. Sub AddFieldMap(out() As FieldMap, ByRef ctr As Integer, nin() As FieldMap)
  289. ' Append a fieldmap to another
  290. Dim fld As Integer
  291.   
  292.   For fld = LBound(nin) To UBound(nin)
  293.     out(ctr) = nin(fld)
  294.     ctr = ctr + 1
  295.   Next fld
  296.   
  297. End Sub
  298.  
  299.  
  300. Sub AddRETRIEVAL_HEADER(map() As FieldMap, ByRef ctr As Integer)
  301.   
  302.   AddField map, ctr, FLD_INTEGER, 2 ' maxRecsToRetrieve
  303.   AddField map, ctr, FLD_INTEGER, 2 ' noFieldsToRetrieve
  304.   
  305. End Sub
  306.  
  307.  
  308. Sub AddFIELD_RETRIEVAL_HEADER(map() As FieldMap, ByRef ctr As Integer)
  309.   
  310.   AddField map, ctr, FLD_INTEGER, 2 ' fieldLen
  311.   AddField map, ctr, FLD_INTEGER, 2 ' fieldOffset
  312.   
  313. End Sub
  314.  
  315. Sub AddPreGNEBufferFldMap(map() As FieldMap, ByRef ctr As Integer)
  316.   
  317.   AddgneHeaderFldMap map, ctr         'gneHeader
  318.   AddTERM_HEADERFldMap map, ctr       ' term1
  319.   AddTERM_HEADERFldMap map, ctr       ' term2
  320.   AddRETRIEVAL_HEADER map, ctr        ' retrieval
  321.   AddFIELD_RETRIEVAL_HEADER map, ctr  ' recordRet
  322.   
  323. End Sub
  324.  
  325. Sub AddRETURNED_RECFldMap(map() As FieldMap, ByRef ctr As Integer)
  326.  
  327.   AddField map, ctr, FLD_INTEGER, 2  ' recLen
  328.   AddField map, ctr, FLD_INTEGER, 4  ' recPos
  329.   AddFieldMap map, ctr, PersonFldMap ' personRecord
  330.   
  331. End Sub
  332.  
  333.  
  334. Sub AddPostGNEBufferFldMap(map() As FieldMap, ByRef ctr As Integer)
  335.  
  336. Dim fld As Integer
  337.    
  338.   AddField map, ctr, FLD_INTEGER, 2   ' numReturned
  339.   
  340.   For fld = 0 To 19
  341.     AddField map, ctr, FLD_PAD32, 0
  342.     AddRETURNED_RECFldMap map, ctr    ' recs
  343.   Next fld
  344.   
  345. End Sub
  346.  
  347.  
  348. Sub AddVersionBufferFldMap(map() As FieldMap, ByRef ctr As Integer)
  349. Dim fld As Integer
  350.  
  351.   For fld = 0 To 2
  352.     AddField map, ctr, FLD_INTEGER, 2 ' version
  353.     AddField map, ctr, FLD_INTEGER, 2 ' revision
  354.     AddField map, ctr, FLD_STRING, 1  'MKDEId
  355.   Next fld
  356.  
  357. End Sub
  358.  
  359. Sub AddClientIDBufferFldMap(map() As FieldMap, ByRef ctr As Integer)
  360. Dim fld As Integer
  361.  
  362.   For fld = 0 To 11
  363.      AddField map, ctr, FLD_BYTE, 1 'networkandnode
  364.   Next fld
  365.   
  366.   For fld = 0 To 2
  367.     AddField map, ctr, FLD_BYTE, 1  'applicationID
  368.   Next fld
  369.   
  370.   AddField map, ctr, FLD_INTEGER, 2 'threadID
  371.   
  372. End Sub
  373.    
  374.  
  375. Sub InitFieldMaps()
  376. 'Initialize FieldMaps
  377.  
  378.   AddPersonFieldMap PersonFldMap, 0
  379.   AddgneHeaderFldMap gneheaderMap, 0
  380.   AddTERM_HEADERFldMap termheaderMap, 0
  381.   AddFIELD_RETRIEVAL_HEADER fieldretrievalMap, 0
  382.   AddRETRIEVAL_HEADER retrievalheaderMap, 0
  383.   AddRETURNED_RECFldMap returnrecMap, 0
  384.   AddPreGNEBufferFldMap pregnebufferMap, 0
  385.   AddPostGNEBufferFldMap Post_GNE_BUFFERFieldMap, 0
  386.   AddVersionBufferFldMap Version_StructMap, 0
  387.   AddClientIDBufferFldMap ClientIDFldMap, 0
  388.   
  389. End Sub
  390.  
  391.