0

Folks, This is less of a C++ question and more of a recovery from damage question.

We had a piece of C++ code that was inserting into a MSSQL database.

The developer tells me the value being passed was an integer but to craft the correct insert command was being converted to string.

However in this process the integer value was being "corrupted".

We've since addressed the code but we still have a database with a few 1000 records with bogus integers.

Here are actual examples.

input integer 7048459
output integer 37629192

input integer 6947757
output integer 37644040

input integer 6947758
output integer 37644080

The examples I can identify have a very similar pattern.

Firstly I don't quite get how the output is being derived from the input.

Secondly and this is the question, can the wrong value be "processed" back into the correct value?

Thanks in advance.

Andye
  • 51
  • 1
  • 1
  • 9
  • Can the developer give you a diff of the commit that fixed it? Then we'll know how it used to be done and what was changed. – Ivan Rubinson Aug 15 '18 at 07:39
  • Thanks Ivan. Not a developer but i believe the fix was changing the variable from %d to %s thereby explicitly accepting the integer as a string when compiling the SQL insert statement. – Andye Aug 15 '18 at 07:43
  • 1
    @Andye Whoever was responsible for that needs some training. Also where were the unit tests or the code reviews that should have caught such a straightforward error. Assuming you are the manager you really need to have a good look at your development practises. – john Aug 15 '18 at 07:57
  • Thanks John. No I'm not the manager, just the poor stoop with the problem. Your point is well made. Fortunately I can recreate the entry from source data with a SQL query and re-apply but I wanted a much better understanding of the fault to see if there was an even easier way like passing the value through a function to reverse it. As for tests it appears the implemented code only failed periodically. And none of the tests failed. For example I have 130 records of one type where only 15 are corrupt. Just need to sort the other 10,000. Thanks for your comment. You are right on all points. – Andye Aug 16 '18 at 01:33

1 Answers1

3

The output is likely an address of the string in memory, that's being converted into an integer value and saved to the data base.

Hence, there's absolutely nothing you can do to reverse that.

lenik
  • 23,228
  • 4
  • 34
  • 43