esodan commented on issue #1280:
URL: https://github.com/apache/arrow-adbc/issues/1280#issuecomment-1823502289

   I'm trying to create a functional API, but found I haven't enough knowledge 
to handle memory issues when C++ is in the middle. There is an example for Vala 
using correctly the API when `void*` is used. But when I wrap the same but 
creating a `GArrow.RecordBatchReader` in the method, the Vala software fails 
with a segmentation fault, and I was unable to handle the problem:
   
   This method calls `gadbc_statement_execute_internal` which is exactly the 
same `gadbc_statement_execute`, but renamed to share it with current API, 
please don't worry I'll move my code to the place is better following your 
recommendations, but know I was unable to understand the problem. Next method 
is using as `Statement.execute_stream()` returning a 
`GArrow.RecordBatchReader`, but when used this object fails to a segmentation 
fault; means I'm using incorrectly the memory.
   
   This is the method I'm using to call from Vala:
   ```c
   GArrowRecordBatchReader*
   gadbc_statement_execute_stream(GADBCStatement* statement,
                                    gint64* n_rows_affected,
                                    GError** error) {
     gpointer stream;
     if (!gadbc_statement_execute_internal(statement, TRUE,
                                &stream, n_rows_affected, error)) {
       return NULL;
     }
     GArrowRecordBatchReader *reader = 
garrow_record_batch_reader_import(stream, error);
     //g_free(stream);
     return reader;
   }
   ```
   
   This is the code in Vala:
   
   ```vala
   // Licensed to the Apache Software Foundation (ASF) under one
   // or more contributor license agreements.  See the NOTICE file
   // distributed with this work for additional information
   // regarding copyright ownership.  The ASF licenses this file
   // to you under the Apache License, Version 2.0 (the
   // "License"); you may not use this file except in compliance
   // with the License.  You may obtain a copy of the License at
   //
   //   http://www.apache.org/licenses/LICENSE-2.0
   //
   // Unless required by applicable law or agreed to in writing,
   // software distributed under the License is distributed on an
   // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   // KIND, either express or implied.  See the License for the
   // specific language governing permissions and limitations
   // under the License.
   
   int main (string[] args) {
       var exit_code = Posix.EXIT_FAILURE;
   
       try {
           var database = new GADBC.Database ();
           database.set_option ("driver", "adbc_driver_sqlite");
           database.set_option ("uri", ":memory:");
           database.init ();
           try {
               var connection = new GADBC.Connection ();
               connection.init (database);
               try {
                   var statement = new GADBC.Statement (connection);
                   string sql = "SELECT sqlite_version() AS version";
                   statement.set_sql_query (sql);
                   try {
                       int64 n_rows_affected = 0;
                       GArrow.RecordBatchReader reader = 
statement.execute_stream (out n_rows_affected);
                       try {
                           var table = reader.read_all ();
                           stdout.printf ("Result:\n%s", table.to_string ());
                       } catch (GLib.Error error) {
                           GLib.error ("Failed to read table: %s", 
error.message);
                       }
                       exit_code = Posix.EXIT_SUCCESS;
                   } catch (GLib.Error error) {
                       GLib.error ("Failed to execute a statement: %s", 
error.message);
                   }
               }
               catch (GLib.Error error) {
                   GLib.error ("Failed to create a statement: %s", 
error.message);
               }
           }
           catch (GLib.Error error) {
               GLib.error ("Failed to create a connection: %s", error.message);
           }
       }
       catch (GLib.Error error) {
           GLib.error ("Failed to create a database: %s", error.message);
       }
   
       return exit_code;
   }
   ```
   Fails exactly on `var table = reader.read_all ();`, so please help me here, 
so I can understand how to write the next methods and create the GObject 
Introspection friendly API as propoused. Also, feel free to write them your 
self if you consider can't point me how to go here, I'll just step a side.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to