Queryexecute or cfquery best practice

If you don’t use queryExecute then what do you use? Do you only use <cfquery> tags? It would be interesting to know what you deem to be best practices here and why.

2 Likes

@micstriit I’d also be intrigued what you use to query in the most efficient memory optimised way.

If queryexecute is a wrapper to cfquery we know the component style to be heavier what’s the alternative ?

Thanks

Alex

First of all i have to correct myself, I meant new Query() and not queryExecute, queryExecute is fine on that front.

Yes i still use the query tag, also in script like this

query datasource="myds" name="qry" params=['susi'] {
    ```select * from test where x=?```
}

sure you also can do, if you prefer

query datasource="myds" name="qry" params=['susi'] {
    echo("select * from test where x=?");
}

i also prefer to use loop instead of using of for in most cases like

loop struct=sct index="k" item="v" {
   dump(k&":"&v);
}
loop array=arr item="v" {
   dump(v);
}

that brings back the idea of tags that can return a object, so i can do

qry=query datasource="myds" params=['susi'] {
    ```select * from test where x=?```
};
// may just this
qry=cfquery( datasource="myds", params=['susi']) {
    ```select * from test where x=?```
};

sadly it is not that easy to do, but actually it should be possible in the lanuage to be more consistent.

1 Like

queryExecute is just a wrapper for cfquery

Ahh, OK. Yes, I know never to use new Query() but do use queryExecute() quite a bit and so I was concerned there was some issue I did not know about! Thank you for clarifying your remarks.