Pending Release of Mini SQL Query

by Paul 5/14/2007 1:38:15 PM

NOTE - Mini SQL Query has been released now - see http://www.pksoftware.net/blog/2008/02/01/Beta+Release+Of+Mini+SQL+Query.aspx.

 

This is not a product release, but a notice of release (!) for my latest pet project, "Mini SQL Query".

What is Mini SQL Query?...

"Mini SQL Query from PK Software is a minimalist SQL query tool for multiple providers (MSSQL, Oracle, OLEDB, MS Access files etc). The goal of the Mini SQL Query tool is to allow a developer or trouble-shooter to quickly diagnose issues or make changes to a database using a tool with a small footprint, that is fast, expandable and easy to use."
Some Features:
  • Multiple database type connections (e.g. MSSQL, Oracle, Access etc)
  • Syntax Highlighting
  • Object Inspector (Browse the tables, columns etc for the connection)
  • Easy to utilize Plug-In system that has access to all the applications internals
Sample Screenshot - The Mini SQL Query tool in use against the Northwind Sample DB:



I call it "mini" because I wanted to keep it simple and fast. I uses a straight forward but powerful plugin architecture that makes adding menu or toolbar options as simple as adding a reference in a DLL project and implementing a few functions from the IPlugIn interface. I will be pushing out a few posts about the service and command style of coding soon due to its implicit focus on issues such as dependency injection (DIP) and (dare I say it) service-oriented architecture (and no I am not talking about web services!) These techniques in turn improve code quality, testing and in turn maintenance (and again in turn our sanity as programmers...)

I will publish a core product and then make other plugins available for download.

Plugin Example 1...

Here is a simple example - display connection...



Below is the example C# plugin code that displays the current connection string in the editor window.

namespace MiniSqlQuery.Plugin.Example
{
    /// <summary>
    /// This example command inserts the current connection string details into the editor text.
    /// </summary>
    public class DisplayConnectionCommand : CommandBase
    {
        public DisplayConnectionCommand(IServiceContainer services)
            : base(services, "Display Connection Example")
        {
        }
        public override void Execute()
        {
            IEditor editorService = this.ServiceManager.CurrentEditor;
            editorService.Query = string.Format(
                "-- Connection: {0}\r\n\r\n{1}",
                this.ServiceManager.DatabaseConfigurationManager.ConnectionString,
                editorService.Query);
        }
    }
}

Running the menu command:



Simple I know but I wanted to show the command execution approach using services.

Plugin Example 2...

OK - not that exciting! Here is another example where a business object is generated from the result set...

Public Class MakeBusinessObjectFromResultsCommand
    Inherits CommandBase

    Sub New(ByVal services As IServiceContainer)
        MyBase.New(services, "Make BO from Results")
    End Sub

    Public Overrides Sub Execute()
        Dim editor As IEditor = Me.ServiceManager.CurrentEditor

        If Not editor.Result Is Nothing AndAlso _
         editor.Result.Tables.Count > 0 Then
            ' create some simple code gen using the results
            editor.Messages = GenerateClass(editor.Result.Tables(0))
        Else
            editor.Messages = "No results to generate code from."
        End If

    End Sub

    ''' <summary>
    ''' Given a DataTable (<paramref name="dt"/>), a basic VB.NET class is generated.
    ''' </summary>
    ''' <param name="dt">A DataTabel to generate a class from.</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GenerateClass(ByVal dt As DataTable) As String
        Dim code As New Text.StringBuilder()
        Dim fieldName As String
        Dim typeName As String

        code.AppendFormat("Public Class {0}{1}", dt.TableName, vbCrLf)
        code.AppendLine()
        code.AppendFormat(" Public Sub New{0}", vbCrLf)
        code.AppendFormat(" End Sub{0}", vbCrLf)
        code.AppendLine()
        For Each column As DataColumn In dt.Columns
            fieldName = "_" + column.ColumnName
            typeName = column.DataType.FullName
            code.AppendFormat(" Private {0} As {1}{2}", fieldName, column.DataType.FullName, vbCrLf)
            code.AppendLine()
            code.AppendFormat(" Public Property {0}() As {1}{2}", column.ColumnName, typeName, vbCrLf)
            code.AppendFormat(" Get{0}", vbCrLf)
            code.AppendFormat(" Return {0}{1}", fieldName, vbCrLf)
            code.AppendFormat(" End Get{0}", vbCrLf)
            code.AppendFormat(" Set(ByVal value As {0}){1}", typeName, vbCrLf)
            code.AppendFormat(" {0} = value{1}", fieldName, vbCrLf)
            code.AppendFormat(" End Set{0}", vbCrLf)
            code.AppendFormat(" End Property{0}", vbCrLf)
            code.AppendLine()
        Next

        code.AppendFormat("End Class")

        Return code.ToString()
    End Function

