[Solved] Accessing the document's data sources

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jkordani
Posts: 11
Joined: Wed Nov 21, 2007 5:01 am

[Solved] Accessing the document's data sources

Post by jkordani »

I am working with base and i need to write a few macros that take information from the tables and outputs it, and does calculations etc. Before all I needed to do was just tie UI forms to a filter builder, that got working thanks to Drew! But now I need to actually work with the data, not to mention be able to print it out and make a pager for it since the size of the output can get large. But I found that in order to use rowsets and queries based on my tables I had to register the base file as a data source in oo options. This may be an incorrect statement, maybe I typed something wrong, so if so please tell me. If not, then the problem with doing it that way is if the file ever gets moved, then the user has to go re register the file as a data source in oo options! Or is this also not the case? Am I missing something? So what im looking for is a way to get access to the current files datasource(s). I tried doing something like this.datasource or something, no avail. Anyone got any pointers?
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Accessing the document's data sources.

Post by DrewJensen »

Do you mean you want to call this routine from say a button on a form and then get access to the datasource used by that form?

or

You want to refer to an ODB file and get the datasource for it?

Thanks
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
jkordani
Posts: 11
Joined: Wed Nov 21, 2007 5:01 am

Re: Accessing the document's data sources.

Post by jkordani »

the first one.
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Accessing the document's data sources.

Post by DrewJensen »

Alright, let me put together a decent little example for you...won;t take very long...but a bit more then a few minutes..OK
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
jkordani
Posts: 11
Joined: Wed Nov 21, 2007 5:01 am

Re: Accessing the document's data sources.

Post by jkordani »

Wow, I've seen your other posts, how long have you been using this language? You make it seem so easy! Thanks for your help btw.
mobi-doc
Posts: 59
Joined: Wed Nov 21, 2007 11:29 am
Location: Greece

Re: Accessing the document's data sources.

Post by mobi-doc »

In BASIC your form document has all the rowset/resultset functionality. You just access your root form with

Code: Select all

oForm=ThisComponent.drawpage.forms(0)
and then you can use methods like oForm.first, oForm.last, oForm.getString, etc...

To get access to the datasource of your form try

Code: Select all

oConn=ThisComponent.Parent.DataSource.getConnection("","")
and then you can execute queries with

Code: Select all

oResultSet=oConn.createStatement.executeQuery("the sql code goes here...")
have a nice day.
jkordani
Posts: 11
Joined: Wed Nov 21, 2007 5:01 am

Re: Accessing the document's data sources.

Post by jkordani »

Thanks, that did the trick!
Post Reply