Hi Group,
Does anyone have suggestions (document/code) for a simple database example,
just to get started/familiarization?
Worked up quick example below (familiarizing with tool below
also) just for confidence build. Thought someone maybe has done similar
with VW. Would help I think before getting into the longer
DatabaseAppDevGuide.
sqlite preferred to get started; or other if needed.
I hope the simpler questions are okay -- I perceive that I'm the
only/few not on the top of the VW learning curve in the group?
#simple database example in ruby
require 'sqlite3' class HelloDatabase
def go begin open build_table add_data query ensure close end end def open db(SQLite3::Database.open(db_path)) end def
build_table
#db.execute("drop table persons;") #un-comment if table already exists db.execute("create table 'persons' ('name' varchar(255), 'phone' varchar(255));") end def add_data db.execute("insert into persons (name,phone) values ('Sue','123-456-7890');") db.execute("insert into persons (name,phone) values ('Raul','123-456-7891');") end def query records = db.execute("select * from persons") records.each {|record| puts record.to_s} end def db(*args) #getter/setter - answer or set the database ivar if (args.size==1) then @db = args[0] end @db end def close
if (!db.nil?) db.close db = nil
end end def db_path "C:/Program Files/Ruby/work/play/hellodb/db/development.sqlite3" end end HelloDatabase.new.go
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
There are a couple of screencasts covering database connectivity:
http://www.cincomsmalltalk.com/userblogs/cincom/blogView?content=smalltalk_daily_database A good idead might be to start with Glorp (object-relational mapping), instead of working with the low-level EXDI interfaces. > Does anyone have suggestions (document/code) for a simple database > example, just to get started/familiarization? > Worked up quick example below (familiarizing with tool below also) just > for confidence build. Thought someone maybe has done similar with VW. > Would help I think before getting into the longer DatabaseAppDevGuide. > sqlite preferred to get started; or other if needed. > I hope the simpler questions are okay -- I perceive that I'm the > only/few not on the top of the VW learning curve in the group? _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by Gary Peterson
If you want to see a complete sample application, you could try Glorp-Examples-Calendar (1.31,markr) in the public repository. It's a simple web application that uses Glorp to persist calendar events in a database. It illustrates all the parts of a typical web application that persists data. If you load this single package, all needed prerequisites should get loaded too. Then, see the package comment for Glorp-Examples-Calendar to get usage instructions. If you're curious, I also have a powerpoint presentation that gives a simple introduction to Glorp, using this application as an example. Best, M. Roberts Cincom Systems, Inc. On 11/3/2010 8:53 PM, Gary Peterson wrote:
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Update on database from getting-started persective:
1) Thank you to Nic who provided some classes and tips which (along
with Screen Cast) made it easy. Ended up with sqlite *one-pager* (below).
Maybe this would be helpful search 'landing page'? If anyone thinks it
worthwhile to add one-pager (for newbies) for also building table
-- let Nic and myself know.
2) Thank you to Holger and Mark for suggesting Glorp. Going to look at
that next. The upcoming projects don't have it in play, however want to get
familiar with it and go from there.
*Mark -- yes please on ppt!
*One Pager for SQLite*
" = = = = = = = = = = "
prerequisites: 1) Determine 'working folder' - ie 'vw7.7.1nc\launchpad\' (see note
at bottom)
2) Add db to folder (ie 'development.sqlite3') 3) Put dll (ie sqlite3.dll) in folder " = = = = = = = = = = " "connect to db" connection := SQLite3Connection new.
connection username: 'john'; environment: 'development.sqlite3'; connect: 'john'. session := connection getSession. " = = = = = = = = = = "
"do some sql" "select all records"
sql := 'select * from persons'. session prepare: sql. results := (session execute) answer upToEnd. "get field headers"
sql := 'pragma table_info (persons)'. session prepare: sql. results := (session execute) answer upToEnd. "select subset"
sql := 'select * from persons where name = "Sue"'. session prepare: sql. results := (session execute) answer upToEnd. "using parameters"
sql := 'select * from persons where name = ?'. session prepare: sql; bindInput: (Array with: 'Raul'). results := (session execute) answer upToEnd. " = = = = = = = = = = " "when done - disconnect" connection disconnect.
session disconnect.
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |