@@ -123,15 +123,14 @@ Array KuzuGD::get_config() const {
123
123
******************************************************************/
124
124
125
125
bool KuzuGD::kuzu_init (const String database_path) {
126
- UtilityFunctions::print (" Kuzu Init Start" );
127
126
if (database_path.is_empty ()) {
128
- UtilityFunctions::print ( " Error: Database path is empty! " );
127
+ UtilityFunctions::push_error ( " KuzuGD Error | Database path is empty" );
129
128
return false ;
130
129
}
131
130
132
131
myKuzuDB = (kuzu_database *)malloc (sizeof (kuzu_database));
133
132
if (!myKuzuDB) {
134
- UtilityFunctions::print ( " Error: Memory allocation failed for KuzuDB! " );
133
+ UtilityFunctions::push_error ( " KuzuGD Error | Memory allocation failed for KuzuDB Init " );
135
134
return false ;
136
135
}
137
136
myKuzuDB->_database = nullptr ;
@@ -148,7 +147,7 @@ bool KuzuGD::kuzu_init(const String database_path) {
148
147
bool KuzuGD::kuzu_connect (int num_threads) {
149
148
dbConnection = (kuzu_connection *)malloc (sizeof (kuzu_connection));
150
149
if (!dbConnection) {
151
- UtilityFunctions::print ( " Error: Memory allocation failed for KuzuDB Connection! " );
150
+ UtilityFunctions::push_error ( " KuzuGD Error | Memory allocation failed for KuzuDB Connect " );
152
151
return false ;
153
152
}
154
153
memset (dbConnection, 0 , sizeof (kuzu_connection));
@@ -176,13 +175,13 @@ bool KuzuGD::connection_set_max_threads(int num_threads) {
176
175
}
177
176
178
177
int KuzuGD::connection_get_max_threads () {
179
- uint64_t * result = nullptr ;
178
+ uint64_t result = 0 ;
180
179
kuzu_state state = kuzu_connection_get_max_num_thread_for_exec (
181
180
dbConnection,
182
- result);
181
+ & result);
183
182
184
183
if (state == KuzuSuccess) {
185
- return static_cast <int >(* result);
184
+ return static_cast <int >(result);
186
185
} else {
187
186
return -1 ;
188
187
}
@@ -199,68 +198,66 @@ int KuzuGD::connection_get_max_threads() {
199
198
******************************************************************/
200
199
201
200
Array KuzuGD::execute_query (const String &query) {
202
- kuzu_query_result * result = nullptr ;
203
- kuzu_state state = kuzu_connection_query (dbConnection, query.utf8 ().get_data (), result);
201
+ kuzu_query_result result;
202
+ kuzu_state state = kuzu_connection_query (dbConnection, query.utf8 ().get_data (), & result);
204
203
205
- if (state != KuzuSuccess || !result) {
204
+ if (state != KuzuSuccess || !& result) {
206
205
return Array ();
207
206
}
208
207
209
208
Array result_array;
210
209
211
- while (true ) { // Instead of checking `has_next()`, we retrieve directly
212
- kuzu_flat_tuple * row = nullptr ;
213
- if (kuzu_query_result_get_next (result, row) != KuzuSuccess || !row) {
210
+ while (true ) {
211
+ kuzu_flat_tuple row;
212
+ if (kuzu_query_result_get_next (& result, & row) != KuzuSuccess || !& row) {
214
213
break ;
215
214
}
216
215
217
216
Dictionary row_dict;
218
217
219
- for (uint32_t i = 0 ; i < kuzu_query_result_get_num_columns (result); i++) {
220
- // Fix column name retrieval using an output parameter
218
+ for (uint32_t i = 0 ; i < kuzu_query_result_get_num_columns (&result); i++) {
221
219
char *column_name;
222
- if (kuzu_query_result_get_column_name (result, i, &column_name) == KuzuSuccess) {
223
- // Fix value retrieval using an output parameter
224
- kuzu_value *value = nullptr ;
225
- if (kuzu_flat_tuple_get_value (row, i, value) == KuzuSuccess) {
226
- row_dict[String (column_name)] = kuzu_value_to_string (value);
220
+ if (kuzu_query_result_get_column_name (&result, i, &column_name) == KuzuSuccess) {
221
+ kuzu_value value;
222
+ if (kuzu_flat_tuple_get_value (&row, i, &value) == KuzuSuccess) {
223
+ row_dict[String (column_name)] = kuzu_value_to_string (&value);
227
224
}
228
225
}
229
226
}
230
227
231
- result_array.append (row_dict); // Store row dictionary directly in the array
228
+ result_array.append (row_dict);
232
229
}
233
230
234
231
return result_array;
235
232
}
236
233
237
- Array KuzuGD::execute_prepared_query (const godot:: String &query, const godot:: Dictionary ¶ms) {
238
- kuzu_prepared_statement * stmt = nullptr ;
239
- if (kuzu_connection_prepare (dbConnection, query.utf8 ().get_data (), stmt) != KuzuSuccess) {
240
- return godot:: Array (); // Return empty array if preparation fails
234
+ Array KuzuGD::execute_prepared_query (const String &query, const Dictionary ¶ms) {
235
+ kuzu_prepared_statement stmt;
236
+ if (kuzu_connection_prepare (dbConnection, query.utf8 ().get_data (), & stmt) != KuzuSuccess) {
237
+ return Array (); // Return empty array if preparation fails
241
238
}
242
239
243
240
// Bind parameters
244
241
for (int i = 0 ; i < params.size (); i++) {
245
- godot:: String key = params.keys ()[i];
246
- godot:: Variant value = params.values ()[i];
242
+ String key = params.keys ()[i];
243
+ Variant value = params.values ()[i];
247
244
248
245
// Godot does not support the same types as Kuzu
249
246
switch (value.get_type ()) {
250
- case godot:: Variant::INT: {
251
- kuzu_prepared_statement_bind_int64 (stmt, key.utf8 ().get_data (), value.operator int64_t ());
247
+ case Variant::INT: {
248
+ kuzu_prepared_statement_bind_int64 (& stmt, key.utf8 ().get_data (), value.operator int64_t ());
252
249
break ;
253
250
}
254
251
255
- case godot:: Variant::STRING: {
256
- string string_value = value.operator godot:: String ().utf8 ().get_data ();
252
+ case Variant::STRING: {
253
+ string string_value = value.operator String ().utf8 ().get_data ();
257
254
258
255
if (is_date (string_value)) {
259
256
kuzu_date_t *kuzuDate = nullptr ;
260
257
261
258
kuzu_date_from_string (string_value.c_str (), kuzuDate);
262
259
kuzu_prepared_statement_bind_date (
263
- stmt, key.utf8 ().get_data (),
260
+ & stmt, key.utf8 ().get_data (),
264
261
*kuzuDate);
265
262
}
266
263
@@ -274,7 +271,7 @@ Array KuzuGD::execute_prepared_query(const godot::String &query, const godot::Di
274
271
275
272
if (state == KuzuSuccess) {
276
273
kuzu_prepared_statement_bind_timestamp_tz (
277
- stmt, key.utf8 ().get_data (),
274
+ & stmt, key.utf8 ().get_data (),
278
275
kuzu_ts);
279
276
} else {
280
277
UtilityFunctions::print (" TimeStamp Format is not a Time Zone" );
@@ -290,7 +287,7 @@ Array KuzuGD::execute_prepared_query(const godot::String &query, const godot::Di
290
287
291
288
if (state == KuzuSuccess) {
292
289
kuzu_prepared_statement_bind_timestamp (
293
- stmt, key.utf8 ().get_data (),
290
+ & stmt, key.utf8 ().get_data (),
294
291
kuzu_ts);
295
292
} else {
296
293
UtilityFunctions::print (" TimeStamp Format is not a Time Zone" );
@@ -299,53 +296,53 @@ Array KuzuGD::execute_prepared_query(const godot::String &query, const godot::Di
299
296
300
297
else if (is_interval (string_value)) {
301
298
kuzu_prepared_statement_bind_interval (
302
- stmt, key.utf8 ().get_data (),
299
+ & stmt, key.utf8 ().get_data (),
303
300
string_to_kuzu_interval (string_value));
304
301
}
305
302
306
303
else {
307
- kuzu_prepared_statement_bind_string (stmt, key.utf8 ().get_data (), string_value.c_str ());
304
+ kuzu_prepared_statement_bind_string (& stmt, key.utf8 ().get_data (), string_value.c_str ());
308
305
}
309
306
310
307
break ;
311
308
}
312
309
313
- case godot:: Variant::BOOL: {
314
- kuzu_prepared_statement_bind_bool (stmt, key.utf8 ().get_data (), value.operator bool ());
310
+ case Variant::BOOL: {
311
+ kuzu_prepared_statement_bind_bool (& stmt, key.utf8 ().get_data (), value.operator bool ());
315
312
break ;
316
313
}
317
314
318
- case godot:: Variant::FLOAT: {
319
- kuzu_prepared_statement_bind_float (stmt, key.utf8 ().get_data (), value.operator float ());
315
+ case Variant::FLOAT: {
316
+ kuzu_prepared_statement_bind_float (& stmt, key.utf8 ().get_data (), value.operator float ());
320
317
break ;
321
318
}
322
319
323
320
default :
324
- UtilityFunctions::print ( " Unsupported data type for binding: " + key);
321
+ UtilityFunctions::push_error ( " KuzuGD Error | Prepared Query - Unsupported data type for binding: " + key);
325
322
}
326
323
}
327
324
328
325
// Execute the query
329
- kuzu_query_result * result = nullptr ;
330
- if (kuzu_connection_execute (dbConnection, stmt, result) != KuzuSuccess) {
331
- return godot:: Array (); // Return empty array if execution fails
326
+ kuzu_query_result result;
327
+ if (kuzu_connection_execute (dbConnection, & stmt, & result) != KuzuSuccess) {
328
+ return Array (); // Return empty array if execution fails
332
329
}
333
330
334
331
// Process result
335
- godot:: Array result_array;
332
+ Array result_array;
336
333
while (true ) {
337
- kuzu_flat_tuple * row = nullptr ;
338
- if (kuzu_query_result_get_next (result, row) != KuzuSuccess || row == nullptr ) {
334
+ kuzu_flat_tuple row;
335
+ if (kuzu_query_result_get_next (& result, & row) != KuzuSuccess || & row == nullptr ) {
339
336
break ;
340
337
}
341
338
342
- godot:: Dictionary row_dict;
343
- for (uint32_t i = 0 ; i < kuzu_query_result_get_num_columns (result); i++) {
339
+ Dictionary row_dict;
340
+ for (uint32_t i = 0 ; i < kuzu_query_result_get_num_columns (& result); i++) {
344
341
char *column_name;
345
- if (kuzu_query_result_get_column_name (result, i, &column_name) == KuzuSuccess) {
346
- kuzu_value * value = nullptr ;
347
- if (kuzu_flat_tuple_get_value (row, i, value) == KuzuSuccess) {
348
- row_dict[String (column_name)] = kuzu_value_to_string (value);
342
+ if (kuzu_query_result_get_column_name (& result, i, &column_name) == KuzuSuccess) {
343
+ kuzu_value value;
344
+ if (kuzu_flat_tuple_get_value (& row, i, & value) == KuzuSuccess) {
345
+ row_dict[String (column_name)] = kuzu_value_to_string (& value);
349
346
}
350
347
}
351
348
}
0 commit comments