Btrieve 2
読み取り中…
検索中…
一致する文字列を見つけられません
bfileattributes.py

これは Python で書かれたファイル属性の使用例です。

1import sys
2import struct
3import math
4import os
5import platform
6
7if (platform.system() == "Windows"):
8 sys.path.append("C:\\Program Files\\Actian\\Zen\\bin")
9else:
10 sys.path.append("/usr/local/actianzen/lib64")
11
12import btrievePython
13
14min_x = 0
15max_x = 255
16btrieveFileName = "squaresAndSquareRoots.btr"
17numberOfRecords = max_x - min_x + 1
18recordFormat = "<BHd1024s"
19recordLength = 11 + 1024
20
21# If the incorrect number of arguments were given.
22if (len(sys.argv) != 1):
23 sys.exit("Usage: " + os.path.basename(sys.argv[0]))
24
25btrieveClient = btrievePython.BtrieveClient()
26assert(btrieveClient != None)
27
28# Create file.
29btrieveFileAttributes = btrievePython.BtrieveFileAttributes()
30assert(btrieveFileAttributes != None)
31
32
33rc = btrieveFileAttributes.SetBalancedIndexes(True)
34assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetBalancedIndexes():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
35
36
37
38rc = btrieveFileAttributes.SetFileVersion(btrievePython.Btrieve.FILE_VERSION_9_5)
39assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetFileVersion():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
40
41
42rc = btrieveFileAttributes.SetFixedRecordLength(4)
43assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetFixedRecordLength():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
44
45
46rc = btrieveFileAttributes.SetFreeSpaceThreshold(btrievePython.Btrieve.FREE_SPACE_THRESHOLD_10_PERCENT)
47assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetFreeSpaceThreshold():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
48
49
50
51rc = btrieveFileAttributes.SetPageSize(btrievePython.Btrieve.PAGE_SIZE_16384)
52assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetPageSize():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
53
54
55
56rc = btrieveFileAttributes.SetPreallocatedPageCount(64 * 1024 - 1)
57assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetPreallocatedPageCount():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
58
59
60
61rc = btrieveFileAttributes.SetRecordCompressionMode(btrievePython.Btrieve.RECORD_COMPRESSION_MODE_RUN_LENGTH_ENCODING)
62assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetRecordCompressionMode():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
63
64
65
66rc = btrieveFileAttributes.SetReservedDuplicatePointerCount(119)
67assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetReservedDuplicatePointerCount():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
68
69
70
71rc = btrieveFileAttributes.SetSystemDataMode(btrievePython.Btrieve.SYSTEM_DATA_MODE_NO)
72assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetSystemDataMode():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
73
74
75
76rc = btrieveFileAttributes.SetVariableLengthRecordsMode(btrievePython.Btrieve.VARIABLE_LENGTH_RECORDS_MODE_YES_VARIABLE_ALLOCATION_TAILS)
77assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFileAttributes::SetVariableLengthRecordsMode():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
78
79
80rc = btrieveClient.FileCreate(btrieveFileAttributes, btrieveFileName, btrievePython.Btrieve.CREATE_MODE_OVERWRITE)
81assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveClient::FileCreate():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
82
83# Open file.
84btrieveFile = btrievePython.BtrieveFile()
85assert(btrieveFile != None)
86
87rc = btrieveClient.FileOpen(btrieveFile, btrieveFileName, None, btrievePython.Btrieve.OPEN_MODE_NORMAL)
88assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveClient::FileOpen():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
89
90# Print file information.
91btrieveFileInformation = btrievePython.BtrieveFileInformation()
92assert(btrieveFileInformation != None)
93
94rc = btrieveFile.GetInformation(btrieveFileInformation)
95assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveFile::GetInformation():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
96
97rc = btrieveFileInformation.GetBalancedIndexes()
98assert(rc >= 0), "Error: BtrieveFileInformation::GetBalancedIndexes():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
99
100print("BalancedIndexes =", "Yes" if rc > 0 else "No")
101
102rc = btrieveFileInformation.GetFileVersion()
103assert(rc != btrievePython.Btrieve.FILE_VERSION_UNKNOWN), "Error: BtrieveFileInformation::GetFileVersion():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
104
105print("FileVersion =", btrievePython.Btrieve.FileVersionToString(rc))
106
107rc = btrieveFileInformation.GetFreeSpaceThreshold()
108assert(rc != btrievePython.Btrieve.FREE_SPACE_THRESHOLD_UNKNOWN), "Error: BtrieveFileInformation::GetFreeSpaceThreshold():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
109
110print("FreeSpaceThreshold =", btrievePython.Btrieve.FreeSpaceThresholdToString(rc))
111
112rc = btrieveFileInformation.GetFixedRecordLength()
113assert(rc >= 0), "Error: BtrieveFileInformation::GetFixedRecordLength():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
114
115print("FixedRecordLength =", rc)
116
117rc = btrieveFileInformation.GetPageCompression()
118assert(rc >= 0), "Error: BtrieveFileInformation::GetPageCompression():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
119
120print("PageCompression =", "Yes" if rc > 0 else "No")
121
122rc = btrieveFileInformation.GetPagePreallocation()
123assert(rc >= 0), "Error: BtrieveFileInformation::GetPagePreallocation():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
124
125print("PagePreallocation =", "Yes" if rc > 0 else "No")
126
127rc = btrieveFileInformation.GetPageSize()
128assert(rc != btrievePython.Btrieve.PAGE_SIZE_UNKNOWN), "Error: BtrieveFileInformation::GetPageSize():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
129
130print("PageSize =", btrievePython.Btrieve.PageSizeToString(rc))
131
132rc = btrieveFileInformation.GetRecordCompressionMode()
133assert(rc != btrievePython.Btrieve.RECORD_COMPRESSION_MODE_UNKNOWN), "Error: BtrieveFileInformation::GetRecordCompressionMode():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
134
135print("RecordCompressionMode =", btrievePython.Btrieve.RecordCompressionModeToString(rc))
136
137rc = btrieveFileInformation.GetSystemDataMode()
138assert(rc != btrievePython.Btrieve.SYSTEM_DATA_MODE_UNKNOWN), "Error: BtrieveFileInformation::GetSystemDataMode():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
139
140print("SystemDataMode =", btrievePython.Btrieve.SystemDataModeToString(rc))
141
142rc = btrieveFileInformation.GetUnusedDuplicatePointerCount()
143assert(rc >= 0), "Error: BtrieveFileInformation::GetUnusedDuplicatePointerCount():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
144
145print("UnusedDuplicatePointerCount =", rc)
146
147rc = btrieveFileInformation.GetUnusedPageCount()
148assert(rc >= 0), "Error: BtrieveFileInformation::GetUnusedPageCount():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
149
150print("UnusedPageCount =", rc)
151
152rc = btrieveFileInformation.GetVariableLengthRecordsMode()
153assert(rc != btrievePython.Btrieve.VARIABLE_LENGTH_RECORDS_MODE_UNKNOWN), "Error: BtrieveFileInformation::GetVariableLengthRecordsMode():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFileInformation.GetLastStatusCode()))
154
155print("VariableLengthRecordsMode =", btrievePython.Btrieve.RecordCompressionModeToString(rc))
156
157# Close file.
158rc = btrieveClient.FileClose(btrieveFile)
159assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveClient::FileClose():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
160
161# Delete file.
162rc = btrieveClient.FileDelete(btrieveFileName)
163assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR), "Error: BtrieveClient::FileDelete():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))