Click here to Skip to main content
15,886,258 members
Articles / Database Development / SQL Server

SqlProcedure - Improve Database Performance, Eliminate Errors and Reduce Code

Rate me:
Please Sign up or sign in to vote.
4.66/5 (16 votes)
23 Nov 2007CPOL8 min read 74.6K   1.4K   66  
Provides a utility to generate a wrapper for stored procedures to improve performance and eliminate certain run-time errors
using System;
using System.Collections.Generic;
using System.Text;

namespace SqlProcedureWriter
{
    public class CommandLineParams
    {
        private string _username = string.Empty;
        private string _password = string.Empty;
        private string _servername = string.Empty;
        private string _database = string.Empty;
        private bool _isWin;
        private string _filter = string.Empty;
        private string _folder = string.Empty;
        private string _using = string.Empty;
        private string _namespace = string.Empty;

        //-f="c:\tmp\wrappers" -n=carl.exe -u="one;two" -s=(local) -d="dbwrapper" -i 

        public CommandLineParams(string[] args)
        {
            foreach (string s in args)
            {
                ArgValue v = GetParam(s);
                switch (v.Arg)
                {
                    case "i":
                        _isWin = true;
                        break;
                    case "folder":
                    case "f":
                        _folder = v.Value;
                        break;
                    case "namespace":
                    case "n":
                        _namespace = v.Value;
                        break;
                    case "u":
                    case "using":
                        _using = v.Value;
                        break;
                    case "s":
                    case "server":
                        _servername = v.Value;
                        break;
                    case "d":
                    case "database":
                        _database = v.Value;
                        break;
                    case "user":
                        _username = v.Value;
                        break;
                    case "pass":
                        _password = v.Value;
                        break;
                    case "r":
                    case "regex":
                        _filter = v.Value;
                        break;
                }
            }
        }

        private ArgValue GetParam(string arg)
        {
            string s = arg.Remove(0, 1);
            if (s.Contains("="))
            {
                string [] bits = s.Split('=');
                return new ArgValue(bits[0], bits[1]);
            }
            else
                return new ArgValue(s, string.Empty);
        }

        public string Using
        {
            get { return _using; }
            set { _using = value; }
        }
        public string Namespace
        {
            get { return _namespace; }
            set { _namespace = value; }
        }
        public string Filter
        {
            get { return _filter; }
            set { _filter = value; }
        }
        public string Folder
        {
            get { return _folder; }
            set { _folder = value; }
        }
        public string Username
        {
            get { return _username; }
            set { _username = value; }
        }
        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }
        public string Servername
        {
            get { return _servername; }
            set { _servername = value; }
        }
        public string Database
        {
            get { return _database; }
            set { _database = value; }
        }
        public bool IsWindowsAuth
        {
            get { return _isWin; }
            set { _isWin = value; }
        }

        private struct ArgValue
        {
            public readonly string Arg ;
            public readonly string Value ;
            public ArgValue(string arg, string val)
            {
                Arg = arg;
                Value = val;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions