[Solved] Get list of table names from existing database

Creating a macro - Writing a Script - Using the API

[Solved] Get list of table names from existing database

Postby mic45267 » Wed Aug 30, 2017 10:05 am

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   Expand viewCollapse view
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
mic45267
 
Posts: 9
Joined: Tue Aug 29, 2017 8:41 am

Re: Get list of table names from existing database

Postby Arineckaig » Wed Aug 30, 2017 12:38 pm

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/wiki/Documentation/BASIC_Guide
from which can be found code such as:
Code: Select all   Expand viewCollapse view
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
Arineckaig
Volunteer
 
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Get list of table names from existing database

Postby mic45267 » Wed Aug 30, 2017 1:12 pm

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
mic45267
 
Posts: 9
Joined: Tue Aug 29, 2017 8:41 am

Re: Get list of table names from existing database

Postby Arineckaig » Wed Aug 30, 2017 3:54 pm

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/common/ref/com/sun/star/sdbcx/XTablesSupplier.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
Arineckaig
Volunteer
 
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland


Return to Macros and UNO API

Who is online

Users browsing this forum: Exabot [Bot] and 2 guests