This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 2de52f3d fix(csharp): include GetTableTypes and GetTableSchema call 
for .NET 4.7.2  (#950)
2de52f3d is described below

commit 2de52f3d8eec6aabbe6423587bc929cda91faf9f
Author: davidhcoe <[email protected]>
AuthorDate: Mon Jul 31 11:02:37 2023 -0400

    fix(csharp): include GetTableTypes and GetTableSchema call for .NET 4.7.2  
(#950)
    
    Continuation of https://github.com/apache/arrow-adbc/issues/930
    
    Resolve https://github.com/apache/arrow-adbc/issues/947
    
    ---------
    
    Co-authored-by: David Coe <[email protected]>
---
 csharp/src/Apache.Arrow.Adbc/AdbcException.cs      | 116 +++++++++---------
 .../src/Apache.Arrow.Adbc/C/CAdbcDriverExporter.cs |   4 +-
 .../src/Apache.Arrow.Adbc/C/CAdbcDriverImporter.cs | 129 +++++++++++++++++----
 3 files changed, 166 insertions(+), 83 deletions(-)

diff --git a/csharp/src/Apache.Arrow.Adbc/AdbcException.cs 
b/csharp/src/Apache.Arrow.Adbc/AdbcException.cs
index 8c1e6ed6..288d9df8 100644
--- a/csharp/src/Apache.Arrow.Adbc/AdbcException.cs
+++ b/csharp/src/Apache.Arrow.Adbc/AdbcException.cs
@@ -16,73 +16,75 @@
  */
 
 using System;
-using Apache.Arrow.Adbc;
 
-/// <summary>
-/// The root exception when working with Adbc drivers.
-/// </summary>
-public class AdbcException : Exception
+namespace Apache.Arrow.Adbc
 {
-    private AdbcStatusCode _statusCode = AdbcStatusCode.UnknownError;
-
-    public AdbcException()
+    /// <summary>
+    /// The root exception when working with Adbc drivers.
+    /// </summary>
+    public class AdbcException : Exception
     {
-    }
+        private AdbcStatusCode _statusCode = AdbcStatusCode.UnknownError;
 
-    public AdbcException(string message)
-        : base(message)
-    {
-    }
+        public AdbcException()
+        {
+        }
 
-    public AdbcException(string message, AdbcStatusCode statusCode)
-        : base(message)
-    {
-        _statusCode = statusCode;
-    }
+        public AdbcException(string message)
+            : base(message)
+        {
+        }
 
-    public AdbcException(string message, AdbcStatusCode statusCode, Exception 
innerException)
-       : base(message, innerException)
-    {
-    }
+        public AdbcException(string message, AdbcStatusCode statusCode)
+            : base(message)
+        {
+            _statusCode = statusCode;
+        }
 
-    public AdbcException(string message, Exception innerException)
-        : base(message, innerException)
-    {
-    }
+        public AdbcException(string message, AdbcStatusCode statusCode, 
Exception innerException)
+           : base(message, innerException)
+        {
+        }
 
-    public static AdbcException NotImplemented(string message)
-    {
-        return new AdbcException(message, AdbcStatusCode.NotImplemented);
-    }
+        public AdbcException(string message, Exception innerException)
+            : base(message, innerException)
+        {
+        }
 
-    /// <summary>
-    /// For database providers which support it, contains a standard
-    /// SQL 5-character return code indicating the success or failure
-    /// of the database operation. The first 2 characters represent the
-    /// class of the return code (e.g. error, success), while the
-    /// last 3 characters represent the subclass, allowing detection
-    /// of error scenarios in a database-portable way.
-    /// For database providers which don't support it, or for
-    /// inapplicable error scenarios, contains null.
-    /// </summary>
-    public virtual string SqlState
-    {
-        get => null;
-    }
+        public static AdbcException NotImplemented(string message)
+        {
+            return new AdbcException(message, AdbcStatusCode.NotImplemented);
+        }
 
-    /// <summary>
-    /// Gets or sets the <see cref="AdbcStatusCode"/> for the error.
-    /// </summary>
-    public AdbcStatusCode Status
-    {
-        get => _statusCode;
-    }
+        /// <summary>
+        /// For database providers which support it, contains a standard
+        /// SQL 5-character return code indicating the success or failure
+        /// of the database operation. The first 2 characters represent the
+        /// class of the return code (e.g. error, success), while the
+        /// last 3 characters represent the subclass, allowing detection
+        /// of error scenarios in a database-portable way.
+        /// For database providers which don't support it, or for
+        /// inapplicable error scenarios, contains null.
+        /// </summary>
+        public virtual string SqlState
+        {
+            get => null;
+        }
 
-    /// <summary>
-    /// Gets a native error number.
-    /// </summary>
-    public virtual int NativeError
-    {
-        get => 0;
+        /// <summary>
+        /// Gets or sets the <see cref="AdbcStatusCode"/> for the error.
+        /// </summary>
+        public AdbcStatusCode Status
+        {
+            get => _statusCode;
+        }
+
+        /// <summary>
+        /// Gets a native error number.
+        /// </summary>
+        public virtual int NativeError
+        {
+            get => 0;
+        }
     }
 }
diff --git a/csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverExporter.cs 
b/csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverExporter.cs
index eb0c5e25..33d80f0f 100644
--- a/csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverExporter.cs
+++ b/csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverExporter.cs
@@ -78,10 +78,10 @@ namespace Apache.Arrow.Adbc.C
         internal unsafe delegate AdbcStatusCode 
ConnectionGetObjects(CAdbcConnection* connection, int depth, byte* catalog, 
byte* db_schema, byte* table_name, byte** table_type, byte* column_name, 
CArrowArrayStream* stream, CAdbcError* error);
         private static unsafe readonly NativeDelegate<ConnectionGetObjects> 
s_connectionGetObjects = new 
NativeDelegate<ConnectionGetObjects>(GetConnectionObjects);
         private static IntPtr ConnectionGetObjectsPtr => 
s_connectionGetObjects.Pointer;
-        private unsafe delegate AdbcStatusCode 
ConnectionGetTableSchema(CAdbcConnection* connection, byte* catalog, byte* 
db_schema, byte* table_name, CArrowSchema* schema, CAdbcError* error);
+        internal unsafe delegate AdbcStatusCode 
ConnectionGetTableSchema(CAdbcConnection* connection, byte* catalog, byte* 
db_schema, byte* table_name, CArrowSchema* schema, CAdbcError* error);
         private static unsafe readonly 
NativeDelegate<ConnectionGetTableSchema> s_connectionGetTableSchema = new 
NativeDelegate<ConnectionGetTableSchema>(GetConnectionTableSchema);
         private static IntPtr ConnectionGetTableSchemaPtr => 
s_connectionGetTableSchema.Pointer;
-        private unsafe delegate AdbcStatusCode 
ConnectionGetTableTypes(CAdbcConnection* connection, CArrowArrayStream* stream, 
CAdbcError* error);
+        internal unsafe delegate AdbcStatusCode 
ConnectionGetTableTypes(CAdbcConnection* connection, CArrowArrayStream* stream, 
CAdbcError* error);
         private static unsafe readonly NativeDelegate<ConnectionGetTableTypes> 
s_connectionGetTableTypes = new 
NativeDelegate<ConnectionGetTableTypes>(GetConnectionTableTypes);
         private static IntPtr ConnectionGetTableTypesPtr => 
s_connectionGetTableTypes.Pointer;
         internal unsafe delegate AdbcStatusCode 
ConnectionInit(CAdbcConnection* connection, CAdbcDatabase* database, 
CAdbcError* error);
diff --git a/csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverImporter.cs 
b/csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverImporter.cs
index 10808764..13449a3c 100644
--- a/csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverImporter.cs
+++ b/csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverImporter.cs
@@ -254,6 +254,34 @@ namespace Apache.Arrow.Adbc.C
 
                 return arrowArrayStream;
             }
+
+            public override unsafe IArrowArrayStream GetTableTypes()
+            {
+                CArrowArrayStream* nativeArrayStream = 
CArrowArrayStream.Create();
+
+                using (CallHelper caller = new CallHelper())
+                {
+                    caller.Call(_nativeDriver.ConnectionGetTableTypes, ref 
_nativeConnection, nativeArrayStream);
+                }
+
+                IArrowArrayStream arrowArrayStream = 
CArrowArrayStreamImporter.ImportArrayStream(nativeArrayStream);
+
+                return arrowArrayStream;
+            }
+
+            public override unsafe Schema GetTableSchema(string catalog, 
string db_schema, string table_name)
+            {
+                CArrowSchema* nativeSchema = CArrowSchema.Create();
+
+                using (CallHelper caller = new CallHelper())
+                {
+                    caller.Call(_nativeDriver.ConnectionGetTableSchema, ref 
_nativeConnection, catalog, db_schema, table_name, nativeSchema);
+                }
+
+                Schema schema = 
CArrowSchemaImporter.ImportSchema(nativeSchema);
+
+                return schema;
+            }
         }
 
         /// <summary>
