Something akin to this still exists in some code bases I have to work on.
Step 1: SELECT many rows from the database
Step 2: Loop thru each row
Step 3: * SELECT each row again for some data not fetched originally
Step 4: * SELECT rows from a child table
Step 5: * * Loop thru each child row
Step 6: * * * Keep only a single row and ignore the rest
Step 7: Never use any of the data
I saw something similar in the last legacy app I worked on. Bear in mind this was a single, monolithic, method embedded in a Windows form. It went like this....
Step 1:
Do For Each User Criteria Entry
Select a lot of rows from the database using unparameterized user entry
Loop through the results to load them in an array
Loop through this array doing a switch to determine which single row SQL to execute, loading the resulting data into a new array.
Clear out the original array.
Loop
Step 2:
Loop through the results array, adding/deleting values based on poorly documented business rules and deleting any duplicates.
Step 3:
Repeat of Step 1, using slightly different criteria on the switch SQL statements based on the business rule modifications. It was likely this code was cut and pasted from step 1 and modified.
Step 4:
Loop trough the results array again to delete any duplicates
Step 5:
Display the first record from the array (there was only supposed to be one record by this point but that didn't always happen)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Something akin to this still exists in some code bases I have to work on.
Step 1:
SELECTmany rows from the databaseStep 2: Loop thru each row
Step 3: *
SELECTeach row again for some data not fetched originallyStep 4: *
SELECTrows from a child tableStep 5: * * Loop thru each child row
Step 6: * * * Keep only a single row and ignore the rest
Step 7: Never use any of the data
I saw something similar in the last legacy app I worked on. Bear in mind this was a single, monolithic, method embedded in a Windows form. It went like this....
Step 1:
Do For Each User Criteria Entry
Select a lot of rows from the database using unparameterized user entry
Loop through the results to load them in an array
Loop through this array doing a switch to determine which single row SQL to execute, loading the resulting data into a new array.
Clear out the original array.
Loop
Step 2:
Loop through the results array, adding/deleting values based on poorly documented business rules and deleting any duplicates.
Step 3:
Repeat of Step 1, using slightly different criteria on the switch SQL statements based on the business rule modifications. It was likely this code was cut and pasted from step 1 and modified.
Step 4:
Loop trough the results array again to delete any duplicates
Step 5:
Display the first record from the array (there was only supposed to be one record by this point but that didn't always happen)