Formatting SQL

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
December 7th, 2006

Today I found a nice little Java tool to help format long SQL queries. It has many options on how the string will be formatted. It will also take sql input types such as:

  • SQL
  • DB2/UDB
  • Oracle
  • MSAccess
  • SQL Server
  • Sybase
  • MYSQL
  • PostgreSQL
  • Informix

It then can take this input SQL and format it into a different type such as:

  • SQL
  • Java StringBuffer
  • Java String
  • C# StringBuilder
  • PHP String
  • ASP StringBuilder
  • VB String
  • VB StringBuilder
  • Concatenated SQL
  • HTML Code

This tool really has a lot of options and is very handy when trying to read/edit a long SQL query.

format sql screenshot

Java to C# Comparison

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
November 22nd, 2006

The first high-level language that I learned was Java. Of course I shortly found that there was a need to know C# too. So, as I started  to learn C# I kept a list of the differences between C# and Java (as can m be seen below). 
 
Class
——–
    Java: class GMTTime extends Time implements ICloneable{…}
    C#: class GMTTime: Time, ICloneable{…}
Constructor
———–
    Java: GMTTime(){
              this(System.DateTime.Now);
          }
    C#:GMTTime():this(System.DateTime.Now){…}
       GMTTime(long millis): base(millis){…}//if base not specified default constructor
                                              //called

Java            =       C#
—————————
    Finalizer     =       destructors //spedifies code that will execute once an object is no
                                    //longer usable
    Package       =       namespace
    import        =       using
    StringBuffer  =       StringBuilder
   
    indexer: allows a class to be accessed as an array
    struct: lightweight class, value type instead of reference type (like class)

Method Inheritance
——————-
    class BaseClass{
        //virtual is required  to allow this method to be overridden by a sub class
        virtual long GetTime(){…}
    }

    class childClass: BaseClass {
        //override allows an object to be a base class (BaseClass) but will still use
        //this method
        override long GetTime(){…}
    }

    class childClass2: BaseClass {
        //new overwrites the method but uses the method of the class that the calling
        //object is.
        new long GetTme(){…}
    }

Java Final
———-
    class = sealed //can not be inherited
    method = no virtual
    variable = const or readonly

Accessibility
————-
    public = visible to all
    protected = only derived classes
    private = only withen given class
    internal = visible only to project/assembly/jar file
    protected internal = visible only to project/assembly/jar file and derived classes
    default = private

Getters/Setters
—————
    //new C# way…old way used getter and setter methods
    class Circle {
         private int radius;
         public int Radius {
              get {return radius;}
              set {radius = value;}
         }

         public int Area {
              get { return 3.14 * radius * radius; }
         }
    }

    class otherClass{
        Circle c = new Circle();
        c.Radius = 3;//Note: no need to call a setter method.
        int area = c.Area;//Note no need to call a getter method
    }

synchronous = responds immediately
asynchronous = responds when ready to.

How to do events in C#
—————————–
1. Manually Trigger Event
    //namespace level, also specifies signature for event/handling methods
    public delegate void MyEventHandler();
2. Create an Event (requires a delegate)
    public event MyEventHandler TriggerIt;//class level
3. Register the event handlers with the event
    obj.TriggerIt += new MyEventHandler(obj.method);
4. Manually Trigger Event
    obj.TriggerIt();

// Declare the delegate handler for the event:
public delegate void MyEventHandler();//determines signitures of handling methods.

class TestEvent{
    // Declare the event implemented by MyEventHandler.
    public event MyEventHandler TriggerIt;

    public void MyMethod1(){
        System.Console.WriteLine(“Hello!”);
    }
    public void MyMethod2(){
        System.Console.WriteLine(“Hello again!”);
    }
    public void MyMethod3(){
        System.Console.WriteLine(“Good-bye!”);
    }

    static void Main(){
        TestEvent myEvent = new TestEvent();

        // Subscribe to the event by associating the handlers with the events:
        myEvent.TriggerIt += new MyEventHandler(myEvent.MyMethod1);
        myEvent.TriggerIt += new MyEventHandler(myEvent.MyMethod2);
        myEvent.TriggerIt += new MyEventHandler(myEvent.MyMethod3);
        // Trigger the event:
        myEvent.TriggerIt();

       
        // Unsuscribe from the the event by removing the handler from the event:
        myEvent.TriggerIt -= new MyEventHandler(myEvent.MyMethod2);
        System.Console.WriteLine(“\”Hello again!\” unsubscribed from the event.”);
        // Trigger the new event:
        myEvent.TriggerIt();
    }
}

typeof, GetType, is
———————-
    Type s = typeof(String);
    Type s = “my String”.GetType();
    “my string” is String //returns true

Array
—–
    MyArray[column,row]
    int[] arr = new int[]{1,2,3);
    int[] arr = {1,2,3};
    foreach(int i in arr){
        Console.WriteLine(“Value is {0}”,i);
    }

Create file in DOS edit/copy con

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
November 21st, 2006

When working in DOS sometimes I have the need to quickly create a file. Normally I would type “edit test.txt” which would open test.txt if it exists or create it if it doesn’t exist. This works well if I need to edit an existing file or type a lot of data. Note: use the alt key to navigate the menu in “edit” 

SP32-20061121-123114

edit test.txt

If I just need a quick file with only a few lines of text there is another method to quickly create a file. By typing “copy con test.txt”. It will then give a blank line to start typing the text that belongs in the file. Each time enter is hit it starts a new line and you will not be able to go back to the previous line. When you are finished typing the text hit CTRL+Z and hit enter. It will then create the file.

copy con test.txt

Hardlinks in Windows (junctions)

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
November 15th, 2006

Hardlinks are something that I always thought were not supported in windows. Now with the NTFS file system hard links can be used.

In dos the fsutil command can be used to create a hardlink from a specific file. Using a command like the following:

fsutil hardlink create newFile.txt originalFile.txt

From what I can tell this does not support hardlinking a directory. In order to hardlink a directory you would have to purchase the windows 2000 resource kit and use the linkd program to do this.

Although, now there is another program created by Sysinternals/microsoft called junction which gives the functionality to hardlink a file or directory.

To top it off for everyone who likes gui programs there is a shell extension which also gives this ability which can be found here.

Force No Cache on a Webpage

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
November 6th, 2006

Sometimes it is usefull to force a web page to not be cached. One example where this could be used is on a form that takes credit card information. Once the user submits their data you may not want someone to be able to hit the back button and be able to view the users credit card information. Microsoft has an article explaining how to force the browser to not cache the page but when I tried their method it did not work. Instead with a little trial and error I came up with the following solution:

In ASP (vbscript):
<%
Response.AddHeader "Expires", "Mon, 21 Jul 1979 01:00:00 GMT"
Response.AddHeader "Cache-Control", "no-store, no-cache, must-revalidate" ' HTTP/1.1
Response.AddHeader "Cache-Control", "post-check=0, pre-check=0" ' HTTP/1.1
Response.AddHeader "Pragma", "no-cache" ' HTTP/1.0
%>

In PHP:
header("Expires: Mon, 21 Jul 1979 01:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false); // HTTP/1.1
header("Pragma: no-cache"); // HTTP/1.0

Character Encodings

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
November 1st, 2006

A text document can be saved with many different types of character encodings. The question is which one is correct? Is there a best encoding for web development or to use in the <meta http-equiv=“Content-Type”?

A great guide to understanding the different encodings can be found here.

Dos Prompt Modifications

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
October 26th, 2006

As I tend to use a dos a lot I decided it might be nice to modify the way dos looks. Below is the result of my modifications. I basically just changed the font color to green and made the working directory appear one line higher than normal.

Dos

Here are the steps if you would like to modify your dos prompt:

  1. To change the color of DOS go to /HKEY_CURRENT_USER/Software/Microsoft/Command Processory/ in your registry and modify the DefaultColor to be 0a
  2. To make the working directory appear one line higher, right click on “My Computer” go to “Properties” and then select the “advanced tab”. Now, click the “Environment Variables” button. Under “User variables” click the “new” button and put “PROMPT” (without the quotes) in the “variable name” text box and “$P$_$+$G” (without the quotes) in the “variable value” text box. This change will not take effect until the computer has been restarted.

ftp with 2 connections transfer from remote server to remote server

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
October 24th, 2006

Every so often I need the ability to transfer files directly from one server to another. Now this could be done by using a standard ftp program like filezilla and first copying it from a remote computer to the local computer and then again copying it back to another remote computer. Although, sometimes it is nice to go the more direct route and use a program that supports fxp which allows connecting to 2 remote servers and transfering directly from one to the other. Wikipedia has a nice list of programs that support this.

Time to switch to Internet Explorer 7

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
October 23rd, 2006

If your a web developer and you haven’t yet switched to internet explorer 7 (ie7) then now might be a good time. Microsoft has announced that they plan on distributing ie7 via automatic update by November 1st.

Since many computers are set to automatically update. It might be a good idea to start checking sites in ie7. So you can be prepared for sites that ie7 might break.

As people start transitioning to ie7 you may still want to test sites in ie6. This can be done by installing ie6 as a standalone application. The ie6 standalone version can be found here.

Below are a few css items that should not be used to hide the css from ie:

If you want to target IE or bypass IE, you can use conditional comments.

Portfolio

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
September 25th, 2006

For those that are looking for my portfolio I have moved it. It is now located at the following location (the link can also be found in the right navigation bar):  http://brett.batie.com/portfolio/