End Class


Running this command against the "select * from customers" query produces the following:

Public Class Table

    Public Sub New()
    End Sub

    Private _CustomerID As System.String

    Public Property CustomerID() As System.String
        Get
            Return _CustomerID
        End Get
        Set(ByVal value As System.String)
            _CustomerID = value
        End Set
    End Property

    Private _CompanyName As System.String

    Public Property CompanyName() As System.String
        Get
            Return _CompanyName
        End Get
        Set(ByVal value As System.String)
            _CompanyName = value
        End Set
    End Property

    Private _ContactName As System.String

    Public Property ContactName() As System.String
        Get
            Return _ContactName
        End Get
        Set(ByVal value As System.String)
            _ContactName = value
        End Set
    End Property

    Private _ContactTitle As System.String

    Public Property ContactTitle() As System.String
        Get
            Return _ContactTitle
        End Get
        Set(ByVal value As System.String)
            _ContactTitle = value
        End Set
    End Property

    Private _Address As System.String

    Public Property Address() As System.String
        Get
            Return _Address
        End Get
        Set(ByVal value As System.String)
            _Address = value
        End Set
    End Property

    Private _City As System.String

    Public Property City() As System.String
        Get
            Return _City
        End Get
        Set(ByVal value As System.String)
            _City = value
        End Set
    End Property

    Private _Region As System.String

    Public Property Region() As System.String
        Get
            Return _Region
        End Get
        Set(ByVal value As System.String)
            _Region = value
        End Set
    End Property

    Private _PostalCode As System.String

    Public Property PostalCode() As System.String
        Get
            Return _PostalCode
        End Get
        Set(ByVal value As System.String)
            _PostalCode = value
        End Set
    End Property

    Private _Country As System.String

    Public Property Country() As System.String
        Get
            Return _Country
        End Get
        Set(ByVal value As System.String)
            _Country = value
        End Set
    End Property

    Private _Phone As System.String

    Public Property Phone() As System.String
        Get
            Return _Phone
        End Get
        Set(ByVal value As System.String)
            _Phone = value
        End Set
    End Property

    Private _Fax As System.String

    Public Property Fax() As System.String
        Get
            Return _Fax
        End Get
        Set(ByVal value As System.String)
            _Fax = value
        End Set
    End Property

End Class


Motivation

My main motivation was the lack of speed I experience (no matter how fast my dev box) in using the "default" tools for SQL development. No way of customizing things easily further frustrated me. With a tool such as Mini SQL Query I can quickly add extras as I need them. For example, one plugin I plan of adding is focused on Access databases, I want to be able to write a query in an editor and push the .Net code to execute that query straight into my development project.

I will but publishing a first cut within the next couple of weeks and from there get some feedback etc.

Related posts

Comments are closed

Powered by BlogEngine.NET 1.3.1.0
Theme by Mads Kristensen

About the author

Paul Kohler Paul Kohler
A .NET software developer living and working in Brisbane, Australia.

PK Software
E-mail me Send mail

Calendar

<<  August 2008  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008