Ask Your Question
0

how to get connection information in BASE with a macro?

asked 2017-10-17 21:17:25 +0100

xoristzatziki gravatar image

updated 2017-10-18 23:12:50 +0100

I want to use my Mysql connection info to create an external link in a macro. How to get current connection info? (ip, port, user, password)

LO 5.1.6.2, ubuntu 64

edit retag flag offensive close merge delete

Comments

More descriptive. I have an odb that connects to a MySQL server. In the odb many buttons run several actions (ex.open php files in browser, using the connection information of the odb passing as GET/PUT parameters username and password). User is able to change MySQL credentials with the menu selection Edit->Database->Properties. But he buttons include code that user is not familiar with.

xoristzatziki gravatar imagexoristzatziki ( 2017-10-20 14:48:07 +0100 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2017-10-18 23:12:14 +0100

xoristzatziki gravatar image

The answer assumes I want to create an odb and not to use the connection for my own purposes. Ex. I want to use the same info to connect to the same server or to create a temporary document, not a BASE specific, that will use that info. Andrew's document is somehow irrelevant since 8.6.5 is about how to use a known connection info for creating a new connection and get some data. More explanation on why I specifically want this info: Occasionally the connection specifics are changed (either the ip or the port or even the user or password) so I recreate the connection, after opening the odb with error, by using the menus. After that "starting" change I have to go to every piece of code for buttons, in Basic and in python, and change that info and rebind python code. (I will edit the question and remove the "use" part.)

edit flag offensive delete link more

Comments

Sorry, but the answer does not 'assume' what you state at all. The edit in my answer shows that by using the original answer, you would request the information wanted (in this case the Meta data), thus getting the connection info. My edit also shows two other ways to obtain this information.

Ratslinger gravatar imageRatslinger ( 2017-10-20 07:50:45 +0100 )edit
0

answered 2017-10-17 23:50:16 +0100

Ratslinger gravatar image

updated 2017-10-20 07:41:35 +0100

Hello,

Your question is too broad to give details on this answer in a forum. To establish a connection, there is an example in the "AndrewBase" document found on this page. See section 8.6.5 of that document for more information. Once you make a connection you need to send a request to the DB for what is wanted and the return is a 'Result Set'. Information about Result Sets and using data returned can be found on this AOO Wiki starting here.

As for How to get current connection info? (ip, port, user, password), that is determined on the user side when MySQL was installed. If you don't have this info you need to get it from the DB administrator.

Edit 10/08/2017:

Sorry for misunderstanding your original question but the answer does contain relevant information. The answer you provided has given better information and would be nice as part of the question.

From this it seems you want access to the same information which is under the menu selection Edit->Database->Properties. Three ways I can think of to get this information.

Locally, this information is stored within one of the files zipped in the .odb - content.xml file. You would need to extract the data from this portion (beginning of section sample):

image description

From the connected .odb you can use a macro, as previously stated, by creating a connection and retrieving the Meta data:

    oContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
oDB = oContext.getByName(sDBName)
oCon = oDB.getConnection(sUserName,sUserPW) 

REM Use above three line for connection or the previously mentioned connection from section 8.6.5

oMeta = oCon.getMetaData()
connMeta = oMeta.getConnection().getMetaData()
print connMeta.URL
print connMeta.UserName

sDBName is either the registered name or the .odb URL.

The connMeta.URL you can retrieve will be something like: sdbc:mysql:mysqlc:192.135.214.251:3306/YOUR_DB

Don't know of any way to retrieve the password as you request.

The last way ThisDatabaseDocument.DataSource.URL retrieve the same info as in the Meta data.

Even after all that, it is not clear as to why you need to change all the code. Changing the connection is all you should need. I'm not even certain what I presented is what you are looking for.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-10-17 21:17:25 +0100

Seen: 628 times

Last updated: Oct 20 '17