[GRLUG] Client/Server Database app question
    zdennis 
    zdennis at mktec.com
       
    Thu Jan 19 08:52:10 EST 2006
    
    
  
Chris Lamrock wrote:
> Right now the program is made up of 4 or 5 live databases.  One with quotes, 
> one with customers, notes, signatures and companies - all running in Foxpro 
> (since 1995!) :-)
> 
> So the databases would be created new in Mysql or what have you...
> 
> Is that what you were asking?
> 
Yeah, I am thinking that I'd like to show you a neat database trick. Here is what sample code looks 
like. I am a big fan of simplifying database access:
Say you have a customers table in the databse and it has a relationship to the signatures table.
class Customer < ActiveRecord::Base
   has_many :signatures
end
class Signature < ActiveRecord::Base
   has_one :customer
end
That right there handles our relationship between Customer and Signature. Do save data to the 
databse you'd write:
customer = Customer.new
customer.name = "Jon Doe'
customer.company = 'ABC Corp.'
signature = Signature.new
customer.signature = signature
customer.save
signature.save
And that's pretty much it. Of course it gets more advanced and you can get crazy with complex joins 
and conditions on queries, but it makes accessing the databse 1000% nicer, then using Perl::DBI or 
something similar.
This may/may-not fix what you're going for, but I thought I'd throw it out as a suggestion. The 
sample code above is from the ActiveRecord portion of Ruby On Rails. Although you can use 
ActiveRecord by itself without Rails, I use it alot.
Whatever you choose, good luck!
Zach
    
    
More information about the grlug
mailing list