Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
MySQL
Last updated at 2:25 pm UTC on 16 January 2006
Also see the Databases and Persistence page and the Persistence section of the All Projects page for more info on database projects with Squeak.

As of 1/2005 the current version of this driver for Squeak is available on SqueakMap.
It is a Squeak port of Josh Miller's VisualWorks driver for MySQL. The license for his driver is GPL. The home page for his driver is http://jdmsoft.com/MysqlDriver.html

I've added this page in the hope that some folk may find it useful in getting Squeak connected to MySQL. I've got Squeak talking to MySQL: here's what I needed to do (my machine is a Win2000 laptop, and I'm running Squeak 3.1alpha #4173):

I then could use a modified form of Bolot's example (having setup a user 'squeak' with select privs on the mysql database):

| connection spec statement resultSet value |
Socket initializeNetwork.
spec :=    (JdmConnectionSpec new initialize
        user: 'squeak'; password: 'squeak';
        host: (NetNameResolver addressForName: 'your.computer.name');
        database: 'mysql';
        port: 3306).

connection := JdmConnection on: spec.
statement := connection createStatement.
resultSet := statement executeQuery: 'select * from db'.
	
"print column names"
Transcript cr; show: (resultSet columns collect: [:col | col name]) asString.

[resultSet next]
whileTrue:
[
	value := resultSet valueNamed: 'Db'. "get column named Db"
	Transcript cr; show: value printString.
].

connection close.

And I get a printout on the transcript of the values in the "Db" column. The retrieval is case sensitive...so "db" and "Db" are different. This example has no error handling.

Further details: Anyone?

Chris Wright (caw@cs.mu.oz.au)


Gerald Zincke (2002/04/28):

Also thanks from me to Bolot and to the provider of the sample ! Maybe some of you will find it helpful to change the parameters for this example a bit. If you install MySQL on your local system you will find scripts to create the demo-database "Menagerie" (See the "README" file in the directory mysql\examples\menagerie ). If you want to retrieve data from column "name" in table "pet" in the test-database "menagerie" you have to use the sample as follows (Rest in MySQL is installed all with defaults; tested with Squeak 3.1 ; mysql Ver 11.15 Distrib 3.23.47, for Win95/Win98 (i32)):


| connection spec statement resultSet value |
Socket initializeNetwork.
Transcript open.
spec :=    (JdmConnectionSpec new initialize
        user: ''; password: '';
        host: (NetNameResolver addressForName: 'localhost');
        database: 'menagerie';
        port: 3306).


connection := JdmConnection on: spec.
statement := connection createStatement.
resultSet := statement executeQuery: 'select * from pet'.
	
"print column names"
Transcript cr; show: (resultSet columns collect: [:col | col name]) asString.

[resultSet next]
whileTrue:
[
	value := resultSet valueNamed: 'name'. "get column named name"
	Transcript cr; show: value printString.
].

connection close.


And by the way: The result is:

#('name' 'owner' 'species' 'sex' 'birth' 'death')
'Fluffy'
'Claws'
'Buffy'
'Fang'
'Bowser'
'Chirpy'
'Whistler'
'Slim'
'Puffball'



BLOB field is NULL


I ran into an error when loading BLOB columns whose content was NULL.
I edited the corresponding converter method: JdmFieldConverter-toByteArraycolumn2.st




minor (?) problem in 3.6

Evidently 3.6 marked a bit of a change in network support. For one thing, the SimpleClientSocket class has gone away - causing some confusion to JdmConnection. As far as I can tell, the new Socket fits the bill. One further change was needed to use waitForConnectionFor: instead of waitForConnectionUntil:

JdmConnection>>initializeConnection
	| a |
	packetClass _ JdmInputPacket.
     a _ self class protocolHashes.
	(hashesByProtocol _ Dictionary new)
		at: (a at: 1) put: (a at: 2);
		at: (a at: 3) put: (a at: 4).

	socket _ Socket new
		connectTo: (connectionSpec host)
		port: (connectionSpec port).
	socket waitForConnectionFor: Socket standardDeadline.

	readStream _ writeStream _ SocketStream on: socket.

	serverInfo _ JdmServerInfo on: self.
	serverInfo serverVersion >= self class largeSizesVersion
		ifTrue: [packetClass _ JdmLargeSizeInputPacket].

	clientCapabilities _ serverInfo protocol = 10 ifTrue: [1] ifFalse: [0]


Aran Lunzer


The client protocol changed from version 4 to 5 of MySql. Fortunately there is a backward compatibility password encryption that can be used, cf. http://dev.mysql.com/doc/refman/5.0/en/old-client.html. Just assign passwords using the 'old_password' function and the current Squeak client will continue to work.

M Buchanan