Posts

Inserting Into Sql Server Identity and Default Columns

For some reason I always try to insert default or null into Sql Server identity or default columns. So that I remember here is how to do it when not explicitly listing the columns list. When inserting into a table with an identity column, exclude the identity column from the values column list. e.g. Pretend the columns doesn't exist. When inserting into a table with a default column, use the DEFAULT keyword. DECLARE @Test TABLE( id INT IDENTITY(1,1), fname VARCHAR(30) not null, lname VARCHAR(30) not null, ts DATETIME DEFAULT GETDATE() ) INSERT INTO @Test VALUES('Joe', 'Somebody', DEFAULT) SELECT * FROM @Test GO Which results in: id fname lname ts --- ------ -------- ----------------------- 1 Joe Somebody 2011-01-30 12:37:20.353 (1 row(s) affected)

AutoItX4Java - Java AutoIt Bridge

AutoIt is a very useful automation scripting language for Microsoft Windows. It allows for GUI automation using a very simple syntax and can be useful for testing applications. It is packaged with AutoItX which supports accessing AutoIt functions through COM objects. I just created a new project on Google Code for Java AutoItX bindings. The project is called AutoItX4Java and uses the JACOB Java COM Bridge to access AutoItX functions. Currently the project is in an unstable state but hopefully as time goes on things will get better tested. Using AutoItX4Java is simple: Download JACOB . Download and install AutoIt . (or register the dll. See below) Add jacob.jar and autoitx4java.jar to your library path. Place the jacob-1.15-M4-x64.dll file in your library path. A simple example of using this library is below: File file = new File("lib", "jacob-1.15-M4-x64.dll"); //path to the jacob dll System.setProperty(LibraryLoader.JACOB_DLL_PATH, file...

Automated web testing with Java, Selenium RC, LoggingSelenium, HtmlUnit and TestNG

I used the  Selenium  web automation framework extensively for a suite of websites I had tested. Over the course of a year I had ended up with a complete automation framework for a suite of websites. This resulted in lots of project specific code. Now that I need to use Selenium for other sites I thought I would write about setting things up at a basic level which includes using HtmlUnit, Selenium, LoggingSelenium, starting the Selenium server through java and using TestNG. Getting Setup Download Selenium RC and Selenium IDE from http://seleniumhq.org/download/ . Selenium IDE will install right into Firefox as an add-on. I am using Selenium RC 1.0.3. Download LoggingSelenium from http://sourceforge.net/projects/loggingselenium/files/ Download TestNG from http://testng.org/doc/index.html Extract the files into your projects library folder and add the following 4 jars to your project: selenium-server.jar selenium-java-client-driver.jar logging-selenium-1.2.jar ...

The SQL Server and .Net equivalent of PHP and MySQL's SHA1 function

In PHP and MySql there is an sha1(str) function which generates an sha1 hash of a string. Their usages are simple: <?php echo sha1('password'); ?> //Outputs:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 mysql> select sha1('password'); +------------------------------------------+ | sha1('password') | +------------------------------------------+ | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 | +------------------------------------------+ 1 row in set (0.00 sec) Similarly, .Net has an SHA1 method within the System.Security.Cryptography  namespace which can be used in the following manner to generate the same hash. public static string Sha1(string hashStr, Encoding encoding) { var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider(); var hash = sha1.ComputeHash(encoding.GetBytes(hashStr)); return BitConverter.ToString(hash).Replace("-", ""); } Console.WriteLine(S...

Netbeans Native Linux GTK Look and Feel

Fedora updated my Netbeans install last night and I had to set the look and feel in the config file again. Since this happened a few times and I never remember the laf option I thought I would write it down. Especially since the default Netbeans look and feel seems very ugly to me. To change the laf to GTK add "--laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel" to the netbeans_default_options in the netbeans.conf file. The netbeans.conf file is located in /usr/share/netbeans in the etc subdirectory of the netbeans version you are running.

Using Windows Powershell To Find A String Within Files

The below will find searchstr in all files with the .txt file extension in the current directory and all sub-directories and place the results in c:\tmp.txt Select-String searchstr $(dir . -recurse | where {$_.extension -eq ".txt"}) | out-file c:\tmp.txt

Generating PHP Table Objects from MySql

I needed to generate some PHP table objects for a couple MySql tables so wrote up the query below real quick. I am sure there are better ways to do this through IDE's, tools, or PHP. There will also be some kinks that can be worked out such as turning database fields such as create_date into getCreateDate instead of getCreate_date but this did the trick for me. It will generate class members, getters and setters. SET @table = 'post'; SET @db = 'blog'; SELECT '<?php' UNION ALL SELECT CONCAT('class ', CONCAT( UCASE(SUBSTRING(@table,1,1)), SUBSTRING(@table,2)), '{') UNION ALL SELECT CONCAT('\tprotected $_', COLUMN_NAME, ';') FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = @table and table_schema = @db UNION ALL SELECT '\n' UNION ALL SELECT CONCAT('public function get', CONCAT(UCASE(SUBSTRING(COLUMN_...