Page 1 of 1

Reading database table column into an array

Posted: Wed Mar 05, 2008 12:23 am
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

Re: Reading database table column into an array

Posted: Wed Mar 05, 2008 12:31 am
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")

Re: Reading database table column into an array

Posted: Wed Mar 05, 2008 12:44 am
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

Re: Reading database table column into an array

Posted: Wed Mar 05, 2008 12:50 am
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

Re: Reading database table column into an array

Posted: Wed Mar 05, 2008 12:56 am
by Lazy-legs
Aaah! I see. It all make sense now. Thank you very much, Villeroy!

Kind regards,
Dmitri