Fandom

Scratchpad

GNU Smalltalk MySQL-Driver

216,084pages on
this wiki
Add New Page
Discuss this page0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

MySQL-Driver Status: integrated into 2.0b!

Another useful thing (with a different scope than the gdbm-driver) would be a MySQL-driver. Here is a smalltalk MySQL-driver available at: http://jdmsoft.com/MysqlDriver.html. It is reengineered from the c-source of the native MySQL-client lib, so it has no need for bindings.

I tried to work with the squeak version of the driver, but I needed too much code from squeak, so I decided to start from the original driver by Josh Miller. Here they are:

Mysql-Driver.st (VisualWorks 3.0 Version)

Mysql-Driver-Tests.st (VisualWorks 3.0 Version)

Testing-Framework.st (VisualWorks 3.0 Version)

Here is my first working version. Unpack it, then adjust the parameters in mysql-test.st. Then run it with

gst -Q mysql-test.st


JdmMySQL-driver-GST.tar.gz

The hardest translation was done in JdmWriteStream (look below). The rest was relatively simple (Adjusting socket-methods, conversion from ByteStream to Integer, etc). An impressive example for smalltalk's power!

!JdmWriteStream methodsFor: 'accessing'!

setWritePosition: aPosition

"original code"

position _ (aPosition > writeLimit

ifTrue: [writeLimit]

ifFalse: [aPosition])! !"


"here's the trick involved:"

ptr := aPosition + 1! !



Here is a simple testscript:

| value resultSet statement spec connection |

FileStream fileIn: 'DB.st'.

FileStream fileIn: 'MySQL.st'.

spec := (Jdm JdmConnectionSpec new initialize

user: 'root'; password: ;

host: 'localhost';

database: 'mysql';

port: 3306).

connection := Jdm MySQL JdmConnection on: spec.

JdmStatement initialize.

statement := connection createStatement.

resultSet := (statement executeQuery: 'select * from db') value.

Transcript cr; show: (resultSet columns collect: [:col | col name]) printString

[resultSet next]

whileTrue:

[

value := resultSet valueNamed: 'Db'. "get column named Db"

Transcript cr; show: value printString.

].

Transcript cr.

connection close.

ObjectMemory quit!


The hierarchy has been refactored with respect to the original driver by Josh. His initials now are the acronym for `Just a Database Manager', so the DBMS-independent classes have been moved to the `Jdm' namespace, while the MySQL driver proper resides in `Jdm MySQL'.

Markus Fritsche and Paolo Bonzini

Also on Fandom

Random wikia