Reading database table column into an array

Creating a macro - Writing a Script - Using the API

Reading database table column into an array

Postby Lazy-legs » Wed Mar 05, 2008 12:23 am

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   Expand viewCollapse view
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
Lazy-legs
 
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: Reading database table column into an array

Postby Villeroy » Wed Mar 05, 2008 12:31 am

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   Expand viewCollapse view
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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26395
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Reading database table column into an array

Postby Lazy-legs » Wed Mar 05, 2008 12:44 am

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
Lazy-legs
 
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: Reading database table column into an array

Postby Villeroy » Wed Mar 05, 2008 12:50 am

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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26395
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Reading database table column into an array

Postby Lazy-legs » Wed Mar 05, 2008 12:56 am

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

Kind regards,
Dmitri
User avatar
Lazy-legs
 
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests