6

I want to access an ODB file (made with LibreOffice Base) in Python and extract a table for further use. The ODB contains several tables, one relation design and several forms.

Is it possible to achieve this without using any SQL?

Edit: Since it seems overcomplicated to parse this format on my own, i'll consider using a proper HSQLDB engine.

What python module accesses via HSQL (like sqlite3 for SQLite does)?

rypel
  • 4,686
  • 2
  • 25
  • 36
  • 1
    If you don't use whatever form of SQL ODB would typically use, you're going to have to write your own parser for the format, which is going to be much more complicated than using a pre-built lib and learning how to write queries. – Endophage Jul 06 '12 at 22:07
  • @Endophage: I see your point. Would [sqlite3](http://docs.python.org/library/sqlite3.html) work with ODB? – rypel Jul 06 '12 at 22:49
  • sqlite3 is its own database implementation. I believe (but I really can't say 100%) that it has no relation to ODB other than they are both databases... like Windows and Linux are both OSes. You'll need to find a python lib specifically for ODB. The Python IRC channel is a good place to ask if nobody responds here. – Endophage Jul 06 '12 at 23:43
  • If you just want to extract the table, might it not be simpler to export it as CSV in LibreOffice, then import it into something that has better Python support? – Aya May 30 '13 at 12:24
  • @Aya: it would be simpler, but i wanted to learn some SQL through this , e.g. use a client to make queries and so on – rypel May 31 '13 at 05:37

2 Answers2

5

You can consider Python Uno API that comes with OpenOffice. There are several Python examples to interact with the API, including one with the sample database

There is also this SO question where it is explained how to use uno with LibreOffice.

Community
  • 1
  • 1
Zeugma
  • 31,231
  • 9
  • 69
  • 81
  • +1 for pointing me to `PyUno`, it looks promising. but concerning the [recent changes](https://wiki.documentfoundation.org/ReleaseNotes/4.0#API_Changes) to LibreOffice's API, i'll have to see if it still works. also see this [blog](http://standardsandfreedom.net/index.php/2013/01/24/the-meaning-of-the-4-0/) – rypel May 29 '13 at 12:35
  • 1
    Yes, I have seen that: if you can afford it, stay on the previous major version up to the time pyuno is properly adapted to 4.0: they just don't seem to be ready to support pyuno+python3 on 4.0 right now... – Zeugma May 29 '13 at 12:40
1

The default form of ODB file contains an HSQLDB database. You can extract this database then access it using HSQLDB software and any client that can connect to HSQLDB.

Instructions on how to extract the database can be found here: http://programmaremobile.blogspot.co.uk/2009/01/java-and-openoffice-base-db-through.html

fredt
  • 24,044
  • 3
  • 40
  • 61