. .

st4u

ST 4U 142: Using SQL in VA Smalltalk

October 7, 2011 12:00:33.950

Today's Smalltalk 4 You looks at using VA Smalltalk to interact with a relational database. Today, we add a new table from Smalltalk - to see how to connect, please go back to this tutorial. 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:

Adding a Table.

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 creating a table in VA Smalltalk - to see how to connect, please go back to this tutorial, as we are building on it here.

Once you have a connection to your database set up (with a user who has permissions to make changes), set up your SQL to create a table:

"connects with the alias"
connection := conSpec connectUsingAlias: 'winlocalSpec'.


"define sql"
sqlDef := '(NAME varchar(30) NOT NULL,',
' STREET varchar(20) null,',
' CITY varchar(20) null,',
' STATE varchar(2) null,',
' ZIPCODE int null,',
' PHONE varchar(13) null)'.

This sets up the SQL to create a simple table. Now we need to tell the connection to send it to the database:


"create a table"
table := connection createTableNamed: 'PEOPLE' definition: sqlDef.

At this point, you aren't quite done. Since this is a database change rather than just a query, we need to commit the change:


"commit it"
connection commitUnitOfWork

Finally, after working with your database, make sure you close the connection:


"disconnect"
connection disconnect.

We'll look at querying and binding query results in a future tutorial.

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:
[st4u142-iPhone.m4v ( Size: 4475151 )]

 Share Tweet This