使用 python 构建 MS Access 数据库
我计划投标的一个项目的主要目标是使用 python 创建 Microsoft Access 数据库。主要的数据库后端将是 postgres,但计划是导出 Access 映像。
这将是一个 Web 应用程序,它将接收用户的输入并通过黑匣子并将结果输出为访问数据库。该 Web 应用程序将构建在 Linux 服务器上。
我有几个相关问题:
- 是否有可靠的库或模块可以使用?
- 您使用 Access 和 python 的经历如何?
- 我需要了解哪些提示、技巧或必须避免的事项?
谢谢 :)
A primary goal of a project I plan to bid on involves creating a Microsoft Access database using python. The main DB backend will be postgres, but the plan is to export an Access image.
This will be a web app that'll take input from the user and go through a black box and output the results as an access db. The web app will be built on a linux server.
I have a few related questions:
- Is there a reliable library or module that can be used?
- What has your experience been using Access and python?
- Any tips, tricks, or must avoids I need to know about?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
你可以使用 sqlite 数据库来代替吗?
编辑:
如果它必须在Linux上并且必须在MS Access上,那么我很确定这是您唯一的选择,但价格为 1,550 美元。
您要么必须掏钱,要么说服客户更改其他两个参数之一。就我个人而言,我会推动将数据库文件更改为 sqlite。
当然,您始终可以编写自己的数据库驱动程序,但花 1,550 美元的时间可能是值得的。 mdbtools 多年来一直致力于此,但该项目几乎已被放弃。
找到了,有点
好吧,所以我就是不能放手,发现有一个名为 Jackcess 将写入任何可以运行 jvm 的平台上的 MS Access mdb 文件。当然,它是 java 而不是 python,但也许您可以学习足够的 java 来组合应用程序并从 python 执行它?或者只是将整个应用程序切换到java,无论如何。
Could you use an sqlite database instead?
edit:
If it HAS to be on linux and it HAS to be to MS Access, then I'm pretty sure this is your only choice, but it costs $1,550.
You are either going to have to shell out the money, or convince the client to change one of the other two parameters. Personally, I would push to change the database file to sqlite.
Of course you could always code up your own database driver, but it would probably be worth the time to shell out the $1,550. mdbtools has been working on this for years and the project has been pretty much abandoned.
found it, kinda
Ok, so I just couldn't let this go and found that there is a java library called Jackcess that will write to MS Access mdb files on any platform that can run the jvm. Granted, it's java and not python, but maybe you could learn just enough java to throw an application together and execute it from python? Or just switch the whole app to java, whatever.
对重复问题的各种答案表明您在 Linux 服务器上创建 MS Access 数据库的“主要目标”是无法实现的。
当然,这样的目标本身根本不值得。如果您告诉我们 Access 数据库的用户/消费者希望使用它做什么,也许我们可以帮助您。可能性:(1) 创建一个脚本和一组文件,用户下载并运行这些文件来创建 Access DB (2) 如果只是为了临时用户检查/操作,则可以使用 Excel 文件。
The various answers to the duplicate question suggest that your "primary goal" of creating an MS Access database on a linux server is not attainable.
Of course, such a goal is of itself not worthwhile at all. If you tell us what the users/consumers of the Access db are expected to do with it, maybe we can help you. Possibilities: (1) create a script and a (set of) file(s) which the user downloads and runs to create an Access DB (2) if it's just for casual user examination/manipulation, an Excel file may do.
如果您足够了解这一点:
,那么您应该知道如何执行此操作:
如果是这样,那么您已经非常接近您的数据库了 。所需的解决方案。诀窍是,您可以将 MDB 文件作为 ODBC 数据源打开。现在:我不确定您是否可以在 MDB 文件中使用 ODBC“创建表”,所以让我提出这个方法:
这对你有用吗?
几乎可以肯定,在 Windows 上完成这一切会更容易,因为对 ODBC 的支持将得到最广泛的应用。不过,我认为原则上您可以在 Linux 上执行此操作,只要您找到正确的 ODBC 组件来通过 ODBC 访问 MDB。
If you know this well enough:
then you should know how to do this:
If so, then you are very close to your required solution. The trick is, you can open an MDB file as an ODBC datasource. Now: I'm not sure if you can "CREATE TABLES" with ODBC in an MDB file, so let me propose this recipe:
Would that work for you?
It would almost certainly be easier to do that all on Windows as the support for ODBC will be most widely available. However, I think in principle you could do this on Linux, provided you find the right ODBC components to access MDB via ODBC.
您可以使用 MS 的 officedata 命名空间导出为 XML。 Access 在使用它时应该不会有任何问题。您可以提供单独的 xsd 架构,或直接在文档树中对类型和关系进行编码。这是一个简单的示例:
谷歌搜索“urn:schemas-microsoft-com:officedata”应该会出现一些有用的结果。
You could export to XML using MS's officedata namespace. Access shouldn't have any trouble consuming that. You can provide a separate xsd schema, or encode types and relationships directly in the document tree. Here's is a simple example:
Googling "urn:schemas-microsoft-com:officedata" should turn up some useful hits.
我建议将数据移动到Microsoft SQL数据库中,然后链接或导入数据访问。
I would suggest moving the data into a Microsoft SQL database, then linking or importing the data to access.
您能否创建一个自解压文件发送给安装了 Microsoft Access 的 Windows 用户?
和数据
所有 xml 文档并导入到
Access .mdb 文件。
对于用户来说这是一个额外的步骤,但您可以依赖他们现有的驱动程序、软件和桌面。
Could you create a self-extracting file to send to the Windows user who has Microsoft Access installed?
and data
all of the xml docs and import into
the Access .mdb file.
It's an extra step for the user, but you get to rely on their existing drivers, software and desktop.
嗯,在我看来,你需要在运行 Windows 的 Linux 机器上有一个 vmware 服务器的副本,在虚拟机中需要一个用于写入访问的 Web 服务,以及从主 Linux 机器与其进行通信。您不会找到在 Linux 上创建访问数据库的方法。称其为要求并不意味着它在技术上是可行的。
Well, looks to me like you need a copy of vmware server on the linux box running windows, a web service in the vm to write to access, and communications to it from the main linux box. You aren't going to find a means of creating an access db on Linux. Calling it a requirement isn't going to make it technically possible.
http://adodb.sourceforge.net/ - 安装在 Linux 上,用 php 或 python 编写,连接到 Access和 PostgreSQL。
我们已经使用它很多年了,而且效果非常好。
http://adodb.sourceforge.net/ - installs on linux, written in php or python, connects to Access and PostgreSQL.
We've been using it for years, and it works beautifully.