From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:49:46 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>DatabaseWorkbook</name> <environment>Smalltalk</environment> <super>Tools.Workbook</super> <private>false</private> none session connection profile <imports></imports> <category>DatabaseExamplesUI</category> <attributes> <package>Database-Examples</package> </attributes> </class> <comment> DatabaseWorkbook
DatabaseWorkbook is a clone of Alan Knight's Glorp Workbook examples, and illustrates EXDI layer database usage. Instance Variables: connection <ExternalDatabaseConnection> EXDI connection to a database. profile <ConnectionProfile> Holds the username/password/environment/database vendor information. session <ExternalDatabaseSession> EXDI session for the connection.
</comment> <class> <name>BindTest</name> <environment>Database</environment> <super>Core.Object</super> <private>false</private> none cid cname <imports></imports> <category>Database-Examples</category> <attributes> <package>Database-Examples</package> </attributes> </class> <comment> Database.BindTest
BindTest is an example class, to illustrate use of the VisualWorks EXDI. For details, see the Database Developer's Guide, located in the /doc subdirectory of the VisualWorks distribution. Instance Variables: cid <Integer> ID for this instance cname <String> Name of this instance
</comment> <class> <name>PhoneListEntry</name> <environment>Database</environment> <super>Core.Object</super> <private>false</private> none name phone <imports></imports> <category>Database-Examples</category> <attributes> <package>Database-Examples</package> </attributes> </class> <comment> Database.PhoneListEntry
PhoneListEntry is an example class, to illustrate use of the VisualWorks EXDI. For details, see the Database Developer's Guide, located in the /doc subdirectory of the VisualWorks distribution. Instance Variables: name <String> Name of person who owns this phone number phone <PhoneNumber> Phone number
</comment> <methods> DatabaseWorkbook <category>accessing</category>
environment ^profile environment
password ^profile password
username ^profile username
</methods> <methods> DatabaseWorkbook <category>private</category>
noticeOfWindowClose: aWindow self logout
postOpenWith: aBuilder super postOpenWith: aBuilder. connection ifNotNil: [self login]
preBuildWith: aBuilder super preBuildWith: aBuilder. self replaceAllTextPagesWith: self class examplesPage.
tracingCollector "Return the stream object which will recieve the database tracing (logging)." ^Transcript
tracingLevel "Return a number from 1 to 5, where 5 provides the most detailed trace level." ^5
</methods> <methods> DatabaseWorkbook <category>actions</category>
logging: aBoolean aBoolean ifTrue: [session traceLevel: self tracingLevel] ifFalse: [session traceLevel: 0]
login [connection isConnected ifFalse: [connection connect]] on: ConnectionException do: [:ex | ex return: nil]. builder window label: (self class workbookLabel , ' (<1s> - <2s>/<3s>)' expandMacrosWith: connection username with: connection class kind asString with: connection environment)
logout connection disconnect. builder window label: (self class workbookLabel, ' (<1s> - not connected)' expandMacrosWith: connection username)
</methods> <methods> DatabaseWorkbook <category>aspects</category>
isLoggedIn ^connection ifNil: [false] ifNotNil: [connection isConnected]
isLogging ^session traceLevel > 0
isNotLoggedIn ^self isLoggedIn not
</methods> <methods> DatabaseWorkbook <category>initialize-release</category>
initialize super initialize. ExternalDatabaseConnection traceCollector ifNil: [ExternalDatabaseConnection traceCollector: self tracingCollector]
on: aConnectionProfile profile := aConnectionProfile. connection := Database.ConnectionDialog connect: profile. connection ifNil: [session := nil] ifNotNil: [connection password: profile password. session := connection getSession]. self addLocal: #connection value: connection. self addLocal: #session value: session
</methods> <methods> DatabaseWorkbook class <category>examples</category>
exampleHeader ^'"The examples below illustrate how to use the database EXDI. You can evaluate them with Do it or modify them as you like."'.
examplesOneByOne "Return a list of alternating comments and examples for the workspace. Do this so we can automatically emphasize the text to make them stand out." ^#('"Show status of the connection"' 'connection isConnected.' '"Establish a connection with the database"' 'connection isConnected ifFalse: [connection connect].' '"Show the database environment string"' 'connection environment.' '"Disconnect from the database"' 'connection disconnect.' '"Create a table for use as an address book"' 'session prepare: ''CREATE TABLE contacts (fullname VARCHAR(25), address VARCHAR(25), city VARCHAR(25), state VARCHAR(2), zip VARCHAR(10), phone VARCHAR(14), cell VARCHAR(14), email VARCHAR(25), notes VARCHAR(254))''. session execute. [(ans := session answer) = #noMoreAnswers] whileFalse: [(ans = #noAnswerStream) ifFalse: [strm := ans upToEnd]].' '"Populate the address book"' 'data := #( #(''Alice Jones'' ''25 Maple Street'' ''Brattleborough'' ''VT'' ''01234'' ''012 345 6789'' '''' ''ajones@www.com'' '''') #(''Jim Smith'' ''12 Geary St'' ''San Francisco'' ''CA'' ''94123'' ''567 890 1234'' '''' ''jsmith@www.com'' '''') ). session prepare: ''INSERT INTO contacts VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''. data do: [:contact| session bindInput: contact. session execute. [(ans := session answer) = #noMoreAnswers] whileFalse: [(ans = #noAnswerStream) ifFalse: [strm := ans upToEnd]] ].' '"Count the number of records in the address book"' 'session prepare: ''SELECT COUNT(*) FROM contacts''. session execute. [(ans := session answer) = #noMoreAnswers] whileFalse: [(ans = #noAnswerStream) ifFalse: [strm := ans upToEnd]]. strm first inspect' '"Drop the table used by the address book"' 'session prepare: ''DROP TABLE contacts''. session execute. [(ans := session answer) = #noMoreAnswers] whileFalse: [(ans = #noAnswerStream) ifFalse: [strm := ans upToEnd]].' '"Disconnect from the database"' 'connection disconnect.' ).
examplesPage ^WorkspacePage labeled: self workbookLabel on: (WorkspacePage cautiousAdaptorOn: self examplesText asValue).
examplesText | text examples | text := TextStream on: String new. text nextPutAllText: self exampleHeader asText allBold. text cr; cr. examples := self examplesOneByOne. 1 to: examples size by: 2 do: [:i | text nextPutAllText: (examples at: i) asText allBold. text cr. text nextPutAllText: (examples at: i + 1). text cr; cr]. ^text contents.
workbookLabel ^'Database Examples'.
</methods> <methods> DatabaseWorkbook class <category>instance creation</category>
on: aConnectionProfile ^self new on: aConnectionProfile
openRequestingDatabase | login workbook | login := self requestDatabase. login ifNotNil: [workbook := self on: login. workbook isLoggedIn ifTrue: [workbook open]]
requestDatabase | login defaultProfile | defaultProfile := nil "Database.ConnectionProfile new". login := Database.ConnectionDialog chooseProfileInitially: defaultProfile. ^login
</methods> <methods> Database.BindTest <category>accessing</category>
cid "Answer the receiver's id" ^cid
cid: anInteger cid := anInteger
cname "Answer the receiver's name" ^cname
cname: aString cname := aString
</methods> <methods> Database.BindTest class <category>instance creation</category>
cid: anInteger cname: aString | anInstance | anInstance := self new. anInstance cid: anInteger. anInstance cname: aString. ^anInstance
</methods> <methods> Database.PhoneListEntry <category>accessing</category>
name "Answer the receiver's name" ^name
name: aString "Set the receiver's name" name := aString
phone "Answer the receiver's phone number" ^phone
phone: aPhoneNumber "Set the receiver's phone number" phone := aPhoneNumber
</methods> <methods> Database.PhoneListEntry class <category>instance creation</category>
name: aString phone: aPhoneNumber | anInstance | anInstance := self new. anInstance name: aString. anInstance phone: aPhoneNumber. ^anInstance
</methods> <methods> DatabaseWorkbook <category>menus</category>
databaseSubmenu <submenu: #(#Database #menus 'Database') nameKey: #databaseMenu menu: #(#menuBar) position: 10.03>
menuLogin <menuItem: '&Connect' nameKey: #databaseLoginSelect enablement: #isNotLoggedIn indication: nil menu: #(menuBar databaseMenu) position: 30.40> self isLoggedIn ifFalse: [ self login ].
menuLogout <menuItem: '&Disconnect' nameKey: #databaseLogoutSelect enablement: #isLoggedIn indication: nil menu: #(menuBar databaseMenu) position: 30.40> self isLoggedIn ifTrue: [ self logout ].
toggleLogging <menuItem: 'Log SQL' nameKey: #sqlLoggingToggle enablement: nil indication: #isLogging menu: #(#menuBar #databaseMenu) position: 30.5> self logging: self isLogging not. ^self.
</methods> <methods> Tools.VisualLauncher <category>db examples menus</category>
openDatabaseWorkbook <menuItem: 'Database Examples Workbook' icon: nil nameKey: nil menu: #(#menuBar #tools #database) position: 21.5> DatabaseWorkbook openRequestingDatabase.
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>Object</name> <environment>Core</environment> <super></super> <private>false</private> none <imports></imports> <category>Kernel-Objects</category> <attributes> <package>Kernel-Objects</package> </attributes> </class> <class> <name>VisualLauncher</name> <environment>Tools</environment> <super>UI.ApplicationModel</super> <private>false</private> none menuBar toolBar textCollector toolDock <imports></imports> <category>Tools-Misc</category> <attributes> <package>Tools-Misc</package> </attributes> </class> <class> <name>Workbook</name> <environment>Tools</environment> <super>Tools.AbstractWorkspace</super> <private>false</private> none pageHolder lastInstalledPage <imports></imports> <category>Tools-Workspace</category> <attributes> <package>Tools-Workspace</package> </attributes> </class>