from ctypes import *
from enum import Enum
import ctypes
tianzuo_QiankunLib = cdll.LoadLibrary('./tianzuo.Qiankun.dll')
class Qiankun_error_code(Enum):
Qiankun_errorcode_success = 1
Qiankun_errorcode_normal = 2
Qiankun_errorcode_differ = 3
Qiankun_errorcode_no_rights = 4
Qiankun_errorcode_db_not_exist = 5
Qiankun_errorcode_exist = 6
Qiankun_errorcode_not_exist = 7
Qiankun_errorcode_out_of_range = 8
Qiankun_errorcode_type = 9
Qiankun_errorcode_param = 10
Qiankun_errorcode_compress = 11
Qiankun_errorcode_get_array = 12
Qiankun_errorcode_out_of_memory = 13
Qiankun_errorcode_handle = 14
Qiankun_errorcode_io = 15
def __init__(self):
tianzuo_QiankunLib.tianzuo_QiankunInterface_initialize.restype = c_void_p
self.obj = tianzuo_QiankunLib.tianzuo_QiankunInterface_initialize()
def __del__(self):
tianzuo_QiankunLib.tianzuo_QiankunInterface_terminate.argtypes = [c_void_p]
tianzuo_QiankunLib.tianzuo_QiankunInterface_terminate(self.obj)
def initialize(self):
tianzuo_QiankunLib.tianzuo_QiankunInterface_initialize.restype = c_int
tianzuo_QiankunLib.tianzuo_QiankunInt_initialize.argtypes = [c_void_p]
return tianzuo_QiankunLib.tianzuo_QiankunInt_initialize(self.obj)
def db_create_database(self, db_file_name, db_password, db_name, over_write):
tianzuo_QiankunLib.tianzuo_QiankunInt_db_create_database.argtypes = [c_void_p, c_char_p, c_char_p, c_char_p, c_int]
return tianzuo_QiankunLib.tianzuo_QiankunInt_db_create_database(self.obj, db_file_name, db_password, db_name, over_write)
def db_open_database(self, db_file_name, db_password):
tianzuo_QiankunLib.tianzuo_QiankunInt_db_open_database.argtypes = [c_void_p, c_char_p, c_char_p]
return tianzuo_QiankunLib.tianzuo_QiankunInt_db_open_database(self.obj, db_file_name, db_password)
def db_close_database(self, db_file_name, db_password):
tianzuo_QiankunLib.tianzuo_QiankunInt_db_close_database.argtypes = [c_void_p, c_char_p, c_char_p]
return tianzuo_QiankunLib.tianzuo_QiankunInt_db_close_database(self.obj, db_file_name, db_password)
def data_int_combine(self, db_file_name, db_password, data_name, remark, data):
tianzuo_QiankunLib.tianzuo_QiankunInt_data_int_combine.argtypes = [c_void_p, c_char_p, c_char_p, c_char_p, c_char_p, c_int]
return tianzuo_QiankunLib.tianzuo_QiankunInt_data_int_combine(self.obj, db_file_name, db_password, data_name, remark, data)
def data_int_extract(self, db_file_name, db_password, data_name, data):
tianzuo_QiankunLib.tianzuo_QiankunInt_data_int_extract.argtypes = [c_void_p, c_char_p, c_char_p, c_char_p, ctypes.POINTER(ctypes.c_int)]
return tianzuo_QiankunLib.tianzuo_QiankunInt_data_int_extract(self.obj, db_file_name, db_password, data_name, data)
def main():
print("initialize the interface")
error_code = qiankun.initialize()
if error_code != Qiankun_error_code.Qiankun_errorcode_success.value:
print("initialize error:", error_code)
return
db_file_name = b"qiankunDataBase.Ztz"
db_password = b"password"
error_code = qiankun.db_create_database(db_file_name, db_password, b"qiankunDataBase", True)
if error_code != Qiankun_error_code.Qiankun_errorcode_success.value:
print("db_create_database error:", error_code)
return
error_code = qiankun.db_open_database(db_file_name, db_password)
if error_code != Qiankun_error_code.Qiankun_errorcode_success.value:
print("db_open_database error:", error_code)
return
intInt = 12345678
error_code = qiankun.data_int_combine(db_file_name, db_password, b"integer", None, intInt)
if error_code != Qiankun_error_code.Qiankun_errorcode_success.value:
print("data_combine error:", error_code)
return
return_data = ctypes.c_int()
error_code = qiankun.data_int_extract(db_file_name, db_password, b"integer", ctypes.byref(return_data))
if error_code != Qiankun_error_code.Qiankun_errorcode_success.value:
print("data_extract error:", error_code)
return
integer = return_data.value
print("get integer data: {}".format(integer))
error_code = qiankun.db_close_database(db_file_name, db_password)
if error_code != Qiankun_error_code.Qiankun_errorcode_success.value:
print("db_close_database error:", error_code)
return
print("test done -------------------")
if __name__ == '__main__':
main()