@@ -124,13 +124,13 @@ Array KuzuGD::get_config() const {
124124
125125bool KuzuGD::kuzu_init (const String database_path) {
126126 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" );
128128 return false ;
129129 }
130130
131131 myKuzuDB = (kuzu_database *)malloc (sizeof (kuzu_database));
132132 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" );
134134 return false ;
135135 }
136136 myKuzuDB->_database = nullptr ;
@@ -147,7 +147,7 @@ bool KuzuGD::kuzu_init(const String database_path) {
147147bool KuzuGD::kuzu_connect (int num_threads) {
148148 dbConnection = (kuzu_connection *)malloc (sizeof (kuzu_connection));
149149 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" );
151151 return false ;
152152 }
153153 memset (dbConnection, 0 , sizeof (kuzu_connection));
@@ -161,16 +161,23 @@ bool KuzuGD::kuzu_connect(int num_threads) {
161161 kuzu_connection_set_max_num_thread_for_exec (
162162 dbConnection,
163163 num_threads);
164- }
164+ return state == KuzuSuccess;
165165
166- return state == KuzuSuccess;
166+ } else {
167+ UtilityFunctions::push_error (" KuzuGD ERROR | Kuzu Connection FAILED" );
168+ return state == KuzuError;
169+ }
167170}
168171
169172bool KuzuGD::connection_set_max_threads (int num_threads) {
170173 kuzu_state state = kuzu_connection_set_max_num_thread_for_exec (
171174 dbConnection,
172175 num_threads);
173176
177+ if (state == KuzuError) {
178+ UtilityFunctions::push_error (" KuzuGD ERROR | Kuzu Set Max Threads FAILED" );
179+ }
180+
174181 return state == KuzuSuccess;
175182}
176183
@@ -183,6 +190,8 @@ int KuzuGD::connection_get_max_threads() {
183190 if (state == KuzuSuccess) {
184191 return static_cast <int >(result);
185192 } else {
193+ UtilityFunctions::push_error (" KuzuGD ERROR | FAILED to Obtain Max Num Threads for Connection" );
194+
186195 return -1 ;
187196 }
188197}
@@ -201,15 +210,19 @@ Array KuzuGD::execute_query(const String &query) {
201210 kuzu_query_result result;
202211 kuzu_state state = kuzu_connection_query (dbConnection, query.utf8 ().get_data (), &result);
203212
204- if (state != KuzuSuccess || !&result) {
205- return Array ();
206- }
207-
208213 Array result_array;
209214
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+
210223 while (true ) {
211224 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) {
213226 break ;
214227 }
215228
@@ -234,18 +247,24 @@ Array KuzuGD::execute_query(const String &query) {
234247Array KuzuGD::execute_prepared_query (const String &query, const Dictionary ¶ms) {
235248 kuzu_prepared_statement stmt;
236249 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 ();
238252 }
239253
240254 // Bind parameters
241255 for (int i = 0 ; i < params.size (); i++) {
242256 String key = params.keys ()[i];
243257 Variant value = params.values ()[i];
244258
245- // Godot does not support the same types as Kuzu
259+ // ! Godot does not support the same types as Kuzu
246260 switch (value.get_type ()) {
247261 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+
249268 break ;
250269 }
251270
@@ -255,26 +274,38 @@ Array KuzuGD::execute_prepared_query(const String &query, const Dictionary ¶
255274 if (is_date (string_value)) {
256275 kuzu_date_t *kuzuDate = nullptr ;
257276
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 (
260283 &stmt, key.utf8 ().get_data (),
261284 *kuzuDate);
285+
286+ if (stateSuccess2 != KuzuSuccess) {
287+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind Date to Query Parameter" );
288+ }
262289 }
263290
264291 else if (is_timestamp_tz (string_value)) {
265292 ParsedTime tmp_time;
266293 string_to_tm (string_value, tmp_time);
267294
268295 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);
270297 kuzu_ts.value += tmp_time.tz_offset_microseconds ;
271298
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 (
274301 &stmt, key.utf8 ().get_data (),
275302 kuzu_ts);
303+
304+ if (stateSuccess2 != KuzuSuccess) {
305+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind TimeZone TimeStamp to Query Parameter" );
306+ }
276307 } 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" );
278309 }
279310 }
280311
@@ -283,56 +314,83 @@ Array KuzuGD::execute_prepared_query(const String &query, const Dictionary ¶
283314 string_to_tm (string_value, tmp_time);
284315
285316 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);
287318
288- if (state == KuzuSuccess) {
289- kuzu_prepared_statement_bind_timestamp (
319+ if (stateSuccess == KuzuSuccess) {
320+ kuzu_state stateSuccess2 = kuzu_prepared_statement_bind_timestamp (
290321 &stmt, key.utf8 ().get_data (),
291322 kuzu_ts);
323+ if (stateSuccess2 != KuzuSuccess) {
324+ UtilityFunctions::push_error (" KuzuGD ERROR | Prepared Query - FAILED to bind TIMESTAMP to Query Parameter" );
325+ }
292326 } 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 " );
294328 }
295329 }
296330
297331 else if (is_interval (string_value)) {
298- kuzu_prepared_statement_bind_interval (
332+ kuzu_state stateSuccess = kuzu_prepared_statement_bind_interval (
299333 &stmt, key.utf8 ().get_data (),
300334 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+ }
301339 }
302340
303341 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+ }
305347 }
306348
307349 break ;
308350 }
309351
310352 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+
312359 break ;
313360 }
314361
315362 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+
317369 break ;
318370 }
319371
320372 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);
322374 }
323375 }
324376
377+ Array result_array;
325378 // Execute the query
326379 kuzu_query_result result;
327380 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+
328386 return Array (); // Return empty array if execution fails
329387 }
330388
331389 // Process result
332- Array result_array;
333390 while (true ) {
334391 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" );
336394 break ;
337395 }
338396
0 commit comments