@@ -585,6 +613,68 @@ namespace Apache.Arrow.Adbc.C
             }
 #endif
 
+#if NET5_0_OR_GREATER
+            public unsafe void Call(delegate* unmanaged<CAdbcConnection*, 
byte*, byte*, byte*, CArrowSchema*, CAdbcError*, AdbcStatusCode> fn, ref 
CAdbcConnection nativeconnection, string catalog, string dbSchema, string 
tableName, CArrowSchema* nativeSchema)
+            {
+                byte* bCatalog, bDb_schema, bTable_name;
+
+                using (Utf8Helper catalogHelper = new Utf8Helper(catalog))
+                using (Utf8Helper schemaHelper = new Utf8Helper(dbSchema))
+                using (Utf8Helper tableNameHelper = new Utf8Helper(tableName))
+                {
+                    bCatalog = (byte*)(IntPtr)(catalogHelper);
+                    bDb_schema = (byte*)(IntPtr)(schemaHelper);
+                    bTable_name = (byte*)(IntPtr)(tableNameHelper);
+
+                    fixed (CAdbcConnection* connection = &nativeconnection)
+                    fixed (CAdbcError* e = &_error)
+                    {
+                        TranslateCode(fn(connection, bCatalog, bDb_schema, 
bTable_name, nativeSchema, e));
+                    }
+                }
+            }
+#else
+            public unsafe void Call(IntPtr fn, ref CAdbcConnection 
nativeconnection, string catalog, string dbSchema, string tableName, 
CArrowSchema* nativeSchema)
+            {
+                byte* bCatalog, bDb_schema, bTable_name;
+
+                using (Utf8Helper catalogHelper = new Utf8Helper(catalog))
+                using (Utf8Helper schemaHelper = new Utf8Helper(dbSchema))
+                using (Utf8Helper tableNameHelper = new Utf8Helper(tableName))
+                {
+                    bCatalog = (byte*)(IntPtr)(catalogHelper);
+                    bDb_schema = (byte*)(IntPtr)(schemaHelper);
+                    bTable_name = (byte*)(IntPtr)(tableNameHelper);
+
+                    fixed (CAdbcConnection* connection = &nativeconnection)
+                    fixed (CAdbcError* e = &_error)
+                    {
+                        
TranslateCode(Marshal.GetDelegateForFunctionPointer<CAdbcDriverExporter.ConnectionGetTableSchema>(fn)(connection,
 bCatalog, bDb_schema, bTable_name, nativeSchema, e));
+                    }
+                }
+            }
+#endif
+
+#if NET5_0_OR_GREATER
+            public unsafe void Call(delegate* unmanaged<CAdbcConnection*, 
CArrowArrayStream*, CAdbcError*, AdbcStatusCode> fn, ref CAdbcConnection 
nativeconnection, CArrowArrayStream* arrowStream)
+            {
+                fixed (CAdbcConnection* connection = &nativeconnection)
+                fixed (CAdbcError* e = &_error)
+                {
+                    TranslateCode(fn(connection, arrowStream, e));
+                }
+            }
+#else
+            public unsafe void Call(IntPtr fn, ref CAdbcConnection 
nativeconnection, CArrowArrayStream* arrowStream)
+            {
+                fixed (CAdbcConnection* connection = &nativeconnection)
+                fixed (CAdbcError* e = &_error)
+                {
+                    
TranslateCode(Marshal.GetDelegateForFunctionPointer<CAdbcDriverExporter.ConnectionGetTableTypes>(fn)(connection,
 arrowStream, e));
+                }
+            }
+#endif
+
             public unsafe void Dispose()
             {
                 if (_error.release != default)
@@ -636,7 +726,7 @@ namespace Apache.Arrow.Adbc.C
             {
                 byte* bcatalog, bDb_schema, bTable_name, bColumn_Name;
 
-                if(table_types == null)
+                if (table_types == null)
                 {
                     table_types = new List<string>();
                 }
@@ -656,34 +746,25 @@ namespace Apache.Arrow.Adbc.C
 #endif
                 }
 
-                using (Utf8Helper helper = new Utf8Helper(catalog))
-                {
-                    bcatalog = (byte*)(IntPtr)(helper);
-                }
-
-                using (Utf8Helper helper = new Utf8Helper(db_schema))
+                using (Utf8Helper catalogHelper = new Utf8Helper(catalog))
+                using (Utf8Helper schemaHelper = new Utf8Helper(db_schema))
+                using (Utf8Helper tableNameHelper = new Utf8Helper(table_name))
+                using (Utf8Helper columnNameHelper = new 
Utf8Helper(column_name))
                 {
-                    bDb_schema = (byte*)(IntPtr)(helper);
-                }
-
-                using (Utf8Helper helper = new Utf8Helper(table_name))
-                {
-                    bTable_name = (byte*)(IntPtr)(helper);
-                }
+                    bcatalog = (byte*)(IntPtr)(catalogHelper);
+                    bDb_schema = (byte*)(IntPtr)(schemaHelper);
+                    bTable_name = (byte*)(IntPtr)(tableNameHelper);
+                    bColumn_Name = (byte*)(IntPtr)(columnNameHelper);
 
-                using (Utf8Helper helper = new Utf8Helper(column_name))
-                {
-                    bColumn_Name = (byte*)(IntPtr)(helper);
-                }
-
-                fixed (CAdbcConnection* cn = &connection)
-                fixed (CAdbcError* e = &_error)
-                {
+                    fixed (CAdbcConnection* cn = &connection)
+                    fixed (CAdbcError* e = &_error)
+                    {
 #if NET5_0_OR_GREATER
-                    TranslateCode(fn(cn, depth, bcatalog, bDb_schema, 
bTable_name, bTable_type, bColumn_Name, stream, e));
+                        TranslateCode(fn(cn, depth, bcatalog, bDb_schema, 
bTable_name, bTable_type, bColumn_Name, stream, e));
 #else
-                    
TranslateCode(Marshal.GetDelegateForFunctionPointer<CAdbcDriverExporter.ConnectionGetObjects>(fn)(cn,
 depth, bcatalog, bDb_schema, bTable_name, bTable_type, bColumn_Name, stream, 
e));
+                        
TranslateCode(Marshal.GetDelegateForFunctionPointer<CAdbcDriverExporter.ConnectionGetObjects>(fn)(cn,
 depth, bcatalog, bDb_schema, bTable_name, bTable_type, bColumn_Name, stream, 
e));
 #endif
+                    }
                 }
             }
 

Reply via email to