For an exercise with uFFi i am try an C-Connector for MariaDB like
Garage or UBDC As in "Unified FFI Februar 12 2020" I made Helper-classes: FFILibrary subclass: #MariaDBLibC FFIOpaqueObject subclass: #MariaDBHandle MariaDBHandle >> unixModuleName [ ^ '/usr/lib/x86_64-linux-gnu/libmariadb.so' ] and a class Object subclass: #MariaDBDriver instanceVariableNames: 'connectionHandle' "Accessors" MariaDBDriver >> connectionHandle [ ^ connectionHandle ] MariaDBDriver >> connectionHandle: aHandle [ connectionHandle := aHandle ] MariaDBDriver class >> ffiLibrary [ ^ MariaDBLibC ] "API Methods" MariaDBDriver >> clientInfo [ ^ self class clientInfo ] MariaDBDriver class >> clientInfo [ ^ self ffiCall: #(String mysql_get_client_info(void)) ] For a first simple Test I choosed the c-api-funtion: „const char * mysql_get_client_info(void )“ In Playground I executed: driver := MariaDBDriver fromConnectionString: 'mariaDB://localhost:5432/sodbxtest?&user=sodbxtest&password=sodbxtest'. driver clientInfo inspect. And I get the expected result: String „10.2.9“ But the second test with c-api-funtcion fails „MYSQL * mysql_init(NULL)“ MariaDBDriver >> init [ | aNullHandle | aNullHandle := ExternalAddress null. self connectionHandle: (self class init: aNullHandle). ] MariaDBDriver class >> init: aNullHandle [ ^ self ffiCall: #(MariaDBHandle * mysql_init(ExternalAddress aNullHandle)). ] In Playground I again executed: driver := MariaDBDriver fromConnectionString: 'mariaDB://localhost:5432/sodbxtest?&user=sodbxtest&password=sodbxtest'. driver init inspect. " A call to an external function failed" Any ideas what is wrong?? Thanks Georg |
Hello Georg
This is a great news. since we need more binding. I do not really know the answer but I’m sure the guys will help you. Now just a question: what is the definition of MYSQL that you mentioned in „MYSQL * mysql_init(NULL)“ S.
-------------------------------------------- Stéphane Ducasse 03 59 35 87 52 Assistant: Aurore Dalle FAX 03 59 57 78 50 TEL 03 59 35 86 16 S. Ducasse - Inria 40, avenue Halley, Parc Scientifique de la Haute Borne, Bât.A, Park Plaza Villeneuve d'Ascq 59650 France |
Hello Stephane,
Definition from: https://mariadb.com/kb/en/mariadb-connectorc-data-structures : "The MYSQL structure represents one database connection and is used by most of MariaDB Connector/C's API functions. The MYSQL structure needs to be allocated and initialized by the mysql_init() API function. It will be released by the mysql_close() function. The MYSQL structure should be considered as opaque." I try with MariaDB, because there is a valid mysql binding. I can test my UFFi Connector agains MySQL. BTW, I use Pharo 8.0 Georg Hagn Am So., 21. Juni 2020 um 16:12 Uhr schrieb Stéphane Ducasse <[hidden email]>: > > Hello Georg > > This is a great news. since we need more binding. > I do not really know the answer but I’m sure the guys will help you. > Now just a question: what is the definition of MYSQL > that you mentioned in > „MYSQL * mysql_init(NULL)“ > > > S. > > On 21 Jun 2020, at 11:27, Georg Hagn <[hidden email]> wrote: > > For an exercise with uFFi i am try an C-Connector for MariaDB like > Garage or UBDC > As in "Unified FFI Februar 12 2020" I made Helper-classes: > > FFILibrary subclass: #MariaDBLibC > > FFIOpaqueObject subclass: #MariaDBHandle > MariaDBHandle >> unixModuleName [ > ^ '/usr/lib/x86_64-linux-gnu/libmariadb.so' > ] > > and a class > > Object subclass: #MariaDBDriver > instanceVariableNames: 'connectionHandle' > > "Accessors" > MariaDBDriver >> connectionHandle [ ^ connectionHandle ] > MariaDBDriver >> connectionHandle: aHandle [ connectionHandle := aHandle ] > MariaDBDriver class >> ffiLibrary [ ^ MariaDBLibC ] > > "API Methods" > MariaDBDriver >> clientInfo [ ^ self class clientInfo ] > > MariaDBDriver class >> clientInfo [ > ^ self ffiCall: #(String mysql_get_client_info(void)) > ] > > For a first simple Test I choosed the c-api-funtion: > „const char * mysql_get_client_info(void )“ > > In Playground I executed: > driver := MariaDBDriver fromConnectionString: > 'mariaDB://localhost:5432/sodbxtest?&user=sodbxtest&password=sodbxtest'. > > driver clientInfo inspect. > And I get the expected result: String „10.2.9“ > > But the second test with c-api-funtcion fails > „MYSQL * mysql_init(NULL)“ > > MariaDBDriver >> init [ > | aNullHandle | > aNullHandle := ExternalAddress null. > self connectionHandle: (self class init: aNullHandle). > ] > > MariaDBDriver class >> init: aNullHandle [ > ^ self ffiCall: #(MariaDBHandle * mysql_init(ExternalAddress aNullHandle)). > ] > > In Playground I again executed: > driver := MariaDBDriver fromConnectionString: > 'mariaDB://localhost:5432/sodbxtest?&user=sodbxtest&password=sodbxtest'. > > driver init inspect. > " A call to an external function failed" > > Any ideas what is wrong?? > > Thanks > Georg > > > -------------------------------------------- > Stéphane Ducasse > http://stephane.ducasse.free.fr / http://www.pharo.org > 03 59 35 87 52 > Assistant: Aurore Dalle > FAX 03 59 57 78 50 > TEL 03 59 35 86 16 > S. Ducasse - Inria > 40, avenue Halley, > Parc Scientifique de la Haute Borne, Bât.A, Park Plaza > Villeneuve d'Ascq 59650 > France > |
In reply to this post by Georg Hagn
On Sun, Jun 21, 2020 at 11:27:22AM +0200, Georg Hagn wrote:
> 'mariaDB://localhost:5432/sodbxtest?&user=sodbxtest&password=sodbxtest'. Hi, Firstly, 5432 is PostgreSQL. MySQL/MariaDB default port is 3306. Just a note, as mysql_init() only allocates the C level structure and doesn't connect. > FFILibrary subclass: #MariaDBLibC > > FFIOpaqueObject subclass: #MariaDBHandle > MariaDBHandle >> unixModuleName [ > ^ '/usr/lib/x86_64-linux-gnu/libmariadb.so' > ] With your code, implementing #unixModuleName in MariaDBLibC works for me. I've never done that in FFIOpaqueObject subclasses. In terms of organizing code, suggest you implement the FFI calls in MariaDBLibC itself and do away with MariaDBDriver. Having the FFI calls in MariaDBDriver while using MariaDBLibC only for locating the C libraries is using two classes where one will do. Finally, there is a non FFI pure Smalltalk implementation of the MySQL wire protocol that has been around a while. If you are doing this FFI thing for practice, I recommend that you wrap another C library, so that when you are done, Pharo gets another C library binding. https://github.com/pharo-rdbms/Pharo-MySQL Pierce |
> On 22 Jun 2020, at 03:47, Pierce Ng <[hidden email]> wrote: > > Finally, there is a non FFI pure Smalltalk implementation of the MySQL > wire protocol that has been around a while. > https://github.com/pharo-rdbms/Pharo-MySQL Hmm, that is interesting, I somehow missed that. A little bit more documentation, like a description in the README file would be great though. Sven |
On Mon, Jun 22, 2020 at 08:41:22AM +0200, Sven Van Caekenberghe wrote:
> > On 22 Jun 2020, at 03:47, Pierce Ng <[hidden email]> wrote: > > Finally, there is a non FFI pure Smalltalk implementation of the MySQL > > wire protocol that has been around a while. > > > https://github.com/pharo-rdbms/Pharo-MySQL > > Hmm, that is interesting, I somehow missed that. > A little bit more documentation, like a description in the README file would be great though. Agree. Your docu for P3 is the standard to aim for. Quick bit of history: This driver is the one from Squeaksource that was then incorporated into DBXTalk and Garage, and finally moved to the GH repo mentioned above. http://www.squeaksource.com/StdbMysqlProtocol.html Pierce |
Hi Pierce,
> On 23 Jun 2020, at 11:51, Pierce Ng <[hidden email]> wrote: > > On Mon, Jun 22, 2020 at 08:41:22AM +0200, Sven Van Caekenberghe wrote: >>> On 22 Jun 2020, at 03:47, Pierce Ng <[hidden email]> wrote: >>> Finally, there is a non FFI pure Smalltalk implementation of the MySQL >>> wire protocol that has been around a while. >> >>> https://github.com/pharo-rdbms/Pharo-MySQL >> >> Hmm, that is interesting, I somehow missed that. >> A little bit more documentation, like a description in the README file would be great though. > > Agree. Your docu for P3 is the standard to aim for. Thanks, but I still do not consider P3 completely documented, though as far as a README in GitHub goes it is quite good. > Quick bit of history: This driver is the one from Squeaksource that was > then incorporated into DBXTalk and Garage, and finally moved to the GH > repo mentioned above. > > http://www.squeaksource.com/StdbMysqlProtocol.html Ah, OK. Then the origins and original authors should definitively be acknowledged. > Pierce Regards, Sven |
Free forum by Nabble | Edit this page |