Many thanks for the confirmation Jeremy,
So what is the difference between the way I've done it and MODELS format?
eg....
require statements in here
Class DB
def Initialize
open DB connection, test for failure
end
def getallrecs
get a list of all data from a particular table
end
def save
save data to a particular Table
end
def find_a_rec(nos)
query table for a record
end
end
I mean I have a script (layed out similar to above pesudo code) as a class
that handles all enteraction with the underlaying DB but I pass back a
dataset or act against the DB/Table from within a Method call.
Is there anything I'd gain from going to a model based approach to datasets?
cheers,
Dave.
On 22 November 2010 05:42, Jeremy Evans <[email protected]> wrote:
> On Nov 20, 5:54 pm, dave <[email protected]> wrote:
> > I have written a sign in / out program to record start & finish times
> > of staff.
> >
> > I have 1 ruby script that currently handles my connection and all
> > query's, deletions, Updates and additions to the tables with the
> > currently connected DB.
> >
> > I now have a need to get another connection to a database on the same
> > server. how best would I do this?
> >
> > below is the current connection setup
> >
> > require 'sequel.rb'
> > require 'logger'
> >
> > class Dopen
> >
> > def initialize
> > @path = "/path to log files/"
> > @log = Logger.new("#...@path}db - info.log")
> > @log.level = Logger::DEBUG
> >
> > @log.debug('initialing the DB access!')
> >
> > @db = Sequel.connect(:adapter => 'mysql', :localhost =>
> > 'localhost', :database => 'test', :user => 'dave', :password =>
> > 'test')
> >
> > rescue DBI::DatabaseError => e
> > @log.debug("Asn error occurred\nError code: #{e.err}\nError
> > message: #{e.errstr}")
> >
> > ensure
> > @log.debug('DB closed!')
> > @db.disconnect if @db
> > end
> > =begin
> > In here i have method calls to get data from the table and
> > delete rows etc but not shown.
> > =end
> >
> > end
> >
> > the schema is something like this...
> >
> > Database - test
> > Table test
> > id - pimary autoincrement
> > name
> > address
> > barcode
> > phone
> > email
> >
> > Database - codes
> > Table barcdoes
> > barcode
> > datetime
> > code
> > flag
> >
> > Best of my knowledge there isn't a index on this table (I've copied
> > from someone else and they don't have a column called id or a primary
> > index).
> >
> > What i am wanting to do is get a barcode belonging to a person then
> > get all matches for that code found in the 2nd database table
> > barcodes.
> >
> > from this i spit them out to a report.
> >
> > How best to get the connection to the second database?
> > I don't really care about having them joined (1 dataset for both
> > Tables )
> >
> > @db = Sequel.connect(:adapter => 'mysql', :localhost =>
> > 'localhost', :database => 'test', :user => 'dave', :password =>
> > 'test'; :adapter => 'mysql', :localhost => 'localhost', :database =>
> > 'codes', :user => 'ann', :password => 'test')
> >
> > I had tried another Sequal.connect statement but was getting errors so
> > believe that approach to be wrong.
> >
> > @db = Sequel.connect(:adapter => 'mysql', :localhost =>
> > 'localhost', :database => 'test', :user => 'dave', :password =>
> > 'test')
> >
> > @db1 = Sequel.connect(:adapter => 'mysql', :localhost =>
> > 'localhost', :database => 'codes', :user => 'ann', :password =>
> > 'test')
>
> That's the correct approach, as you want to use two separate
> Sequel::Database instances. If you were getting errors, you should
> probably post the backtrace and related code.
>
> Jeremy
>
> --
> You received this message because you are subscribed to the Google Groups
> "sequel-talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<sequel-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/sequel-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.