通过 ADO 从 JET 数据库中提取查询定义
我在 Delphi 2010 中有一个程序,它通过 ADO 使用 JET (mdb) 数据库。我希望能够提取数据库中某些查询的定义并将其显示给用户。这是否可以通过 SQL、某些 ADO 接口或通过询问数据库本身来实现(我似乎没有 MSysObjects 的权限)。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
其中一些信息可通过 ADOX 调用获得。 MSDN 网站。
基本上,您需要做的是导入 ADOX 类型库,然后使用为您生成的包装器来访问底层 API。从那里开始,就像导航层次结构以获取所需的数据一样简单。
您将需要访问特定的查看对象,然后从那里获取命令属性。
Some of that information is available via ADOX calls. There is an overview of the api with some examples (unfortunately not in Delphi) on the MSDN website.
Basically what you will want to do is to is to import the ADOX type library, and then use the wrapper that is generated for you to access the underlying API. From there its as simple as navigating the hierarchy to get at the data you need.
You will need to access the specific View object, and from there get the command property.
通过 DAO,这非常简单。您只需提取每个 QueryDef 的 SQL 属性。在 Access 内的 DAO 中,这将是:
我不知道如何翻译它,但我认为一旦您习惯使用 DAO 而不是 ADOX,这是最简单的方法。
我根本不使用 ADO,但我猜测它有一个视图集合,并且 SQL 属性适用于 SELECT 查询。但是,如果您有兴趣获取所有保存的 QueryDef 的 SQL,您还需要查看 DML 查询,因此您必须查看存储过程。我必须为此查找语法,但我非常确定这就是您通过 ADO 获取信息的方式。
Via DAO, it's pretty easy. You just extract the SQL property of each QueryDef. In DAO from within Access, that would be:
I don't know how to translate that, but I think it's the simplest method once you're comfortable with using DAO instead of ADOX.
I don't use ADO at all, but I'm guessing that it has a collection of views and the SQL property would work for SELECT queries. However, if you're interested in getting the SQL for all saved QueryDefs, you'd also need to look at the DML queries, so you'd have to look at the stored procedures. I would have to look up the syntax for that, but I'm pretty certain that's how you'd get to the information via ADO.