. .

st4u

ST 4U 149: Parameterized Statements in VA Smalltalk

October 24, 2011 10:04:59.523

Today's Smalltalk 4 You looks at parameterized queries against a database using VA Smalltalk. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Parameterized Access.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll look at parameterized queries against a relational database using VA Smalltalk - to see how to connect, please go back to this tutorial, as we are building on it here. As you probably expect, you'll need to set up a connection, and then a mapping dictionary:


"Example - insertFromScript - parameter markers"
queryStatement := 'INSERT INTO PEOPLE (NAME, STREET,CITY,STATE,ZIPCODE,PHONE) VALUES (:PNAME, :PSTREET,:PCITY,:PSTATE,:PZIPCODE,:PPHONE)'.
qSpec := AbtQuerySpec new
statement: queryStatement;
yourself.
dict := Dictionary new.
dict
	at: 'PNAME'  put: 'Fred Flintstone';
	at: 'PSTREET'  put: 'Paleozoic Way';
	at: 'PCITY'  put: 'Rubble City';
	at: 'PSTATE'  put: 'AN';
	at: 'PZIPCODE' put: 23456;
	at: 'PPHONE' put: '890-123-4567'.


If you think about that for a moment, it will become clear how easy it would be to set up a "mini framework" that maps simple objects to database tables; we have one that follows this pattern (using VisualWorks, but it's the same idea) where I work. Make sure you commit the statement:


"commit it"
connection commitUnitOfWork.

Next, look at the two screen captures - we have a query before the code above ran, and then another one after it:

Table before

Table after

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u149-iPhone.m4v ( Size: 4230679 )]

 Share Tweet This