halildurmus / win32

Access common Win32 APIs directly from Dart using FFI — no C required!
https://win32.pub
BSD 3-Clause "New" or "Revised" License
759 stars 123 forks source link

Any chance to implement ADODB #185

Closed efreibe closed 1 week ago

efreibe commented 3 years ago

I'm wondering if it's too hard to implement ADODB (Connection, Command and Recordset at least), I've tried, but I can't figure out how to implement those interfaces completely.

I have some questions, for example, the typelib has definitions like object, that I do not how to convert to dart (I found over there that should be a Long value?). And I've not found how to implement enum types.

Moreover I do not know how to calculate the vtable indexes of methods and properties.

Here is an example of _Connection Interface that I've tried to implement, I do not know if the tool I've used reorders methods and properties, this makes more confusing to calculate vtable indexes.

There is another way to tackle this? For example, using IDispatch/Invoke like old Visual Basic does?

Any help would be appreciated. Thank you.

[Guid("00000550-0000-0010-8000-00aa006d2ea4")]
interface _Connection
{
   /* Methods */
   void Close();
   Recordset Execute(string CommandText, [Out,Optional] Object& RecordsAffected, [Optional] int Options);
   int BeginTrans();
   void CommitTrans();
   void RollbackTrans();
   void Open([Optional] string ConnectionString, [Optional] string UserID, [Optional] string Password, [Optional] int Options);
   Recordset OpenSchema(SchemaEnum Schema, [Optional] object Restrictions, [Optional] object SchemaID);
   void Cancel();
   /* Properties */
   Properties Properties { get; }
   string ConnectionString { get; set; }
   int CommandTimeout { get; set; }
   int ConnectionTimeout { get; set; }
   string Version { get; }
   Errors Errors { get; }
   string DefaultDatabase { get; set; }
   IsolationLevelEnum IsolationLevel { get; set; }
   int Attributes { get; set; }
   CursorLocationEnum CursorLocation { get; set; }
   ConnectModeEnum Mode { get; set; }
   string Provider { get; set; }
   int State { get; }
}
timsneath commented 3 years ago

I'd love to understand the scenario better -- what are you building where ADO on the client is the right choice?

While it's theoretically possible, I think you might be better off with something like this: https://pub.dev/packages/dart_mssql

efreibe commented 3 years ago

I need to support another server than mssql. Here is the link:

http://devzone.advantagedatabase.com/dz/content.aspx?key=20&Release=19

I'm thinking that adodb is the best option I have in this situation. Besides adodb can handle a variety of additional data stores like excel.

Do you see a better option here? There are other libraries in that page, I think that addressing the native library would be a mess.

timsneath commented 3 years ago

Oh my! Yeah, that's quite a challenge. If I were building this today, I would probably create a native component in a more COM-friendly that does the heavy lifting work of getting data out of ADODB, and then expose that to Dart through a simpler interface.

What you're describing is theoretically possible with Dart, but you're pioneering into new territory. While I have IDispatch wired up, I've not been able to successfully invoke a method using it. Unclear yet whether it's bad pointer management on my side or whether there's something more fundamentally broken.

If you're comfortable to be a pioneer, you can check the experimentation I've done so far here: https://github.com/timsneath/win32/blob/dotnet/example/dotnet/invoke.dart

efreibe commented 3 years ago

I will take a look and see what can I do... thank you

efreibe commented 3 years ago

@timsneath I've taken a look to the code you left in the past comment, I've made some arrangements and came up with the code below. Hope helps to complete the invoke example:

testinvoke.zip

I've added some free functions to avoid leaks, but being a short example maybe could be better to remove them.

I will continue investigating how to port ADODB. Thank you.

timsneath commented 3 years ago

This is fantastic! Thank you. You've fixed my pointer bug and this works nicely now.

I'll tidy up the sample and try and use it to do something slightly more sophisticated, but this gets us a big step closer to something like ADODB. Thank you.

efreibe commented 3 years ago

You're welcome, let me know if you need any further help.