You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "lidavidm (via GitHub)" <gi...@apache.org> on 2023/07/28 14:14:38 UTC

[GitHub] [arrow-adbc] lidavidm commented on a diff in pull request #945: fix(csharp): include GetInfo and GetObjects call for .NET 4.7.2

lidavidm commented on code in PR #945:
URL: https://github.com/apache/arrow-adbc/pull/945#discussion_r1277596523


##########
csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverImporter.cs:
##########
@@ -567,6 +601,83 @@ public unsafe void Dispose()
                 }
             }
 
+#if NET5_0_OR_GREATER
+            public unsafe void Call(delegate* unmanaged<CAdbcConnection*, byte*, int, CArrowArrayStream*, CAdbcError*, AdbcStatusCode> fn, ref CAdbcConnection connection, List<int> infoCodes, CArrowArrayStream* stream)
+#else
+            public unsafe void Call(IntPtr ptr, ref CAdbcConnection connection, List<int> infoCodes, CArrowArrayStream* stream)
+#endif
+            {
+                int numInts = infoCodes.Count;
+
+                // Calculate the total number of bytes needed
+                int totalBytes = numInts * sizeof(int);
+
+                IntPtr bytePtr = Marshal.AllocHGlobal(totalBytes);
+
+                int[] intArray = infoCodes.ToArray();
+                Marshal.Copy(intArray, 0, bytePtr, numInts);
+
+                fixed (CAdbcConnection* cn = &connection)
+                fixed (CAdbcError* e = &_error)
+                {
+#if NET5_0_OR_GREATER
+                    TranslateCode(fn(cn, (byte*)bytePtr, infoCodes.Count, stream, e));
+#else
+                    TranslateCode(Marshal.GetDelegateForFunctionPointer<CAdbcDriverExporter.ConnectionGetInfo>(ptr)(cn, (byte*)bytePtr, infoCodes.Count, stream, e));
+#endif
+                }
+            }
+
+#if NET5_0_OR_GREATER
+            public unsafe void Call(delegate* unmanaged<CAdbcConnection*, int, byte*, byte*, byte*, byte**, byte*, CArrowArrayStream*, CAdbcError*, AdbcStatusCode> fn, ref CAdbcConnection connection, int depth, string catalog, string db_schema, string table_name, List<string> table_types, string column_name, CArrowArrayStream* stream)
+#else
+            public unsafe void Call(IntPtr fn, ref CAdbcConnection connection, int depth, string catalog, string db_schema, string table_name, List<string> table_types, string column_name, CArrowArrayStream* stream)
+#endif
+            {
+                byte* bcatalog, bDb_schema, bTable_name, bColumn_Name;
+                byte** bTable_type = (byte**)Marshal.AllocHGlobal(IntPtr.Size * table_types.Count);
+
+                for (int i = 0; i < table_types.Count; i++)
+                {
+                    string tableType = table_types[i];
+#if NETSTANDARD
+                    bTable_type[i] = (byte*)MarshalExtensions.StringToCoTaskMemUTF8(tableType);
+#else
+                    bTable_type[i] = (byte*)Marshal.StringToCoTaskMemUTF8(tableType);
+#endif
+                }

Review Comment:
   The list is expected to be terminated with a null entry: https://github.com/apache/arrow-adbc/blob/b97e22c4d6524b60bf261e1970155500645be510/adbc.h#L909-L911



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org