Reading database table column into an array

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Lazy-legs
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Reading database table column into an array

Post by Lazy-legs »

Hello,

I'm trying to create a simple macro that reads data from a database table column into an array using the ColumnAsArray function. Here is what I've got so far:

Code: Select all

DBContext=createUnoService("com.sun.star.sdb.DatabaseContext")

DataSource=DBContext.getByName("MyDB")
ConnectToDB=DataSource.GetConnection ("","")

DBTables=ConnectToDB.tables
WordTable=DBTables.getByName("Wordlist")

TableColumns=WordTable.columns
WordColumn=TableColumns.getByName("Word")

Words=ColumnAsArray("MyDB", "Wordlist", "Word")
The problem is that this code returns the "Sub-procedure or function procedure not defined" error. What am I doing wrong?

Thank you!

Kind regards,
Dmitri
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Reading database table column into an array

Post by Villeroy »

The problem is that "ColumnAsArray" is nowhere defined. If that routine is in another Basic library you've got to take care that it is loaded. How to load a library named "DBTools":

Code: Select all

GlobalScope.BasicLibraries.loadLibrary("DBTools")
DBTools.Module1.ColumnAsArray("MyDB", "Wordlist", "Word")
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Lazy-legs
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: Reading database table column into an array

Post by Lazy-legs »

Hi Villeroy,

Thank you for your speedy reply. To be honest, I'm confused. I thought that the ColumnAsArray is a built-in function. Adding the code you've suggested returns the "com.sun.star.container.NoSuchElement" error. I have no clue what I'm doing and I need help. :shock:

Thank you!

Kind regards,
Dmitri
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Reading database table column into an array

Post by Villeroy »

There might be no library "DBTools" on your system. It was just a hint what to do if you would know where and what ColumnAsArray is. No, this stupid Basic has almost nothing built-in. If it where defined in the API it would read "someObject.ColumnAsArray(...)"
I guess you want to call this one by DrewJensen. http://www.oooforum.org/forum/viewtopic ... umnasarray
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Lazy-legs
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: Reading database table column into an array

Post by Lazy-legs »

Aaah! I see. It all make sense now. Thank you very much, Villeroy!

Kind regards,
Dmitri
Post Reply