Docsity

ODBC Tutorial: Setting up a Database Application in Smalltalk using MS Access, Assignments of Computer Science

Toggle sidebar
bg1
ODBC Tutorial – Sanjeet Hajarnis
Implementing a database application in Smalltalk can be useful especially since database can
earn you extra credit on your final grade. Moreover implementing a database eases your
application by avoiding BOSS.
This guide would help you on how to set up an ODBC. For this guide, I am considering the
following requirements
Requirements:
OS: Windows XP/Vista
Database: MS Access
Let’s walk through the setup for the database.
I: Import the ODBCEXDI[7.6] parcel from the Parcel Manager.
From the Main window, open Parcel Manager (F3). Click on Database. Locate the
ODBCEXDI[7.6], and either double click on the parcel or right click->load to load the parcel
into your current image. This parcel helps the application to connect to the database.
pf3
pf4
pf5
pf8

Partial preview of the text

Download ODBC Tutorial: Setting up a Database Application in Smalltalk using MS Access and more Assignments Computer Science in PDF only on Docsity!

ODBC Tutorial – Sanjeet Hajarnis

Implementing a database application in Smalltalk can be useful especially since database can earn you extra credit on your final grade. Moreover implementing a database eases your application by avoiding BOSS. This guide would help you on how to set up an ODBC. For this guide, I am considering the following requirements Requirements: OS: Windows XP/Vista Database: MS Access Let’s walk through the setup for the database. I: Import the ODBCEXDI[7.6] parcel from the Parcel Manager. From the Main window, open Parcel Manager (F3). Click on Database. Locate the ODBCEXDI[7.6], and either double click on the parcel or right click->load to load the parcel into your current image. This parcel helps the application to connect to the database.

Figure 1 II: Create a MS Access Database Open MS Access 2007. Select “Blank database” and enter the desired database name. Finally click on create. Change the path of the database to your desired path. For this tutorial, I would assume filename as DBTest1 and file path as C:\DatabaseTest\

Figure 2 Note: You can save the Database in either MS Access 2007 format or MS Access 2003 format. I would assume the database is saved in MS Access 2003 format. III: Include our database in systems ODBC. Go to Start->Control Panel. Click on Administrative tools followed by clicking on Data Sources (ODBC). A new window should pop up (Figure 3). Select MS Access Database and click on Add. Another window should pop up (Figure 4). Select Driver do MS Access (*.mdb) and click on Finish. Another window should pop up (Figure 5).

Figure 5 Now, click on Select and a File Browser would open. Select your database file (here DBTest1) from your saved path (here C:\ DatabaseTest) And then click on Ok. You can see your database is added to the ODBC datasources (Figure 3) Click on ok in the ODBC Data Source Administrator window. This concludes setting up of the database! IV: Test the database connection. Go to the Smalltalk main window. Click on Tools->Database->Ad Hoc SQL Figure 6 should pop up. Click on Connect. Figure 7 should pop up

Figure 6

Figure 7 For the interface field select ODBCConnection Enter your database file name in the Environment field: DBTest User Name: admin Password: admin

session := connection getSession. session prepare: 'CREATE TABLE testtable (cid int, cname varchar(50))'; execute; answer; answer. session prepare: 'INSERT INTO testtable VALUES(:1, :2)'. #( (1 'Curly' ) (2 'Moe') (3 'Larry') ) do: [ :item | session bindInput: item; execute; answer; answer]. session prepare: 'SELECT * FROM testtable'; execute. answer := session answer. result := OrderedCollection new add: answer upToEnd. session answer. session prepare: 'DROP TABLE testtable'; execute; answer; answer.

result inspect. connection disconnect.

  1. While doing multithreading make sure that you manage your sessions properly or else you would run into multi-session ODBC errors.
  2. Output to a query is in the following format #(#(1 Name1) #(2 Name2)). This format resembles the input that a graph requires. So, it is really easy to generate graph data by querying the database.
  3. In the above insert query, it takes in static information but to make it dynamic you could do something like this: | data d2 | data := Array new:2. data at: 1 put: 5. data at: 2 put: ‘Name’. d2 := Array new:1.

d2 at:1 put: data. Here d2 would be #(#(5 ‘Name’)) which is the same format that an insert statement wants. You could extract information like 5/Name from instances of your Objects. Note: Arrays are indexed at 1 in Smalltalk. I hope this tutorial proved helpful and you would be able to implement an amazing database application in Smalltalk! Good Luck!