Simple Example of Using the World's Simplest Code Generator....

The World's Simplest Code Generator can be used for millions of little tasks in any programmer's daily life. Here is one simple example.

Just say you Urgently need to know the number of rows in EVERY user table in your database...

In sql analyzer, run this:

select name from sysobjects where type = 'u'

This returns a list of all the user tables...

Orders
Products
Order Details
CustomerCustomerDemo
CustomerDemographics
Region
Territories
EmployeeTerritories
Employees
Categories
Customers
Shippers
Suppliers

Now paste that data into the first box in 'The World's Simplest Code Generator'

And paste this 'Pattern' into the second box:

SELECT
       '$1' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [$1]
UNION

Click [calculate] and 'Voila!'

You have this looooong script:

SELECT
       'Orders' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Orders]
UNION
SELECT
       'Products' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Products]
UNION
SELECT
       'Order Details' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Order Details]
UNION
SELECT
       'CustomerCustomerDemo' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [CustomerCustomerDemo]
UNION
SELECT
       'CustomerDemographics' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [CustomerDemographics]
UNION
SELECT
       'Region' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Region]
UNION
SELECT
       'Territories' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Territories]
UNION
SELECT
       'EmployeeTerritories' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [EmployeeTerritories]
UNION
SELECT
       'Employees' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Employees]
UNION
SELECT
       'Categories' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Categories]
UNION
SELECT
       'Customers' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Customers]
UNION
SELECT
       'Shippers' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Shippers]
UNION
SELECT
       'Suppliers' AS 'Table Name', 
      COUNT(*) AS 'Count' 
FROM [Suppliers]
UNION

(remove the word 'UNION' from the very end, before you use it...)

Execute the script in SQL Query Analyser... and here's the result:

a grid showing the sizes of each column in the database

Okay -- now any DBA could've solved that problem in a few other ways, that show off all their fancy-schmancy dba skills and justify all the time they spend reading big thick books about system stored procedures, when they should be down at the local bar trying to meet a life partner.

But the power of 'The World's Simplest Code Generator'is that you can use it to multiply the little bit of knowledge you do have, and get results on a broad number of programming problems in a big big hurry.

Here's some suggested uses:

  • XML: turn a CSV list into a scrap of XML, great for test purposes. For example, testing an RSS reader!
  • HTML: need to craft a HTML table by hand, or to write a html list by hand?
  • C# property getters and setters: Got a list of variable names that you need setters and getters for? (examples provided in the comments here
  • VB.Net property getters and setters: Got a list of variable names that you need setters and getters for? (examples provided in the comments here
  • .Net: repetitive code for validation, or perhaps serialization; need .net wrappers for interop purposes?
  • SQL: Stored procedures to write? Insert/Update statements, union statements, backup scripts...
  • PHP: I don't write PHP myself, but I know this tool could come in handy there
  • Batch files:Some times an administration task will require the construction of a big verbose chain of commands like this: "if not exist x md x"... bring on the WSCG....
  • Any other language you like

This, however, can leave you with so much spare time that they inscribe your name on a plaque on a bar stool down at the local pub. So use this tool wisely and in moderation.

 

My book "Choose Your First Product" is available now.

It gives you 4 easy steps to find and validate a humble product idea.

Learn more.

(By the way, I read every comment and often respond.)

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.