我可以从 SQLite 数据库生成 XML 数据吗? [英] Can I generate XML Data from the SQLite Database?

查看:25
本文介绍了我可以从 SQLite 数据库生成 XML 数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在像 Oracle 或 PostgreSQL 这样的 DBMS 中有从数据库生成 XML 数据的函数:http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb13gen.htmhttp://www.postgresql.org/docs/current/static/functions-xml.html#AEN15086

我的问题是 SQLite 数据库中有类似的东西吗?可能有一些额外的工具、库甚至是用于此目的的标准工具吗?

In such DBMS as Oracle or PostgreSQL there are functions for generating XML Data from the database: http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb13gen.htm or http://www.postgresql.org/docs/current/static/functions-xml.html#AEN15086

My question are there something similar in SQLite database? May be there are some additional tools, libraries or even standard tools for this purpose?

推荐答案

答案是是也不是".它不一样,但 SQLite 在这方面实际上非常有能力.但是,您必须推出自己的解决方案.

The answer is "yes and no." It isn't the same, but SQLite is actually pretty capable in this regard. You do have to roll your own solution however.

要了解如何执行此操作,您必须了解 SQLite 与 PostgreSQL 或 Oracle 等数据库有何不同.后两者是通过套接字(网络或 UNIX)与客户端通信的服务器,而 SQLite 是一个库,它使用进程内内存与应用程序的其余部分进行通信.SQLite 没有特定的 XML 工具,但它有基础设施供您创建自己的工具.鉴于您没有指定您正在使用的语言(这使得嵌入式数据库方法有所不同),我将讨论如何考虑它,然后提供指向 Python 和 C API 文档的指针.

To understand how to do this you have to understand how SQLite differs from a database like PostgreSQL or Oracle. While the latter two are servers which communicate with clients over sockets (network or UNIX), SQLite is a library which communicates with the rest of the application using in-process memory. SQLite has no specific XML tools but it has infrastructure for you to create your own. Given that you didn't specify the language you are working with (and this makes the embedded db approach different) I will discuss how to think about it, and then provide pointers to the Python and C API documentation.

在 PostgreSQL 中,您可以通过提供在调用时运行的函数来扩展 SQL.这些位于后端并在调用时实例化.在 SQLite 中,您的进程与后端相同,因此您在库中拥有的任何内容都与 SQLite 处于同一进程中.这意味着您可以以任意方式将 SQL 扩展为一种语言,只需告诉 SQLite 在看到它不理解的函数时调用什么函数即可.因此,您可以通过定义函数调用然后将它们注册到 SQLite 来构建它.

In PostgreSQL you extend SQL by providing functions which get run when they are called. These live in the backend and are instantiated when called. In SQLite, your process is the same as the backend so anything you have in your library is in the same process as SQLite. This means you can extend SQL as a language in arbitrary ways just by telling SQLite what function to call when it sees a function it doesn't understand. Thus you would build this up by defining function calls and then registering them with SQLite.

Python 文档 提供了一个完整的工作示例,说明如何注册带有 SQLite 的 Python 函数,以便在调用时生成 md5hash.可以使用相同的方法来生成整个 XML 文档.我首先注意到它,因为这很好地说明了您可以做什么.

The Python documentation provides a complete working example with how to register a Python function with SQLite such that it generates an md5hash when called. The same approach can be used to generate whole XML documents. I am noting it first because this gives a good example of what you can do.

SQLite 文档从 C 的角度详细介绍了这一点.从这里您可以定义自己的聚合、自己的函数等等.因此,您拥有完成此类任务所需的所有构建块,只是没有提供最后一英里.

The SQLite documentation covers this in detail from a C perspective. From here you can define your own aggregates, your own functions, and much more. So you have all the building blocks you need for something like this, just the last mile is not provided.

这篇关于我可以从 SQLite 数据库生成 XML 数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