通过 ADO 从 JET 数据库中提取查询定义

发布于 2024-09-27 08:45:38 字数 139 浏览 1 评论 0 原文

我在 Delphi 2010 中有一个程序,它通过 ADO 使用 JET (mdb) 数据库。我希望能够提取数据库中某些查询的定义并将其显示给用户。这是否可以通过 SQL、某些 ADO 接口或通过询问数据库本身来实现(我似乎没有 MSysObjects 的权限)。

I have a program in Delphi 2010 that uses a JET (mdb) database via ADO. I would like to be able to extract the definitions of some of the queries in the database and display them to the user. Is this possible either via SQL, some ADO interface, or by interrogating the database itself (I don't seem to have rights to MSysObjects).

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

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

发布评论

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

评论(2

指尖上的星空 2024-10-04 08:45:38

其中一些信息可通过 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.

苏大泽ㄣ 2024-10-04 08:45:38

通过 DAO,这非常简单。您只需提取每个 QueryDef 的 SQL 属性。在 Access 内的 DAO 中,这将是:

  Dim db As DAO.Database
  Dim qdf As DAO.QueryDef

  Set db = DBEngine.OpenDatabase("[path/name of database]")
  For Each qdf In db
    Debug.Print qdf.SQL
  Next qdf
  Set qdf = Nothing
  db.Close
  Set db = Nothing

我不知道如何翻译它,但我认为一旦您习惯使用 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:

  Dim db As DAO.Database
  Dim qdf As DAO.QueryDef

  Set db = DBEngine.OpenDatabase("[path/name of database]")
  For Each qdf In db
    Debug.Print qdf.SQL
  Next qdf
  Set qdf = Nothing
  db.Close
  Set db = Nothing

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.

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