I am a Microsoft MVP, a Pluralsight Author, a Xamarin Certified Mobile Developer for iOS and Android, and the leader of the Tech Valley .NET User Group.
Sometimes I get actual live data from a client to track down a bug that only happens with their data. That data will contain student records and we don’t like to have live student laying around. We can use TDE to encrypt the data at rest, but if I’m sharing that data with other developers, I want to scrub identifying details from data set.
For the most part, I just need to replace the first and last names from student table. I could set both the first and last names to “Gank“, but if every record looks the same, it can be hard to see how the bug manifests itself. I could set both attributes to the record id value for the record, but I find that hard to look at after a while.
What I end up is writing some sort of reubenizer code. The reubenizer changes the first and last names to some variation of “Reuben”.
Let’s create a fake table to represent the student data to modify.
Running those statements will generate a result set that looks like this
The first thing I do is create a table with a set of surname prefixes. These prefixes will be used with the string “Reuben” to create the new last names
Now it’s time to create the update statement to reubenize the names. To get the surname prefix, we’ll get the last digit of the record id. That will slice up the students into 10 different sets of last names. There are other ways of doing this, this one is quick and simple. You could do the same thing with the first name, but in this case, I’m just going to use “Reuben” for the boys and “Reubenette” for the girls, and tack on that last digit.
To make the code a little cleaner, I use a Common Table Expression (or CTE) to create a calculated field for the last digit of the record id. If you are not familair with CTE’s, they let you build temporary result sets that only exist within the context of the SQL expression that they are in. I blogged about using a CTE here and there.
That update statement would look something like this
After running that update statement, the result set will look like this
The records are no longer recognizable and are distinct enough to allow me to debug the problem. This doesn’t work for every kind of data element, but it allows me to work with and share live data with out displaying any personal identification.
I have some code that uses Apple’s AppConnect API to query App store related things. I wrote a C# script that I run from LINQPad that gives me a weekly sta...
I needed to make a small change to an Android apop that we have in the Google Play store. I made the change, generated a new apk and we submitted to the ap...
I have a new course that was just published this week on Pluralsight, “Xamarin.Forms 5 Fundamentals”. It’s seven hours of tutorials and demos for the devel...
So Apple updated Xcode on my Macbook from 13.4.1 to 14. I wasn’t paying much attention to the prompts or even the version numbers. After doing so, I could n...
Comments