[Solved] Get list of table names from existing database

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
mic45267
Posts: 9
Joined: Tue Aug 29, 2017 8:41 am

[Solved] Get list of table names from existing database

Post by mic45267 »

I have an embedded and registered database in a document and would like to get the list of available tables.
The database is using as datasource CSV files, thus the names of the tables may change.
I have tried to use:

Code: Select all

vDBSource = vDBContext.getByName("localdb")
vTableNames = vDBSource.TableFilter
for i= 0 to UBound(vTableNames())
Print vTableNames(i)
next i
but my result contains only one entry which is "%"
I have looked in "LibreOffice/Tools/TableFilter..." menu and all tables should be visible.
Last edited by mic45267 on Wed Aug 30, 2017 1:10 pm, edited 1 time in total.
LibreOffice: 5.3.5.2
Mac: 10.12.6
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Get list of table names from existing database

Post by Arineckaig »

Welcome to the Forum

I should warn you that VBasic does not readily transfer to the OpenOffice API which is designed to work with a variety of program languages and applications.
An introduction to StarBASIC however can be found at:
http://wiki.services.openoffice.org/wik ... ASIC_Guide
from which can be found code such as:

Code: Select all

oDatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
oDataSource = oDatabaseContext.getByName("localdb")
oTables = oDataSource.Tables
For I = 0 to oTables.Count -1
     print oTables(I).Name
Next
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
mic45267
Posts: 9
Joined: Tue Aug 29, 2017 8:41 am

Re: Get list of table names from existing database

Post by mic45267 »

Yes, thanks- this resolved my issue.
I was not aware of the DataSource property "Tables". (see http://www.openoffice.org/api/docs/comm ... ource.html)
Where is this defined?
LibreOffice: 5.3.5.2
Mac: 10.12.6
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Get list of table names from existing database

Post by Arineckaig »

I was not aware of the DataSource property "Tables". . . . . .Where is this defined?
Alas, beyond my pay grade and limited understanding of the API. MRI suggests it could be the interface at:
http://www.openoffice.org/api/docs/comm ... plier.html.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
Post Reply