Ruby win32ole MS Access:如何查找自上次导出以来更新的所有记录?

发布于 2024-08-20 16:30:28 字数 797 浏览 7 评论 0原文

我正在使用 win32ole 模块/库来访问 Access 数据库。但我无法像在Rails 中那样在数据库中的任何表中找到created_at 或updated_at 列。我想知道如何找到已更新的行?

所以我有

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']

但是如果有人将 Homer 的工作更改为“Winner”,我应该使用什么样的 SQL 查询来找出这一点。据推测,有一个最后检查的时间戳来理解这一点。就说它已经提供了,那么如何去做呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风追烟花雨 2024-08-27 16:30:28

默认情况下,Rails(实际上是 ActiveRecord)模型中的created_at 和updated_at 列会自动添加到从script/generate 模型生成的迁移脚本中。此外,当 ActiveRecord 解析它们的存在时,它们会自动维护。即使如此,如果您绕过 AR 并直接进入数据库,这些列可能不会为您维护。

恐怕 Access 不会自动为您执行任何操作。虽然我确信在某种程度上重复该功能是可能的,但它可能并非微不足道。通常,您需要使用触发器(Access 中未实现)或更新表的代码(ActiveRecord 所做的)来处理更改。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文