What the hell is wrong with people today?
-
[start rant] I had to debug some logic code written by a colleague this morning. Now, the guy usually writes his code properly, but this one... Basically, it drew some 50000 rows from a MySQL table, emptied an Oracle one, inserted those 50000 into the Oracle table, called a stored procedure, updated some stock and price info in the same Oracle table, and then logged the operation info. Now, all would be well, IF THE GODDAMN THING WASN'T GROUPED IN SINGLE GODDAMN ELEPHANTING 250 LINES METHOD!!!! And then, those inserts were done 20 by 20 rows, with NOT EVEN FRICKIN' MANUALLY ESCAPED STRINGS!!! And then, of course those product codes had funky chars in there (\, ', /, " everything you may think of) And then, of course it had no comments, besides what it was doing with those 20 by 20 inserts! And just to get a feel of what I'm saying:
string query = "INSERT INTO product_sync_queue_log (price, sku, stock, log_refference) VALUES";
bool first = true;
foreach(Dictionary row in rows) {
insert_data = new StringBuilder();if(first) { first = false; } else { insert\_data.Append(", "); } try { insert\_data .Append("(") .Append(row\["price"\].ToString()).Append(", ") .Append("\\'").Append(row\["sku"\].ToString()).Append("\\', ") .Append("\\'").Append(row\["stock"\].ToString()).Append("\\', ") .Append(log\_refference) .Append(")"); insert\_rows = insert\_data.ToString(); // avoid max\_allowed\_packet size overflow if((counter % MAX\_INSERT\_ROWS) == 0 && counter != 0) { command = new MySqlCommand(query + insert\_rows + ";", conn); command.ExecuteNonQuery(); command = new MySqlCommand(log\_query + insert\_rows + ";", conn); command.ExecuteNonQuery(); first = true; } counter++; } catch(Exception e) { Helper.treatException(this.GetType().ToString(), "copyKimProductList - ", e.Message + "\\r\\n" + e.StackTrace); Helper.treatException(this.GetType().ToString(), "copyKimProductList - DEBUG - SQL Text:", "\\r\\n" + query + insert\_rows + ";"); counter++; }
}
The first lines in the try - catch are there to make the table insert syntax correct, i.e. if it's the first row, do not append "," to
query
if it's not, do the "," append. Which of course fails! I -
[start rant] I had to debug some logic code written by a colleague this morning. Now, the guy usually writes his code properly, but this one... Basically, it drew some 50000 rows from a MySQL table, emptied an Oracle one, inserted those 50000 into the Oracle table, called a stored procedure, updated some stock and price info in the same Oracle table, and then logged the operation info. Now, all would be well, IF THE GODDAMN THING WASN'T GROUPED IN SINGLE GODDAMN ELEPHANTING 250 LINES METHOD!!!! And then, those inserts were done 20 by 20 rows, with NOT EVEN FRICKIN' MANUALLY ESCAPED STRINGS!!! And then, of course those product codes had funky chars in there (\, ', /, " everything you may think of) And then, of course it had no comments, besides what it was doing with those 20 by 20 inserts! And just to get a feel of what I'm saying:
string query = "INSERT INTO product_sync_queue_log (price, sku, stock, log_refference) VALUES";
bool first = true;
foreach(Dictionary row in rows) {
insert_data = new StringBuilder();if(first) { first = false; } else { insert\_data.Append(", "); } try { insert\_data .Append("(") .Append(row\["price"\].ToString()).Append(", ") .Append("\\'").Append(row\["sku"\].ToString()).Append("\\', ") .Append("\\'").Append(row\["stock"\].ToString()).Append("\\', ") .Append(log\_refference) .Append(")"); insert\_rows = insert\_data.ToString(); // avoid max\_allowed\_packet size overflow if((counter % MAX\_INSERT\_ROWS) == 0 && counter != 0) { command = new MySqlCommand(query + insert\_rows + ";", conn); command.ExecuteNonQuery(); command = new MySqlCommand(log\_query + insert\_rows + ";", conn); command.ExecuteNonQuery(); first = true; } counter++; } catch(Exception e) { Helper.treatException(this.GetType().ToString(), "copyKimProductList - ", e.Message + "\\r\\n" + e.StackTrace); Helper.treatException(this.GetType().ToString(), "copyKimProductList - DEBUG - SQL Text:", "\\r\\n" + query + insert\_rows + ";"); counter++; }
}
The first lines in the try - catch are there to make the table insert syntax correct, i.e. if it's the first row, do not append "," to
query
if it's not, do the "," append. Which of course fails! I:wtf:
public void WriteCode(ICodeContext ctx, ICodeFile file)
{
throw new ProgrammerIsAnIdiotException("I know not I do", new BrainNotFoundException("ERROR 404: Brain Not Found. It may have been deleted or removed."));
}I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking
-
:wtf:
public void WriteCode(ICodeContext ctx, ICodeFile file)
{
throw new ProgrammerIsAnIdiotException("I know not I do", new BrainNotFoundException("ERROR 404: Brain Not Found. It may have been deleted or removed."));
}I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking
:laugh: :thumbsup:
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.