Hey is there any way to get the underlying connect...
# lucee
a
Hey is there any way to get the underlying connection object from a data source name? For some failsafe checks I need to ensure that some JDBC settings are in place (specifically the
allowMultiQueries
setting passed in the connection string).
t
you could start with
getApplicationMetadata()
if that is no good then
getpagecontext().getConfig().getDatasource("dsourcename").getConnectionStringTranslated()
1
a
Yeah cheers
getApplicationMetadata
isn't the object but it'll do. And cheers for the other option.
getConfig
doesn't seem to be part of the standard PageContext spec, but is implemented in Lucee's
lucee.runtime.PageContext
class. On the https://docs.lucee.org/reference/functions/getpagecontext.html docs page there's a link to https://javadoc.lucee.org/lucee/runtime/PageContext.html, am I safe to assume that API is intended to be used in our applications, and accordingly is subject to the usual stability "guarantees" that the CFML parts of Lucee has (eg in https://docs.lucee.org/). I guess the question is just clarifying that it's not considered "internal implement detail" and subject to change at the whim of the Lucee dev team as their needs dictate?
t
It has existed since Railo, that is of course no guarantee for the future
there is Administrator.cfc https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/resource/component/org/lucee/cfml/Administrator.cfc which is claimed to by a maintained wrapper for cfadmin it has a
getDatasource()
method
a
If that is like how
<cfadmin>
works, it's only good for getting stuff actually set in the admin. These DSNs are application-set. The metadata approach is fine for my purposes.
t
we tend to avoid that as you need a password
a
Interestingly it seems that not all of it requires a pwd. Which made me go "erm...?", but then I went "yeah not using this, don't care"
👍 1
eg:
<cfadmin action="getDebugData" returnvariable="debug_data">
... no pwd needed.
getDatasource
did need the pwd though.
t
this is a slightly more belt and braces version (excuse tags)
Copy code
<cfset dataSource = getPageContext().getDatasource(datasourceName)>
			<cftry>
				<cfset details["Database"] = dataSource.getDatabase()>
				<cfcatch>
					<!--- if the datasource is defined in Application.cfc getDatabase() will error --->
					<cfset details["Database"] = CreateObject("java", "lucee.runtime.services.DataSourceImpl").init(dataSource).getconnection().getCatalog()>
				</cfcatch>
			</cftry>