TechQuest: Welcome to TechQuest.
Software Development Secrets: Easing Your Burden – Writing Code that Spits Out Code - Part 1
No users have rated this item yet.
Sometimes software coding involves repetitive tasks, such as writing the SQL code that populates a database. In one of my current projects, we have a database table that defines properties for various objects—our application reads this database table and uses this information to 1) populate various UI elements, 2) read the values users have set for the various properties, and 3) use those stored property values to read and set the values as the related objects are instantiated. Here is an example:
Uploaded Image

Above is a screenshot from DocAuto’s (IMHO revolutionary, explosively powerful, and surgically accurate) admin tool for SharePoint called SPOrganizer (https://www.docauto.com/products/sporganizer/). What you see is the user interface where you can turn on and off the various Features in a SharePoint Site Collection. This list of features is driven by a database table stored on the customer’s machine. It looks like this:
Uploaded Image

But the document of record that our team uses to design this database table is in the form of an Excel spreadsheet. It looks like this:
Uploaded Image

Whenever a change is made to our Excel spreadsheet, we need to make that change in the database, which means we must first make that change in our project’s installer in the form of SQL INSERT statements that define and populate the database table. I’ll explain how we do this in detail, but I think it will be helpful if I use a simpler example. Let’s say we have an excel sheet that looks like this:
Uploaded Image

And we have a database table that looks, similarly, like this:
Uploaded Image

What we need are insert statements that will move the data from our Excel sheet into our database table. We’ll do this using Excel formulas that build our SQL INSERT statements. In the cell just to the right of our data and in the first row of our data, we create an Excel formula that builds our SQL INSERT statements. You can see its formula format in the Excel Formula Bar. Then all we have to is copy that formula to the other rows and you can see the resulting SQL INSERT statements in the grid’s Column E.
Uploaded Image

All you have to do from here is to cut and paste Column E into SQL Management Studio, test, and then we put these commands into our Visual Studio Project that executes this code when our customer installs our product.
Uploaded Image

This saves a great deal of unnecessary typing and ensures that our design is implemented consistently throughout our project. It's not an out-of-this-world technological solution, but software developers often helpful to use well-known tools to make their jobs easier and to ensure quality through various stages of the development cycle.

2,489 views.
No users have rated this item yet.