public static string BuildCapabilityQuery( string[] attributes )
{
StringBuilder sb = new StringBuilder();
sb.Append( "SELECT * FROM ( SELECT * FROM ( SELECT instrument_uuid, capability_name, signal_name, " );
foreach (string attribute in attributes)
{
sb.Append( string.Format("sum(switch( attribute='{0}', low_value )) as {0}_low, ", attribute) );
sb.Append(string.Format("sum(switch( attribute='{0}', high_value )) as {0}_high, ", attribute));
}
if (sb.ToString().EndsWith( ", " ))
sb.Length = sb.Length - 2;
sb.Append(" FROM instrument_capabilities GROUP BY instrument_uuid, capability_name, signal_name ) WHERE ( ");
foreach (string attribute in attributes)
{
sb.Append(string.Format(" ( {0}_low IS NOT NULL or {0}_high IS NOT NULL ) AND ", attribute));
}
if (sb.ToString().EndsWith("AND "))
sb.Length = sb.Length - 4;
sb.Append( ") ) WHERE " );
foreach (string attribute in attributes)
{
sb.Append(string.Format(" ( {0}_low <= ? AND {0}_high >= ? ) AND ", attribute));
}
if (sb.ToString().EndsWith("AND "))
sb.Length = sb.Length - 4;
return sb.ToString();
}