Jason Mauss' Blog Cabin

Because someone's got to do the dirty work

Blog-Flair

Blogroll

Links

How would you store the information?

One of the new products I'm developing for my company is "NQuery", a SQL builder WinForms UserControl. It displays various schema information so the user can drag and drop tables, choose some fields, set some criteria values, etc. in order to have the SQL statement created for them. (btw, props to Scott for coming up with the name "NQuery" - I'll try to round up some swag for you, Scott.)

When the information needs to be saved, I need to store all of the relevant schema information, criteria, and visual display settings to a file.

My first (and only) thought so far has been XML. I could store the information like so:

<nquery version="0.1" release="Alpha">

   <sqlstatement type="select">

      <select distinct="false" top="0" percent="100">

         <selectitems>

            <selectitem>

               <alias></alias>

               <expression></expression>

               <field></field>

            </selectitem>

         </selectitems>

         <from>

            <tables>

               <table>

                  <owner>dbo</owner>

                  <name>Orders</name>

               </table>

            </tables>

         </from>

      </select>

      <update>

         <table>

            <owner>dbo</owner>

            <name>Orders</name>

         </table>

         <setvaluefields>

            <field name="orderdate" value="10/15/2004" />

         </setvaluefields>

         <criteriafields>

            <field name="orderid" value="100" />

         </criteriafields>

      </update>

      <delete>

         <table>

            <owner>dbo</owner>

            <name>Orders</name>

         </table>

         <criteriafields>

            <field name="orderid" value="100" />

         </criteriafields>

      </delete>

      <insert type="into">

      <into>

         <table>

            <owner>dbo</owner>

            <name>Orders</name>

         </table>

         <fields>

            <field name="customerid" value="10" />

            <field name="employeeid" value="5" />

            <field name="orderdate" value="10/15/2004" />

         </fields>

         </into>

         <from>

         </from>

      </insert>

   </sqlstatement>

   <options>

      <displayownername value="false" />

   </options>

   <displaysettings>

   </displaysettings>

</nquery>

(This XML snippet encompasses all possible SQL types (Sel/Ins/Upd/Del) and is not entirely complete but you get the idea...)

Can anyone think of a better way to store this type of information? My concerns are

  1. Parsing the whole tree to populate the object model seems like it could be costly performance-wise
  2. There might be a better format to express this in other than XML
  3. There might be a simpler way I just haven't thought of

If anyone has any thoughts and/or ideas they'd like to share - please - feel free in the comments or through the contact link or email me at jason dot mauss at gmail dot com.

Comments

Dean Harding said:

Are you using .NET? Why not just use binary serialization? It's quick, it's easy, and you don't have to write any additional code! Versioning is more difficult, though not impossible (and even easier come .NET 2.0 with the "versioning tolerant" formatter).
# November 30, 2004 1:00 AM

Dean Harding said:

Heh, obviously you are using .NET, since it's going to be a WinForms user control :-)
# November 30, 2004 1:01 AM

chornbe said:

I like Dean's suggestion for two reasons:

1. speed - it's fast, it's light
2. ease - it's done and working fine in .NET since birth.

The reasons I don't like it are few, but in my opinion, worth weighing heavily. They may not factor into your design, so this could be a solution for you.

1. At some point you *will* need/want to tweak the persisted data for problem resolution, non-compile tweak, spec-change, etc. Can't do that in bin-persists

2. It couples the output tightly to .NET-only implementations. There *might* be a point where you want to trade that information with java, python or (goodness forbid) Perl systems and you'll end up doing something else anyway.

3. With XML and its human-readable format, you have built-in ability to debug issues at the data-persistence level.
# December 11, 2004 4:02 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)