Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. What the hell is wrong with people today?

What the hell is wrong with people today?

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasemysqloracledebuggingquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrei Straut
    wrote on last edited by
    #1

    [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

    B 1 Reply Last reply
    0
    • A Andrei Straut

      [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

      B Offline
      B Offline
      Brisingr Aerowing
      wrote on last edited by
      #2

      :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

      A 1 Reply Last reply
      0
      • B Brisingr Aerowing

        :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

        A Offline
        A Offline
        Andrei Straut
        wrote on last edited by
        #3

        :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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups