Click here to Skip to main content
15,880,364 members
Articles / Programming Languages / SQL

SQL Editor for Database Developers

Rate me:
Please Sign up or sign in to vote.
4.55/5 (65 votes)
10 Mar 2010GPL317 min read 250.1K   9K   236  
SQL editor with syntax parser, direct editing, code execution, database backup, table comparison, script generation, time measurement
/*
SqlBuilder - an intelligent database tool
 
This file is part of SqlBuilder.
www.netcult.ch/elmue

This program is free software; you can redistribute it and/or modify it 
under the terms of the GNU General Public License as published by the 
Free Software Foundation; either version 2 of the License, or 
(at your option) any later version. 
 
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
GNU General Public License for more details. 
 
You find the GNU General Public License in the subfolder GNU
if not, write to the Free Software Foundation, 
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/


using System;
using System.Drawing;
using System.Collections;

namespace SqlBuilder
{
	/// <summary>
	/// Default settings for your company
	/// </summary>
	public class Defaults
	{
		public const string Version = "4.3";

		// Write Debug output from the specified source (e.g. typeof(Parser))
		public static Type  DebugType = null;

		public const bool   TrustedConnection = false;
		public const string Server            = "Sql Server";
		public const string User              = "sa";
		public const string Password          = "sa";

		// the default databases to be checked for Database Backup and Search
		// The databases must be separated by pipe: e.g. "Base1|Base2|Base3"
		public const string DbaseList = "PROD";

		// timeout for SQL commands (seconds)
		public const int    Timeout   = 120; 

		// Display of DateTime
		public const string TimeFormat = "dd.MM.yyyy hh:mm";
		public const string DateFormat = "dd.MM.yyyy";
		// Display of DBNull
		public const string NullText   = "[NULL]";

		// When exporting a table to HTML repeat the header every n-rows (-1 for no repeat)
		public const int    HtmlHeaderRepeat = 25;

		// Defaults when adding new sysobjects
		public const string CreateFunc = "CREATE FUNCTION {0} (@Param as int)\r\nRETURNS int\r\nAS\r\nBEGIN\r\nRETURN 0\r\nEND\r\n";
		public const string CreateProc = "CREATE PROCEDURE {0} AS\r\nSELECT * from Table\r\n";
		public const string CreateView = "CREATE VIEW {0}\r\nAS\r\nSELECT * from Table\r\n";
		public const string CreateTrig = "CREATE TRIGGER {0} ON Table\r\nFOR UPDATE,INSERT\r\nAS\r\n";

		// Folder where deleted SysObjects are temporarily saved and then moved to recycle bin
		public const string DelSysObj  = "DeletedSysObjects\\";
		// Folders to be created inside the working directory
		public const string ScriptDir  = "Scripts\\";
		public const string BackupDir  = "DatabaseBackup\\";

		// The files which are generated in the Script directory
		public const string XmlSettings    = "SqlBuilder.xml";
		public const string CompoundScript = "CompoundScript.sql";

		// The files which are generated in the Backup directory
		public const string XmlBackup      = "Backup.xml";

		// URL where to download the latest version in the format "4.1" from a text file
		public const string UpdateUrl      = "http://netcult.ch/elmue/UpdateSqlBuilder.txt";
		public const string DownloadUrl    = "http://electronix.ch/ptbsync/SqlBuilder.zip";
		// Check for new versions on the server every X days
		public const int    UpdateInterval = 1;

		// This string is used to encrypt the password
		public const string EncryptionKey = "1GsM�A.-U*'du7s$B6(d3#Plke6&?0H@j7kSq!:Y=Fua";

		/// <summary>
		/// Colors in DataGrid in frmDataGrid
		/// </summary>
		public static Color GridColor(Type t_DataType)
		{
			if (t_DataType == typeof(DBNull))
				return Color.DimGray;

			if (t_DataType == typeof(Byte)   || 
				t_DataType == typeof(Int16)  || 
				t_DataType == typeof(Int32)  || 
				t_DataType == typeof(Int64)  || 
				t_DataType == typeof(double) || 
				t_DataType == typeof(decimal))
				return Color.DarkGreen;

			if (t_DataType == typeof(DateTime))
				return Color.DarkBlue;

			if (t_DataType == typeof(string))
				return Color.DarkRed;

			return Color.Black;
		}

		#region Parser

		// syntax highlighting of user defined datatypes
		// you can remove the following if you dont need it
		public const string UserDataTypes = " nBinario nBoolean nDate nDecimal nFloat nGUID nLong nPrecio nStringBig nStringLong nStringMax nStringMid nStringShort nTexto ";

		// RtfHtmlBuilder
		public const int IndentPlain =   4; // spaces to indent plain SQL text
		public const int IndentHtml  =  20; // pixel to indent HTML code
		public const int IndentRtf   = 300; // millipoint to indent RTF code

		public static Hashtable DefineParserColors()
		{
			Hashtable i_Colors = new Hashtable();

			i_Colors.Add(Parser.eType.Comand,    Color.Blue);
			i_Colors.Add(Parser.eType.Keyword,   Color.BlueViolet);
			i_Colors.Add(Parser.eType.Function,  Color.Red);
			i_Colors.Add(Parser.eType.Operator,  Color.Red);
			i_Colors.Add(Parser.eType.DataType,  Color.DodgerBlue);
			i_Colors.Add(Parser.eType.String,    Color.DarkRed);
			i_Colors.Add(Parser.eType.CommentL,  Color.DarkCyan);
			i_Colors.Add(Parser.eType.CommentP,  Color.DarkCyan);
			i_Colors.Add(Parser.eType.Number,    Color.DarkGreen);

			return i_Colors;
		}

		/// <summary>
		/// return false to remove useless line comments
		/// you can remove the following if you dont need it
		/// </summary>
		public static bool CheckLineComment(string s_Text)
		{
			string s_TEXT = s_Text.Substring(2).ToUpper().Trim(); // cut "--"

			// Kill the most stupid comments like "--NAS 23_12_04", "--****BY RBO 03/12/04", "-- GAVEDANO 08.07.2005"
			while (s_TEXT.StartsWith("*") || s_TEXT.StartsWith("-"))
			       s_TEXT = s_TEXT.Substring(1);

			s_TEXT = s_TEXT.Trim();

			if (s_TEXT.StartsWith("BY "))
				s_TEXT = s_TEXT.Substring(3).Trim();

			string[] s_Parts = s_TEXT.Split(' ');
			if (s_Parts.Length == 2 && s_Parts[0].Length < 13 && (s_Parts[1].Length == 8 || s_Parts[1].Length == 10))
			{
				if ((s_Parts[1][2] == '_' && s_Parts[1][5] == '_') ||
					(s_Parts[1][2] == '/' && s_Parts[1][5] == '/') ||
					(s_Parts[1][2] == '.' && s_Parts[1][5] == '.') ||
					(s_Parts[1][2] == '-' && s_Parts[1][5] == '-'))
						return false;
			}

			// Remove useless comments like --FIN ROLEA 18.08.2005
			if (s_TEXT.StartsWith("INICIO ")    || 
				s_TEXT.StartsWith("FIN ")       || 
				s_TEXT.StartsWith("END ")       || 
				s_TEXT.EndsWith(" (COMENTADO)") ||
				s_TEXT.EndsWith(" INICIO")      ||
				s_TEXT.EndsWith(" FIN"))
					return false;

			return true;
		}

		#endregion
	}
}

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 GNU General Public License (GPLv3)


Written By
Software Developer (Senior) ElmüSoft
Chile Chile
Software Engineer since 40 years.

Comments and Discussions