3

i have an large SQL Statement, is there any "smarter" way to format this stuff ??


$serverFields = 'SERVER_ID, SERVERNAME, SERVERLOCATION_ID, SERVERLOCATIONDETAIL_ID,
                             SERVEROS_ID, SERVEROSVERSION_ID, IP_BACKEND, IP_FRONTEND, IP_BACKUP,
                             SERVERREMOTETOOL_IDS, LOGIN, DESCRIPTION, TIME_INSERT, TIME_UPDATE,
                             CHANGE_USER, MANDATOR_ID, TIVOLI_UPDATABLE, TIVOLI_LAST_SCAN,
                             TIVOLI_LAST_UPDATE, WINDOMAIN_ID, PROCESSORCOUNT, OS_ID, PHYSICAL_MEMORY_KB';

$osFields = 'OSLANG_ID, OSARCH_ID, OSSUBVERSION_ID, OSMINORVERSION_ID, OSMAJORVERSION_ID, OSTYPE_ID';

$processorFields = 'PROCESSORMODEL_ID, PROCESSORMANUFACTURER_ID';

$sql = sprintf( "SELECT %s , %s , %s FROM %s s LEFT OUTER JOIN ( (OS JOIN OSSUBVERSION USING (OSSUBVERSION_ID)) JOIN OSMINORVERSION USING (OSMINORVERSION_ID) JOIN OSMAJORVERSION USING (OSMAJORVERSION_ID) )USING (OS_ID) LEFT OUTER JOIN ( PROCESSORMODEL JOIN PROCESSORMANUFACTURER USING(PROCESSORMANUFACTURER_ID) )USING (PROCESSORMODEL_ID) WHERE %s = :id AND MANDATOR_ID = :mandatorId", $serverFields, $osFields, $processorFields, $this->_tableName, $this->_identifier);

1 Answer 1

3

Well, I'd write and indent it all somewhat differently, but whether it's "smarter" is up to you:

$sql = sprintf("
    SELECT %s, %s, %s
    FROM %s
    LEFT OUTER JOIN OS USING (OS_ID)
    JOIN OSSUBVERSION USING (OSSUBVERSION_ID)
    JOIN OSMINORVERSION USING (OSMINORVERSION_ID)
    JOIN OSMAJORVERSION USING (OSMAJORVERSION_ID)
    LEFT OUTER JOIN PROCESSORMODEL USING (PROCESSORMODEL_ID)
    JOIN PROCESSORMANUFACTURER USING (PROCESSORMANUFACTURER_ID)
    WHERE %s = :id
    AND MANDATOR_ID = :mandatorId
", $serverFields, $osFields, $processorFields, $this->_tableName, $this->_identifier);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.