On Windows 10, I’m trying to execute a simple query but I don’t understand the code structure required. I cut and pasted an example I found but how do I find what the class and connectionString need to be?
What name is defined as datasource? I think your definition in the queryexec line shouldn’t be “this.datasources”, instead it needs to be the defined name. Usually if the datasource is defined and set with the name “myDataSourceName”, then the string defined in the application cfc should be something like this.datasources[“myDataSourceName”]=… then the query should be like:
var qry = queryExecute( sql: "select * from tblusers", options:{ datasource="myDataSourceName"} );
Always read the error message and stack trace, it’s telling you exactly what the problem is, it may seem a little cryptic at first but all the clues are there.
Type is missing from what? The datasource? Then cfdump out this.datasources and see what you’re passing in
Lucee 5.3.8.169-SNAPSHOT Error (expression)
Message The key [type] does not exist, only the following keys are available: [A, B, C].
Stacktrace The Error Occurred in C:\lucee\tomcat\webapps\ROOT\query.cfm: line 3
1:
2: this.datasources = {a:1,b:2,c:3}; 3: var qry = queryExecute( sql=“select * from tblusers”, options={ datasource : this.datasources } );
4:
5: for( var row in qry ) {
Java Stacktrace lucee.runtime.exp.ExpressionException: The key [type] does not exist, only the following keys are available : [A, B, C].
at lucee.runtime.type.util.StructSupport.invalidKey(StructSupport.java:65)
at lucee.runtime.type.StructImpl.get(StructImpl.java:139) at lucee.runtime.listener.AppListenerUtil.toDataSource(AppListenerUtil.java:247)
at lucee.runtime.tag.Query.toDatasource(Query.java:247)
at lucee.runtime.tag.Query.setDatasource(Query.java:242)
I had used the code snippet generated by editing the datasource page but hadn’t realised it was intended for use in Application.cfc (I was including it in my program), so presumably that’s why I got the non-existent datasource message. I’m now reading up on CFC’s in Lucee and trying to understand how to set up this code snippet and then how to refer to the cfc from my program. I also don’t understand what the “this.” prefix means.
I totally understand the problem you are facing, really a LOT! There is a need of a new cfml book/ressource that handles cfml in a modern way. There is plenty of stuff all over the net, but no easy step by step guide. You can get a lot of Lucee docs, but its like a index with some good guides. Best at the moment in the net s: learncfinaweek.com but it has been down often lately. We really need some easy contemt like w3schools for cfml with a modern approach. There is a lot of.work to do!!! May be you are the chance for some of us loose conributors to go for it!
If you set the configured datasource in this.datasource=“datasourcename” in an application.cfc means you don’t need to add datasource in cfquery/queryexecute
But if you have multiple datasource means you can set default datasource by using this.defaultdatasource=“datasourcename”
<cfset res = getApplicationMetadata()>
<cfdump var="#res.datasource#">
What would you get from the above code using in the .cfm file? If you configured the datasource in application.cfc by this.datasource means, the above code returns the datasource name