Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
6.7 KiB

  1. // Flags for field descriptor
  2. /* note that these flags are stored persistantly in database
  3. /* catalogs and cannot be changed without a database format change
  4. /**/
  5. #define ffieldNotNull (1<<0) // NULL values not allowed
  6. #define ffieldVersion (1<<2) // Version field
  7. #define ffieldAutoInc (1<<3) // Auto increment field
  8. #define ffieldMultivalue (1<<4) // Multi-valued column
  9. #define ffieldDefault (1<<5) // Column has ISAM default value
  10. #define FIELDSetNotNull( field ) ((field) |= ffieldNotNull)
  11. #define FIELDResetNotNull( field ) ((field) &= ~ffieldNotNull)
  12. #define FFIELDNotNull( field ) ((field) & ffieldNotNull)
  13. #define FIELDSetVersion( field ) ((field) |= ffieldVersion)
  14. #define FIELDResetVersion( field ) ((field) &= ~ffieldVersion)
  15. #define FFIELDVersion( field ) ((field) & ffieldVersion)
  16. #define FIELDSetAutoInc( field ) ((field) |= ffieldAutoInc)
  17. #define FIELDResetAutoInc( field ) ((field) &= ~ffieldAutoInc)
  18. #define FFIELDAutoInc( field ) ((field) & ffieldAutoInc)
  19. #define FIELDSetMultivalue( field ) ((field) |= ffieldMultivalue)
  20. #define FIELDResetMultivalue( field ) ((field) &= ~ffieldMultivalue)
  21. #define FFIELDMultivalue( field ) ((field) & ffieldMultivalue)
  22. #define FIELDSetDefault( field ) ((field) |= ffieldDefault)
  23. #define FIELDResetDefault( field ) ((field) &= ~ffieldDefault)
  24. #define FFIELDDefault( field ) ((field) & ffieldDefault)
  25. #define FIELDSetFlag( field, flag ) ((field).ffield |= (flag))
  26. #define FIELDResetFlag( field, flag ) ((field).ffield &= ~(flag))
  27. #define FRECLongValue( coltyp ) \
  28. ( (coltyp) == JET_coltypLongText || (coltyp) == JET_coltypLongBinary )
  29. #define FRECTextColumn( coltyp ) \
  30. ( (coltyp) == JET_coltypText || (coltyp) == JET_coltypLongText )
  31. #define FRECBinaryColumn( coltyp ) \
  32. ( (coltyp) == JET_coltypBinary || (coltyp) == JET_coltypLongBinary )
  33. #define cbAvgColName 10 // Average length of a column name
  34. /* entry in field descriptor tables found in an FDB
  35. /**/
  36. typedef struct _field
  37. {
  38. JET_COLTYP coltyp; // column data type
  39. ULONG cbMaxLen; // maximum length
  40. ULONG itagFieldName; // Offset into FDB's buffer
  41. USHORT cp; // code page of language
  42. BYTE ffield; // various flags
  43. } FIELD;
  44. typedef struct tagFIELDEX // Extended field info.
  45. {
  46. FIELD field; // Standard field info (see above)
  47. FID fid; // field id
  48. WORD ibRecordOffset; // Record offset (for fixed fields only)
  49. } FIELDEX;
  50. #define itagFDBFields 1 // Tag into FDB's buffer for field info
  51. // (FIELD structures and fixed offsets table)
  52. // The fixed offsets table is also the beginning of the field info (ie. the FIELD
  53. // structures follow the fixed offsets table).
  54. #define PibFDBFixedOffsets( pfdb ) ( (WORD *)PbMEMGet( (pfdb)->rgb, itagFDBFields ) )
  55. // Get the appropriate FIELD structure based on the previous FIELD structure.
  56. // NOTE: Be wary of the alignment fixup for the fixed offsets table.
  57. #define PfieldFDBFixedFromOffsets( pfdb, pibFixedOffsets ) \
  58. ( (FIELD *)( Pb4ByteAlign( (BYTE *) ( pibFixedOffsets + (pfdb)->fidFixedLast + 1 ) ) ) )
  59. #define PfieldFDBVarFromFixed( pfdb, pfieldFixed ) \
  60. ( pfieldFixed + (pfdb)->fidFixedLast + 1 - fidFixedLeast )
  61. #define PfieldFDBTaggedFromVar( pfdb, pfieldVar ) \
  62. ( pfieldVar + (pfdb)->fidVarLast + 1 - fidVarLeast )
  63. // Get the appropriate FIELD strcture, starting from the beginning of the field info.
  64. #define PfieldFDBFixed( pfdb ) PfieldFDBFixedFromOffsets( pfdb, PibFDBFixedOffsets( pfdb ) )
  65. #define PfieldFDBVar( pfdb ) PfieldFDBVarFromFixed( pfdb, PfieldFDBFixed( pfdb ) )
  66. #define PfieldFDBTagged( pfdb ) PfieldFDBTaggedFromVar( pfdb, PfieldFDBVar( pfdb ) )
  67. /* field descriptor block: information about all columns of a table
  68. /**/
  69. struct _fdb
  70. {
  71. BYTE *rgb; // Buffer for FIELD structures, fixed
  72. // offsets table, and column names
  73. FID fidFixedLast; // Highest fixed field id in use
  74. FID fidVarLast; // Highest variable field id in use
  75. FID fidTaggedLast; // Highest tagged field id in use
  76. USHORT ffdb; // FDB flags. NOTE: This field is currently
  77. // no longer used, but keep it here anyways
  78. // for alignment purposes.
  79. FID fidVersion; // fid of version field
  80. FID fidAutoInc; // fid of auto increment field
  81. LINE lineDefaultRecord; // default record
  82. };
  83. typedef struct tagMEMBUFHDR
  84. {
  85. ULONG cbBufSize; // Length of buffer.
  86. ULONG ibBufFree; // Beginning of free space in buffer
  87. // (if ibBufFree==cbBufSize, then buffer is full)
  88. ULONG cTotalTags; // Size of tag array
  89. ULONG iTagUnused; // Next unused tag (never been used or freed)
  90. ULONG iTagFreed; // Next freed tag (previously used, but since freed)
  91. } MEMBUFHDR;
  92. typedef struct tagMEMBUFTAG
  93. {
  94. ULONG ib; // UNDONE: Should these be SHORT's instead?
  95. ULONG cb;
  96. } MEMBUFTAG;
  97. typedef struct tagMEMBUF
  98. {
  99. MEMBUFHDR bufhdr;
  100. BYTE *pbuf;
  101. } MEMBUF;
  102. ERR ErrMEMCreateMemBuf( BYTE **prgbBuffer, ULONG cbInitialSize, ULONG cInitialEntries );
  103. ERR ErrMEMCopyMemBuf( BYTE **prgbBufferDest, BYTE *rgbBufferSrc );
  104. VOID MEMFreeMemBuf( BYTE *rgbBuffer );
  105. ERR ErrMEMAdd( BYTE *rgbBuffer, BYTE *rgb, ULONG cb, ULONG *pitag );
  106. ERR ErrMEMReplace( BYTE *rgbBuffer, ULONG iTagEntry, BYTE *rgb, ULONG cb );
  107. VOID MEMDelete( BYTE *rgbBuffer, ULONG iTagEntry );
  108. #ifdef DEBUG
  109. BYTE *SzMEMGetString( BYTE *rgbBuffer, ULONG iTagEntry );
  110. VOID MEMAssertMemBuf( MEMBUF *pmembuf );
  111. VOID MEMAssertMemBufTag( MEMBUF *pmembuf, ULONG iTagEntry );
  112. #else
  113. #define SzMEMGetString( rgbBuffer, iTagEntry ) PbMEMGet( rgbBuffer, iTagEntry )
  114. #define MEMAssertMemBuf( pmembuf )
  115. #define MEMAssertMemBufTag( pmembuf, iTagEntry )
  116. #endif
  117. // Retrieve a pointer to the desired entry in the buffer.
  118. // WARNING: Pointers into the contents of the buffer are very
  119. // volatile -- they may be invalidated the next time the buffer
  120. // is reallocated. Ideally, we should never allow direct access via
  121. // pointers -- we should only allow indirect access via itags which we
  122. // will dereference for the user and copy to a user-provided buffer. However,
  123. // there would be a size and speed hit with such a method.
  124. INLINE STATIC BYTE *PbMEMGet( BYTE *rgbBuffer, ULONG iTagEntry )
  125. {
  126. MEMBUF *pmembuf = (MEMBUF *)rgbBuffer;
  127. MEMBUFTAG *rgbTags;
  128. MEMAssertMemBuf( pmembuf ); // Validate integrity of string buffer.
  129. MEMAssertMemBufTag( pmembuf, iTagEntry ); // Validate integrity of itag.
  130. rgbTags = (MEMBUFTAG *)pmembuf->pbuf;
  131. return pmembuf->pbuf + rgbTags[iTagEntry].ib;
  132. }
  133. INLINE STATIC ULONG CbMEMGet( BYTE *rgbBuffer, ULONG iTagEntry )
  134. {
  135. MEMBUF *pmembuf = (MEMBUF *)rgbBuffer;
  136. MEMBUFTAG *rgbTags;
  137. MEMAssertMemBuf( pmembuf ); // Validate integrity of string buffer.
  138. MEMAssertMemBufTag( pmembuf, iTagEntry ); // Validate integrity of itag.
  139. rgbTags = (MEMBUFTAG *)pmembuf->pbuf;
  140. return rgbTags[iTagEntry].cb;
  141. }