I am using win32ole module/library to gain access to an Access database. But I can’t find as I can in Rails the created_at or updated_at columns in any of the tables in the database. I was wondering how does one finds rows that are updated, then?
So I have
require 'win32ole'
connection = WIN32OLE.new('ADODB.Conneciton')
conneciton.Open('Provider = Microsoft.ACE.OlEDB.12.0; Data Source = c:\data.accdb')
recordset = WIN32OLE.new('ADODB.Recordset')
recordset.Open(some_sql, connection)
fields = []
recordset.Fields.each do |field|
fields << field.name
end
data = recordset.GetRows.transpose
so data = [
['john', 'doe', 'author'],
['mick', 'jagger', 'singer'],
['woody', 'allen', 'direct'],
['pablo', 'picasso', 'painter'],
['homer', 'simpson', 'loser']
]
fields= ['first', 'last', 'occupation']
But if someone changed Homer’s job to ‘Winner’, what kind of SQL query do I use to find out about this. Presumably, there’s a last-checked timestamp to make sense of this. Let’s just say it’s provided, how does one go about it then?
The created_at and updated_at columns in a Rails (actually ActiveRecord) model are automatically added by default in a migration script generated from a
script/generate model. Further, they’re maintained automatically by ActiveRecord when it detexts their presence. Even then, should you bypass AR and go straight to the database, the columns probably won’t be maintained for you.Access will not automatically do any of that for you, I’m afraid.While I’m sure it msut be possible to some extent to duplicate the functionality, it’s probably not trivial. Typically, you’re either going to need to handle the changes with triggers (which aren’t implemented in Access) or in the code that updates the table (which is what ActiveRecord does).