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" 22 if (len(sys.argv) != 2):
23 sys.exit(
"Usage: " + os.path.basename(sys.argv[0]) +
" uint8_value")
25 integerValue = int(sys.argv[1])
28 if (integerValue < min_x)
or (integerValue > max_x):
29 sys.exit(
"Usage: " + os.path.basename(sys.argv[0]) +
" uint8_value")
32 btrieveClient = btrievePython.BtrieveClient()
33 assert(btrieveClient !=
None)
37 btrieveFileAttributes = btrievePython.BtrieveFileAttributes()
38 assert(btrieveFileAttributes !=
None)
42 rc = btrieveFileAttributes.SetFixedRecordLength(recordLength)
43 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveFileAttributes::SetFixedRecordLength():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
47 rc = btrieveClient.FileCreate(btrieveFileAttributes, btrieveFileName, btrievePython.Btrieve.CREATE_MODE_OVERWRITE)
48 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveClient::FileCreate():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
52 btrieveFile = btrievePython.BtrieveFile()
53 assert(btrieveFile !=
None)
57 rc = btrieveClient.FileOpen(btrieveFile, btrieveFileName,
None, btrievePython.Btrieve.OPEN_MODE_NORMAL)
58 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveClient::FileOpen():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
62 for i
in range(min_x, max_x + 1):
63 record = struct.pack(recordFormat, i, i * i, math.sqrt(i))
66 rc = btrieveFile.RecordCreate(record)
67 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveFile::RecordCreate():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
71 btrieveKeySegment = btrievePython.BtrieveKeySegment()
72 assert(btrieveKeySegment !=
None)
76 rc = btrieveKeySegment.SetField(0, 1, btrievePython.Btrieve.DATA_TYPE_UNSIGNED_BINARY)
77 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveKeySegment::SetField():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
81 btrieveIndexAttributes = btrievePython.BtrieveIndexAttributes()
82 assert(btrieveIndexAttributes !=
None)
86 rc = btrieveIndexAttributes.AddKeySegment(btrieveKeySegment)
87 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveIndexAttributes::AddKeySegment():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
91 rc = btrieveFile.IndexCreate(btrieveIndexAttributes)
92 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveFile::IndexCreate():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
96 record = struct.pack(recordFormat, 0, 0, 0)
97 key = struct.pack(keyFormat, integerValue)
100 rc = btrieveFile.RecordRetrieve(btrievePython.Btrieve.COMPARISON_EQUAL, btrievePython.Btrieve.INDEX_1, key, record)
101 assert(rc == recordLength),
"Error: BtrieveFile::RecordRetrieve():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(btrieveFile.GetLastStatusCode()))
104 print (
"record:", struct.unpack(recordFormat, record))
107 rc = btrieveClient.FileClose(btrieveFile)
108 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveClient::FileClose():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))
112 rc = btrieveClient.FileDelete(btrieveFileName)
113 assert(rc == btrievePython.Btrieve.STATUS_CODE_NO_ERROR),
"Error: BtrieveClient::FileDelete():%d:%s.\n" % (rc, btrievePython.Btrieve_StatusCodeToString(rc))