views:

84

answers:

4

I have to use hardcoded values for certain fields because at this moment we don't have access to the real data.

When we do get access, I don't want to go through a lot of work uncommenting.

Is it possible to keep this statement the way it is, except use '25' as the alias for ratecode?

   IF(special.ratecode IS NULL, br.ratecode, special.ratecode) AS ratecode,

I have about 8 or so IF statements similar to this and I'm just too lazy ( even with vim ) to re-append while commenting out each if statement line by line. I would have to do this:

$sql = 'SELECT u.*,';

// IF ( special.ratecode IS NULL, br.ratecode, special.ratecode) AS ratecode
$sql.= '25 AS ratecode';
+3  A: 

Can't you create a fake database with the test data in it? That's how I usually do database-related testing. If you're attempting to write "real" unit tests or something, you might want to consider making mock objects for your DB layer, but IMHO that's usually overkill. If you're able to swap out SQL engines, you could even swap in something like SQLite for your local testing.

rmeador
I want to basically preserve my long long query without using server-side commenting, not create an entire fake database.
meder
you make it sound like an arduous task... can't you just run your DB creation scripts and then insert '25' into the relevant table?
rmeador
If your priority is producing readable, maintainable, well-tested code, creating a dummy database is the way to go. Otherwise, you risk producing new bugs when you go back and replace code. If you're adamant about your approach, you can try `$sql = 'SELECT u.*, '.((ON_PROD) ? 'IF (special.ratecode IS NULL, br.ratecode, special.ratecode)' : 'SELECT 25').' AS ratecode';`
webbiedave
A: 

I'd put all this stuff into views in your database, and then tweak the logic when it comes to exposing the "real" data: that way you don't have to tinker with any of your application code

e.g. initially:

create view myStuff as
select 25 as my_val
.....
from my_table

and then to be replaced later with:

create view myStuff as
select my_val
.....
from my_table
davek
A: 

If you're using a lot of these SQL statements, you could just put a little file in the application's directory; upon initiation of the script, it would check for the existence of this file, and if it found said file, it would set a variable like $isproduction to TRUE; otherwise, FALSE. Then, for each SQL statement (IDE's with PCRE capabilities are really good for stuff like this) you would do something like

if ($isproduction === FALSE) {
    //big long SQL statement here
}
else {
    //create false data here
}
Bushman