Ability to print/get final SQL queries

Something that people ask for/about now and then in the #yii channel over at freenode, is the ability to print/get the SQL query that would be generated from a given CDbCriteria instance, data provider and similar structures in yii.

Is this something that makes sense? If it does perhaps it’s something that should be considered. I realize a CDbCriteria might not contain all the info by itself, there might need to be context added for this to make sense.

It would be useful when debugging an application (or put another way; easier than current logging, when wanting to pinpoint a specific problem you’re having somewhere in the code). At least this is the most common reason why people ask, AFAIK.

Edit: As yjeroen pointed out there’s already a getText() on CDbCommand, so that part seems to be covered.

Yes, already in the code.

For what parts though, CDbCommand only? What about situations where you have a criteria and a data provider, or a criteria and want to do a find*() ?

In 2.0 DAO and AR are tightly integrated so I think that will work for both.

Nice :) Looking forward to seeing some actual code.

I was about to second this just today, yii really needs this. Current process of creating a syntax error so it prints it out sql in the error is kind of hacky :P. Yii Debugger owns tho.