|
10 | 10 | obx_id = ctypes.c_uint64 |
11 | 11 | obx_qb_cond = ctypes.c_int |
12 | 12 |
|
| 13 | +# enums |
| 14 | +OBXPropertyType = ctypes.c_int |
| 15 | +OBXPropertyFlags = ctypes.c_int |
| 16 | +OBXDebugFlags = ctypes.c_int |
| 17 | +OBXPutMode = ctypes.c_int |
| 18 | +OBXOrderFlags = ctypes.c_int |
| 19 | + |
13 | 20 |
|
14 | 21 | class OBX_model(ctypes.Structure): |
15 | 22 | pass |
@@ -102,22 +109,109 @@ class OBX_query(ctypes.Structure): |
102 | 109 | OBX_query_p = ctypes.POINTER(OBX_query) |
103 | 110 |
|
104 | 111 |
|
| 112 | +class CError(Exception): |
| 113 | + def __init__(self, code): |
| 114 | + self.code = code |
| 115 | + self.message = ctypes.c_char_p(C.obx_last_error_message()).value.decode("utf8") |
| 116 | + super(CError, self).__init__(self.message) |
| 117 | + |
| 118 | + |
| 119 | +# check obx_err and raise an error |
| 120 | +def errcheck(code: obx_err, func, args): |
| 121 | + if code != 0: |
| 122 | + raise CError(code) |
| 123 | + |
| 124 | + |
105 | 125 | # creates a global function "name" with the given restype & argtypes, calling C function with the same name |
106 | 126 | def fn(name: str, restype: type, argtypes): |
107 | 127 | func = C.__getattr__(name) |
108 | 128 |
|
109 | 129 | if restype == obx_err: |
110 | | - # TODO func.errcheck |
111 | | - pass |
| 130 | + func.errcheck = errcheck |
112 | 131 | else: |
113 | 132 | func.restype = restype |
114 | 133 |
|
115 | 134 | func.argtypes = argtypes |
116 | 135 | return func |
117 | 136 |
|
118 | 137 |
|
119 | | -# OBX_model* obx_model_create(void); |
| 138 | +def c_str(string: str) -> ctypes.c_char_p: |
| 139 | + return string.encode('utf-8') |
| 140 | + |
| 141 | + |
| 142 | +# OBX_model* (void); |
120 | 143 | obx_model_create = fn('obx_model_create', OBX_model_p, []) |
121 | 144 |
|
122 | | -# obx_err obx_model_entity(OBX_model* model, const char* name, obx_schema_id entity_id, obx_uid entity_uid); |
| 145 | +# obx_err (OBX_model* model, const char* name, obx_schema_id entity_id, obx_uid entity_uid); |
123 | 146 | obx_model_entity = fn('obx_model_entity', obx_err, [OBX_model_p, ctypes.c_char_p, obx_schema_id, obx_uid]) |
| 147 | + |
| 148 | +# obx_err (OBX_model* model, const char* name, OBXPropertyType type, obx_schema_id property_id, obx_uid property_uid); |
| 149 | +obx_model_property = fn('obx_model_property', obx_err, |
| 150 | + [OBX_model_p, ctypes.c_char_p, OBXPropertyType, obx_schema_id, obx_uid]) |
| 151 | + |
| 152 | +OBXPropertyType_Bool = 1 |
| 153 | +OBXPropertyType_Byte = 2 |
| 154 | +OBXPropertyType_Short = 3 |
| 155 | +OBXPropertyType_Char = 4 |
| 156 | +OBXPropertyType_Int = 5 |
| 157 | +OBXPropertyType_Long = 6 |
| 158 | +OBXPropertyType_Float = 7 |
| 159 | +OBXPropertyType_Double = 8 |
| 160 | +OBXPropertyType_String = 9 |
| 161 | +OBXPropertyType_Date = 10 |
| 162 | +OBXPropertyType_Relation = 11 |
| 163 | +OBXPropertyType_ByteVector = 23 |
| 164 | +OBXPropertyType_StringVector = 30 |
| 165 | + |
| 166 | +OBXPropertyFlags_ID = 1 |
| 167 | +OBXPropertyFlags_NON_PRIMITIVE_TYPE = 2 |
| 168 | +OBXPropertyFlags_NOT_NULL = 4 |
| 169 | +OBXPropertyFlags_INDEXED = 8 |
| 170 | +OBXPropertyFlags_RESERVED = 16 |
| 171 | +OBXPropertyFlags_UNIQUE = 32 |
| 172 | +OBXPropertyFlags_ID_MONOTONIC_SEQUENCE = 64 |
| 173 | +OBXPropertyFlags_ID_SELF_ASSIGNABLE = 128 |
| 174 | +OBXPropertyFlags_INDEX_PARTIAL_SKIP_NULL = 256 |
| 175 | +OBXPropertyFlags_INDEX_PARTIAL_SKIP_ZERO = 512 |
| 176 | +OBXPropertyFlags_VIRTUAL = 1024 |
| 177 | +OBXPropertyFlags_INDEX_HASH = 2048 |
| 178 | +OBXPropertyFlags_INDEX_HASH64 = 4096 |
| 179 | +OBXPropertyFlags_UNSIGNED = 8192 |
| 180 | + |
| 181 | +OBXDebugFlags_LOG_TRANSACTIONS_READ = 1, |
| 182 | +OBXDebugFlags_LOG_TRANSACTIONS_WRITE = 2, |
| 183 | +OBXDebugFlags_LOG_QUERIES = 4, |
| 184 | +OBXDebugFlags_LOG_QUERY_PARAMETERS = 8, |
| 185 | +OBXDebugFlags_LOG_ASYNC_QUEUE = 16, |
| 186 | + |
| 187 | + |
| 188 | +# Standard put ("insert or update") |
| 189 | +OBXPutMode_PUT = 1, |
| 190 | + |
| 191 | +# Put succeeds only if the entity does not exist yet. |
| 192 | +OBXPutMode_INSERT = 2, |
| 193 | + |
| 194 | +# Put succeeds only if the entity already exist. |
| 195 | +OBXPutMode_UPDATE = 3, |
| 196 | + |
| 197 | +# The given ID (non-zero) is guaranteed to be new; don't use unless you know exactly what you are doing! |
| 198 | +# This is primarily used internally. Wrong usage leads to inconsistent data (e.g. index data not updated)! |
| 199 | +OBXPutMode_PUT_ID_GUARANTEED_TO_BE_NEW = 4 |
| 200 | + |
| 201 | + |
| 202 | +# Reverts the order from ascending (default) to descending. |
| 203 | +OBXOrderFlags_DESCENDING = 1, |
| 204 | + |
| 205 | +# Makes upper case letters (e.g. "Z") be sorted before lower case letters (e.g. "a"). |
| 206 | +# If not specified, the default is case insensitive for ASCII characters. |
| 207 | +OBXOrderFlags_CASE_SENSITIVE = 2, |
| 208 | + |
| 209 | +# For scalars only: changes the comparison to unsigned (default is signed). |
| 210 | +OBXOrderFlags_UNSIGNED = 4, |
| 211 | + |
| 212 | +# null values will be put last. |
| 213 | +# If not specified, by default null values will be put first. |
| 214 | +OBXOrderFlags_NULLS_LAST = 8, |
| 215 | + |
| 216 | +# null values should be treated equal to zero (scalars only). |
| 217 | +OBXOrderFlags_NULLS_ZERO = 16, |
0 commit comments