foundeo / toscript

Converts Tag based CFML to CFML Script
GNU General Public License v3.0
20 stars 9 forks source link

CFQuery not converting to new query() #21

Closed nikhildevre closed 7 years ago

nikhildevre commented 7 years ago

Input

` < cfcomponent > < cfset variables.n = 10 > < cffunction name="init" > < cfargument name="number" > < cfset variables.n = arguments.number > < cfreturn this >

    <cffunction name="myQuery" returntype="query">
        <cfquery name="myQuery" datasource="myDataSource">
            SELECT 
                Column1,
                Column2
            FROM [dbo].[myTable]
        </cfquery>
        <cfreturn myQuery>
    </cffunction>

`

OUTPUT

`component { variables.n = 10;

public function init(number) {
    variables.n = arguments.number;
    return this;
}

public query function myQuery() {
    cfquery( name="myQuery", datasource="myDataSource" ) { //Note: queryExecute() is the preferred syntax but this syntax is easier to convert generically

        writeOutput("SELECT 
                Column1,
                Column2
            FROM [dbo].[myTable]");
    }
    return myQuery;
}

} `

nikhildevre commented 7 years ago

Nevermind. It works as expected.

pfreitag commented 7 years ago

Yes ideally we would use

myQuery = queryExecute("SELECT 
                Column1,
                Column2
            FROM [dbo].[myTable]",{}, {datasource="myDataSource"});

But that is really hard to do generically if you have a query with cfif statements in the SQL, etc. So using the generic syntax still works in those more complicated cases.