This is an example of file creation, load, access, and deletion in Python.
7 if (platform.system() ==
"Windows"):
8 sys.path.append(
"C:\\Program Files\\Actian\\Zen\\bin")
10 sys.path.append(
"/usr/local/actianzen/lib64")
16 btrieveFileName =
"squaresAndSquareRoots.btr" 21 if (len(sys.argv) != 2):
22 sys.exit(
"Usage: " + os.path.basename(sys.argv[0]) +
" uint8_value")
24 integerValue = int(sys.argv[1])
26 if (integerValue < min_x)
or (integerValue > max_x):
27 sys.exit(
"Usage: " + os.path.basename(sys.argv[0]) +
" uint8_value")
30 btrieveClient = btrievePython.BtrieveClient()
31 assert(btrieveClient !=
None)
35 btrieveFileAttributes = btrievePython.BtrieveFileAttributes()
36 assert(btrieveFileAttributes !=
None)
40 rc = btrieveFileAttributes.SetFixedRecordLength(recordLength)
41 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveFileAttributes::SetLogicalFixedRecordLength():%d,%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
45 rc = btrieveClient.FileCreate(btrieveFileAttributes, btrieveFileName, btrievePython.Btrieve.CREATE_MODE_OVERWRITE)
46 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveClient::FileCreate():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
50 btrieveFile = btrievePython.BtrieveFile()
51 assert(btrieveFile !=
None)
55 rc = btrieveClient.FileOpen(btrieveFile, btrieveFileName,
None, btrievePython.Btrieve.OPEN_MODE_NORMAL)
56 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveClient::FileOpen():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
60 for i
in range(min_x, max_x + 1):
61 record = struct.pack(recordFormat, i, i * i, math.sqrt(i))
64 rc = btrieveFile.RecordCreate(record)
65 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveFile::RecordCreate():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
69 btrieveKeySegment = btrievePython.BtrieveKeySegment()
70 assert(btrieveKeySegment !=
None)
74 rc = btrieveKeySegment.SetField(0, 1, btrievePython.Btrieve.DATA_TYPE_UNSIGNED_BINARY)
75 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveKeySegment::SetField():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
79 btrieveIndexAttributes = btrievePython.BtrieveIndexAttributes()
80 assert(btrieveIndexAttributes !=
None),
"Error: BtrieveIndexAttributes::AddKeySegment():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
84 rc = btrieveIndexAttributes.AddKeySegment(btrieveKeySegment)
85 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveIndexAttributes::AddKeySegment():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
89 rc = btrieveFile.IndexCreate(btrieveIndexAttributes)
90 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveFile::IndexCreate():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
94 record = struct.pack(recordFormat, 0, 0, 0)
95 key = struct.pack(keyFormat, integerValue)
98 rc = btrieveFile.RecordRetrieve(btrievePython.Btrieve.COMPARISON_EQUAL,btrievePython.Btrieve.INDEX_1, key, record)
99 assert(rc == recordLength),
"Error: BtrieveFileRecordRetrieveEqual():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFile.GetLastStatusCode()))
102 print (
"record:", struct.unpack(recordFormat, record))
105 rc = btrieveClient.FileClose(btrieveFile)
106 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveClient::FileClose():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
110 rc = btrieveClient.FileDelete(btrieveFileName)
111 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveClient::FileDelete():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))