Get Name Of Physical DB Through Datasource?

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Get Name Of Physical DB Through Datasource?

Postby bcusick » Thu Jun 29, 2017 5:34 pm

Hey Guys,

I know that I can get the database VENDOR using

Code: Select all
databaseManager.getDatabaseProductName(theConn)


Is there a way to get the physical database NAME (or JDBC URL is fine) from a connection name?

I'm trying to branch code based on whether the named connection is pointed to a specific database name.

Thanks!

Bob
Bob Cusick
bcusick
 
Posts: 1183
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Re: Get Name Of Physical DB Through Datasource?

Postby mboegem » Thu Jun 29, 2017 6:23 pm

Hi Bob,

the Usermanager plugin has the ability to read any property from the servoy.properties file.
Since this is the place where the connection information is stored, I think you should be able to retrieve it.
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1382
Joined: Sun Oct 14, 2007 1:34 pm
Location: Hoofddorp, The Netherlands

Re: Get Name Of Physical DB Through Datasource?

Postby bcusick » Thu Jun 29, 2017 6:50 pm

OK Marc - thanks.

I was hoping I didn't have to use a plugin... but if I need to, I will.

I really appreciate your quick response! :D

Bob
Bob Cusick
bcusick
 
Posts: 1183
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Re: Get Name Of Physical DB Through Datasource?

Postby Mccourt.cordingley1372837951 » Mon Jul 03, 2017 1:33 pm

Hi Bob

You could always just query it and grab a dataset with getDatasetbyquery using the desired connection.

Sql server
Code: Select all
select DB_NAME();


MySql
Code: Select all
SELECT DATABASE();


Postgres
Code: Select all
SELECT current_database();



Code: Select all
   var sql = "select DB_NAME();"
   var server = databaseManager.getDataSourceServerName(foundset.getDataSource())
   var ds = databaseManager.getDataSetByQuery(server,sql,null,1)
   application.output(ds.getValue(1,1))
User avatar
Mccourt.cordingley1372837951
 
Posts: 28
Joined: Wed Jul 03, 2013 9:52 am

Re: Get Name Of Physical DB Through Datasource?

Postby bcusick » Thu Jul 06, 2017 3:02 pm

That's brilliant! Thank you very much!
Bob Cusick
bcusick
 
Posts: 1183
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 1 guest