Database access
Our next objective was to introduce database interaction. We decided to have the following classes for it.
| Tabular | To show multiple records in a grid |
| FreeForm | To show one record with multiple fields |
| DataStore | To interact with database |
In addition two classes were used internally.
- RecordSet - to hold a retrieved record
- Column - to hold information about columns in a tabular and rows in freeform
- A HTTP XML request can be send from the send from a client action, attached to a tabular column, which will invoke a server side function written in the page.
- The server side function can create a class, like FreeForm, and sends it to the client
- The FreeForm is repainted in the client
We created a database of all people attending the BarCamp at Chennai to get the page working.
The code looks like this:
module PageTabular
def showFreeform(pNameClicked)
datastore = DataStore.new("tsgpdc2k", "ubuildmya", "sets")
datastore.databasename = "SessionDB"
freeform = Freeform.new
freeform.name = "DynamicDisplay"
style = Style.new
style[:font_size] = 12
style[:color] = "blue"
liveNewsText = Text.new("")
liveNewsText.style = style
newsDetail = Text.new("")
newsDetail.style = style
presentation = Text.new("")
presentation.style = style
freeform.add("Name", "Attendee Name", liveNewsText)
freeform.add("Details", "Attendee Details", newsDetail)
freeform.add("Presentation", "Presentation Given", presentation)
datastore.sql = "select * from Attendees where name= ?"
datastore.setParameter(1, pNameClicked)
freeform.columns = datastore.select
return freeform
end
def pageText
page = Page.new(:PageTabular)
datastore = DataStore.new("tsgpdc2k","ubuildmya","sets")
datastore.databasename = "SessionDB"
datastore.sql = "select * from Attendees"
freeformstyle = Style.new
freeformstyle[:left] = 300
freeformstyle[:background_color] = '#A5c3ef'
freeform = Freeform.new
freeform.name = "DynamicDisplay"
freeform.width = 350
freeform.style = freeformstyle
freeform.valign = :top
tabularsection1 = Tabular.new
tabularsection1.maxRow = 100
tabularsection1.height = 100
style = Style.new
style[;color] = "blue"
name = CheckBox.new('')
actionclass = Action.new
actionclass.add(page, 'showFreeform', [name], [freeform])
actionclass.add(freeform, "refresh")
name.event[:Click] = actionclass
name.style = style
tabularsection1.add("Name", "Attendee Name", name)
tabularsection1.columns = datastore.select
page << [tabularsection1, freeform]
return page
end
end









