@@ -124,13 +124,13 @@ Array KuzuGD::get_config() const {
124
124
125
125
bool KuzuGD::kuzu_init (const String database_path) {
126
126
if (database_path.is_empty ()) {
127
- UtilityFunctions::push_error (" KuzuGD Error | Database path is empty" );
127
+ UtilityFunctions::push_error (" KuzuGD ERROR | Database path is empty" );
128
128
return false ;
129
129
}
130
130
131
131
myKuzuDB = (kuzu_database *)malloc (sizeof (kuzu_database));
132
132
if (!myKuzuDB) {
133
- UtilityFunctions::push_error (" KuzuGD Error | Memory allocation failed for KuzuDB Init" );
133
+ UtilityFunctions::push_error (" KuzuGD ERROR | Memory allocation failed for KuzuDB Init" );
134
134
return false ;
135
135
}
136
136
myKuzuDB->_database = nullptr ;
@@ -147,7 +147,7 @@ bool KuzuGD::kuzu_init(const String database_path) {
147
147
bool KuzuGD::kuzu_connect (int num_threads) {
148
148
dbConnection = (kuzu_connection *)malloc (sizeof (kuzu_connection));
149
149
if (!dbConnection) {
150
- UtilityFunctions::push_error (" KuzuGD Error | Memory allocation failed for KuzuDB Connect" );
150
+ UtilityFunctions::push_error (" KuzuGD ERROR | Memory allocation failed for KuzuDB Connect" );
151
151
return false ;
152
152
}
153
153
memset (dbConnection, 0 , sizeof (kuzu_connection));
@@ -161,16 +161,23 @@ bool KuzuGD::kuzu_connect(int num_threads) {
161
161
kuzu_connection_set_max_num_thread_for_exec (
162
162
dbConnection,
163
163
num_threads);
164
- }
164
+ return state == KuzuSuccess;
165
165
166
- return state == KuzuSuccess;
166
+ } else {
167
+ UtilityFunctions::push_error (" KuzuGD ERROR | Kuzu Connection FAILED" );
168
+ return state == KuzuError;
169
+ }
167
170
}
168
171
169
172
bool KuzuGD::connection_set_max_threads (int num_threads) {
170
173
kuzu_state state = kuzu_connection_set_max_num_thread_for_exec (
171
174
dbConnection,
172
175
num_threads);
173
176
177
+ if (state == KuzuError) {
178
+ UtilityFunctions::push_error (" KuzuGD ERROR | Kuzu Set Max Threads FAILED" );
179
+ }
180
+
174
181
return state == KuzuSuccess;
175
182
}
176
183
@@ -183,6 +190,8 @@ int KuzuGD::connection_get_max_threads() {
183
190
if (state == KuzuSuccess) {
184
191
return static_cast <int >(result);
185
192
} else {
193
+ UtilityFunctions::push_error (" KuzuGD ERROR | FAILED to Obtain Max Num Threads for Connection" );
194
+
186
195
return -1 ;
187
196
}
188
197
}
@@ -201,15 +210,19 @@ Array KuzuGD::execute_query(const String &query) {
201
210
kuzu_query_result result;
202
211
kuzu_state state = kuzu_connection_query (dbConnection, query.utf8 ().get_data (), &result);
203
212
204
- if (state != KuzuSuccess || !&result) {
205
- return Array ();
206
- }
207
-
208
213
Array result_array;
209
214
215
+ if (state != KuzuSuccess) {
216
+ char *error_msg = kuzu_query_result_get_error_message (&result);
217
+
218
+ UtilityFunctions::push_error (" KuzuGD ERROR | Query - " + String (error_msg));
219
+ result_array.append (" ERROR: " + String (error_msg));
220
+ return result_array;
221
+ }
222
+
210
223
while (true ) {
211
224
kuzu_flat_tuple row;
212
- if (kuzu_query_result_get_next (&result, &row) != KuzuSuccess || !&row ) {
225
+ if (kuzu_query_result_get_next (&result, &row) != KuzuSuccess) {
213
226
break ;
214
227
}
215
228
@@ -234,18 +247,24 @@ Array KuzuGD::execute_query(const String &query) {
234
247
Array KuzuGD::execute_prepared_query (const String &query, const Dictionary ¶ms) {
235
248
kuzu_prepared_statement stmt;
236
249
if (kuzu_connection_prepare (dbConnection, query.utf8 ().get_data (), &stmt) != KuzuSuccess) {
237
- return Array (); // Return empty array if preparation fails
250
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to prepare query" );
251
+ return Array ();
238
252
}
239
253
240
254
// Bind parameters
241
255
for (int i = 0 ; i < params.size (); i++) {
242
256
String key = params.keys ()[i];
243
257
Variant value = params.values ()[i];
244
258
245
- // Godot does not support the same types as Kuzu
259
+ // ! Godot does not support the same types as Kuzu
246
260
switch (value.get_type ()) {
247
261
case Variant::INT: {
248
- kuzu_prepared_statement_bind_int64 (&stmt, key.utf8 ().get_data (), value.operator int64_t ());
262
+ kuzu_state stateSuccess = kuzu_prepared_statement_bind_int64 (&stmt, key.utf8 ().get_data (), value.operator int64_t ());
263
+
264
+ if (stateSuccess != KuzuSuccess) {
265
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind INT to Query Parameter" );
266
+ }
267
+
249
268
break ;
250
269
}
251
270
@@ -255,26 +274,38 @@ Array KuzuGD::execute_prepared_query(const String &query, const Dictionary ¶
255
274
if (is_date (string_value)) {
256
275
kuzu_date_t *kuzuDate = nullptr ;
257
276
258
- kuzu_date_from_string (string_value.c_str (), kuzuDate);
259
- kuzu_prepared_statement_bind_date (
277
+ kuzu_state stateSuccess = kuzu_date_from_string (string_value.c_str (), kuzuDate);
278
+ if (stateSuccess != KuzuSuccess) {
279
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to convert STRING into Date" );
280
+ }
281
+
282
+ kuzu_state stateSuccess2 = kuzu_prepared_statement_bind_date (
260
283
&stmt, key.utf8 ().get_data (),
261
284
*kuzuDate);
285
+
286
+ if (stateSuccess2 != KuzuSuccess) {
287
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind Date to Query Parameter" );
288
+ }
262
289
}
263
290
264
291
else if (is_timestamp_tz (string_value)) {
265
292
ParsedTime tmp_time;
266
293
string_to_tm (string_value, tmp_time);
267
294
268
295
kuzu_timestamp_tz_t kuzu_ts;
269
- kuzu_state state = kuzu_timestamp_tz_from_tm (tmp_time.tm_value , &kuzu_ts);
296
+ kuzu_state stateSuccess = kuzu_timestamp_tz_from_tm (tmp_time.tm_value , &kuzu_ts);
270
297
kuzu_ts.value += tmp_time.tz_offset_microseconds ;
271
298
272
- if (state == KuzuSuccess) {
273
- kuzu_prepared_statement_bind_timestamp_tz (
299
+ if (stateSuccess == KuzuSuccess) {
300
+ kuzu_state stateSuccess2 = kuzu_prepared_statement_bind_timestamp_tz (
274
301
&stmt, key.utf8 ().get_data (),
275
302
kuzu_ts);
303
+
304
+ if (stateSuccess2 != KuzuSuccess) {
305
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind TimeZone TimeStamp to Query Parameter" );
306
+ }
276
307
} else {
277
- UtilityFunctions::print ( " TimeStamp Format is not a Time Zone" );
308
+ UtilityFunctions::push_error ( " KuzuGD ERROR | Prepared Query - FAILED Timestamp Format is not a Time Zone" );
278
309
}
279
310
}
280
311
@@ -283,56 +314,83 @@ Array KuzuGD::execute_prepared_query(const String &query, const Dictionary ¶
283
314
string_to_tm (string_value, tmp_time);
284
315
285
316
kuzu_timestamp_t kuzu_ts;
286
- kuzu_state state = kuzu_timestamp_from_tm (tmp_time.tm_value , &kuzu_ts);
317
+ kuzu_state stateSuccess = kuzu_timestamp_from_tm (tmp_time.tm_value , &kuzu_ts);
287
318
288
- if (state == KuzuSuccess) {
289
- kuzu_prepared_statement_bind_timestamp (
319
+ if (stateSuccess == KuzuSuccess) {
320
+ kuzu_state stateSuccess2 = kuzu_prepared_statement_bind_timestamp (
290
321
&stmt, key.utf8 ().get_data (),
291
322
kuzu_ts);
323
+ if (stateSuccess2 != KuzuSuccess) {
324
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind TIMESTAMP to Query Parameter" );
325
+ }
292
326
} else {
293
- UtilityFunctions::print ( " TimeStamp Format is not a Time Zone " );
327
+ UtilityFunctions::push_error ( " KuzuGD ERROR | Prepared Query - FAILED Time is not a Timestamp " );
294
328
}
295
329
}
296
330
297
331
else if (is_interval (string_value)) {
298
- kuzu_prepared_statement_bind_interval (
332
+ kuzu_state stateSuccess = kuzu_prepared_statement_bind_interval (
299
333
&stmt, key.utf8 ().get_data (),
300
334
string_to_kuzu_interval (string_value));
335
+
336
+ if (stateSuccess != KuzuSuccess) {
337
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind INTERVAL to Query Parameter" );
338
+ }
301
339
}
302
340
303
341
else {
304
- kuzu_prepared_statement_bind_string (&stmt, key.utf8 ().get_data (), string_value.c_str ());
342
+ kuzu_state stateSuccess = kuzu_prepared_statement_bind_string (&stmt, key.utf8 ().get_data (), string_value.c_str ());
343
+
344
+ if (stateSuccess != KuzuSuccess) {
345
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind STRING to Query Parameter" );
346
+ }
305
347
}
306
348
307
349
break ;
308
350
}
309
351
310
352
case Variant::BOOL: {
311
- kuzu_prepared_statement_bind_bool (&stmt, key.utf8 ().get_data (), value.operator bool ());
353
+ kuzu_state stateSuccess = kuzu_prepared_statement_bind_bool (&stmt, key.utf8 ().get_data (), value.operator bool ());
354
+
355
+ if (stateSuccess != KuzuSuccess) {
356
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind BOOL to Query Parameter" );
357
+ }
358
+
312
359
break ;
313
360
}
314
361
315
362
case Variant::FLOAT: {
316
- kuzu_prepared_statement_bind_float (&stmt, key.utf8 ().get_data (), value.operator float ());
363
+ kuzu_state stateSuccess = kuzu_prepared_statement_bind_float (&stmt, key.utf8 ().get_data (), value.operator float ());
364
+
365
+ if (stateSuccess != KuzuSuccess) {
366
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind FLOAT to Query Parameter" );
367
+ }
368
+
317
369
break ;
318
370
}
319
371
320
372
default :
321
- UtilityFunctions::push_error (" KuzuGD Error | Prepared Query - Unsupported data type for binding: " + key);
373
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED Unsupported data type for binding: " + key);
322
374
}
323
375
}
324
376
377
+ Array result_array;
325
378
// Execute the query
326
379
kuzu_query_result result;
327
380
if (kuzu_connection_execute (dbConnection, &stmt, &result) != KuzuSuccess) {
381
+ char *error_msg = kuzu_prepared_statement_get_error_message (&stmt);
382
+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - " + String (error_msg));
383
+
384
+ result_array.append (" ERROR: " + String (error_msg));
385
+
328
386
return Array (); // Return empty array if execution fails
329
387
}
330
388
331
389
// Process result
332
- Array result_array;
333
390
while (true ) {
334
391
kuzu_flat_tuple row;
335
- if (kuzu_query_result_get_next (&result, &row) != KuzuSuccess || &row == nullptr ) {
392
+ if (kuzu_query_result_get_next (&result, &row) != KuzuSuccess) {
393
+ UtilityFunctions::print (" Breaking" );
336
394
break ;
337
395
}
338
396
0 commit comments