Add a column if it doesn't exist to all tables?

Using MSSQL I needed to add a column to every table in a legacy database because I wanted to see whenever a new record was added. Needed a 'createdate' field that defaulted to getdate(), Instead of having to do each table one at a time I was able to find a query that did it all for me. Saved me a couple of hours. Thanks to Add a column if it doesn't exist to all tables?

Here is the code:

view plain print about
1EXEC sp_MSforeachtable '
2if not exists (select * from sys.columns
3 where object_id = object_id(''?'')
4 and name = ''CreatedOn'')
5begin
6 ALTER TABLE ? ADD CreatedOn datetime NOT NULL DEFAULT getdate();
7end';

Earning my money now cause I just shaved off a couple hours of billable time for my client.

Microsoft SQL Server

Bad Samsung 27" Monitor

We recently attended the NAHB International Home Builders show were we had a booth. For this booth we bought two Samsung 27" monitors. The monitors are beautiful and big.

Several times during the show, when we would first start up the computer the monitor would go blank. We were busy, so we didn't think much about. Unplugged, powered off, and it just seemed to work again.

After returning home I replaced my second monitor with one of those 2 monitors. Whenever the monitor would come on it would go blank after a variable amount of time. Sometimes it would go right off, others it would stay on for 15-20 or even 30 seconds. The only solution I found was to power it off and back on which was quick and easy with the power button on the front bottom right of the screen. But this drove me crazy because some days I would have to power cycle it more than 10 times. When this happens, the monitor appears to go off, but you can actually see very faint shadows of what was on your screen.

I updated the video drivers on my computer, did the monitor self test, and tried every solution I could find on google. I finally contacted samsung support and they had me try everything I had already tried and then asked if I had another computer to try it on. Since I had two monitors and couldn't remember for sure if I had ever had this one plugged into another computer I said I would try that and call them back.

First thing I did though, was hook up our other exact same monitor and it does not have the same problem. It works great which to me means the other monitor is defective. We bought it from cosco and will be exchanging it for the same thing (that hopefully works).

I do like the monitor, it is very crisp and bright and huge for a desktop monitor. If it works it is great.

Making it work with your busy spouse

Just read a great article written by the wife of a busy husband. My wife has always been very supportive of me and we are also knocking it out of the park with most of these suggestions. A great list:

A Post Startup Execs Should Forward to Your Spouse or Partner. 12 Tips for Making it Work

Smart Commit messages for Jira Issues in bitbucket

Just realized that you can process JIRA issues with commit messages. They call these 'smart commits'.

When we used unfuddle it was nice that we could make changes to the ticket with 'powerful commit messages'. We used SVN on unfuddle and could commit with a message like 'spent 2.5 hours on #345 resolved' or something to that affect and it would record the time spent and resolve the ticket. This was a feature that we missed when we moved to a GIT repo on bitbucket linked to our Jira instance. Well, it's finally here. The details can be found at Processing JIRA issues with commit messages

I had to enable 'smart commits' in the DVCS management section of Jira. More info in that same area at Enabling DVCS smart commits

We have not had a 'great' transition to GIT and my Developers have asked more than once to go back to SVN. GIT has a few quirks, but I don't mind it. And in the last few days I have taken a couple of tutorials and read through most of the Pro GIT Book and I am a convert. The more I learn the less I can imagine life without GIT. JIRA Even just announced the End of Life for SVN support inside their hosted JIRA.

It's gonna be GIT for me from now on.

Removing bluedragon from one iis7 website

I am working on a site that was using NewAtlanta bluedragon. I don't know that much about bluedragon but I simply wanted to create another site in IIS and NOT use bluedragon.

I set up the site, installed railo using this great document by Matt Woodward that explains railo and tomcat installation and it worked when testing with just a simple hello world example in index.cfm.

So I uploaded my little fw/1 app and it broke. I got the following error:

view plain print about
1Server Error in '/' Application.Object reference not set to an instance of an object.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
2
3Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
4
5Source Error:
6
7An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
8Stack Trace:
9
10[NullReferenceException: Object reference not set to an instance of an object.]
11 com.naryx.tagfusion.cfm.engine.cfComponentData.buildPolymorphList() +354
12 com.naryx.tagfusion.cfm.engine.cfSession.onRequestStart(cfFile requestFile) +311
13 NewAtlanta.BlueDragon.CfmModule.OnBeginRequest(Object sender, EventArgs e) +599
14 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +79
15 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +269

From that error message I could tell that bluedragon was still intercepting calls. I looked all over IIS and searched for everything. Posted to the railo group and the fw1 group and also posted to the New Atlanta support forums. Many people were very helpful.

After several weeks of trying to find a solution here and there I finally stumbled on to it. I had tried removing the newatlanta entries from 'Handler Mappings' in the IIS7 site that I was using. That didn't work. Finally, I removed the bluedragon reference in the 'Modules' section of the website I was trying to configure and that immediately fixed it. The attached image highlights the line that needed to be removed.

Resolving Conflicts in Egit

I like GIT. It really is cool, especially the related resources on sites such as github and bitbucket. But it also drives me absolutely crazy at times. One of those times is when I have a conflict to resolve. I never can figure it out and I have to have one of my Developers come in and explain/show it to me. This time I did it myself from this resource: http://wiki.eclipse.org/EGit/User_Guide#Resolving_a_merge_conflict. I still don't totally understand it but I wanted this in writing so next time I am that much closer to figuring it out all the way.

I use coldfusion builder in eclipse with eGit for my git repositories.

Parsing Phone number in Sql Server Removing non numeric characters

I inherited a system that has a few quirks. Great system but some of the stuff is hard to deal with. I was asked to make the phone number search work better. They are having a hard time with it cause you have to enter the phone number exactly like it is in the field. i.e. (444) 843-2234 and if you don't include everything it doesn't return any results. Not very convenient.

What we wanted was to be able to type any portion of that phone number, including just a few digits, i.e. 444843 and have the matching records come up. So I need to do two things. Remove any non numeric characters from the inputted value and search the database field which had non numeric characters.

The solution, and it seems to work, even though it feels totally hackish the following:

To clean up the inputted value I use:

view plain print about
1varphone = rereplace(form.phoneNumber,"[^[:digit:]]","","ALL")

To search the database with that value I used:

view plain print about
1WHERE SUBSTRING(phonenumber,2,3) + SUBSTRING(phonenumber,7,3) + SUBSTRING(phonenumber,11,4) like '%#varphone#%'

Now this assumes a consistent phone format like this '(444) 843-2234' which is the case in our database.

That saved a lot of reworking code and it works like a charm.

Resetting Wordpress password

I recently inherited an old WordPress site that nobody had used for over a year. So nobody could remember their username and password. I needed the admin password to be able to go in and make the adjustments that they had asked me to make. I have access to the database on the back end and all the files on the server via ftp so I started searching for solutions.

I found this page that seems to be the goto place for resetting a wordpress password. I needed to reset the admin one. All the info seems to be here: Resetting Your Password

I tried several of those inlcuding FTP and the Emergency Password Reset Script. This site is using Microsoft SQL Server so some of the others didn't apply. I had tried simply adding my own email to the admin user account in the database but that didn't work. I got a mail error.

Then, searching google, I found this page: Is it possible to calculate MD5 hash directly in T-SQL language?

The solution was found on that page where there is the following SQL statement:

view plain print about
1UPDATE T_WHATEVER_YOUR_TABLE_NAME_IS
2 SET PREFIX_Hash = LOWER(SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', LOWER('yournewpassword'))), 3, 32) )

This worked and created the password and I was able to login.

Missing Commit error using egit in coldfusion builder

I am using egit inside coldfusion builder which Is built on eclipse. We switched to Git a few months back and honestly it's not as easy as SVN was. We never had problems with SVN and my devs are almost begging to go back to SVN. Sometimes I want give in and go back (although I have several reasons I want to stay with git). Just now was one of those times. I was getting the following error:

view plain print about
1Exception caught during execution of merge command. org.eclipse.jgit.errors.MissingObjectException: Missing commit a1846c1a954c270a0f03fe7e9f5d1da5693e3469
2Exception caught during execution of merge command. org.eclipse.jgit.errors.MissingObjectException: Missing commit a1846c1a954c270a0f03fe7e9f5d1da5693e3469

Looking around on the internet I see this is a common occurrence, but one article I came across suggested just dropping into native git, which to me is git bash. I did that and ran 'git pull' and it worked. Frustration averted for now.

CFSCRIPT loop over a query and a big mistake

I have to look this one up every time. You can use cfscript to loop over a query by doing the following:

view plain print about
1for (var i=1; i <= qry.recordcount;i++) {
2                
3}
4
5OR
6
7for (var i=1; i <= qry.recordcount;i = i+1) {
8
9}

You notice a slight difference between the part that increments. The top one has an 'i++' the bottom has 'i+1'. I am pretty sure these do the same thing but later version sof coldfusion allowed you to use the double plus sign ++ to increment by 1.

I got stuck half way between and had i=i++. That put my loop into eternal running mode and I had to keep stopping the application to make the thing quit running. I am embarrassed how long this stumped me. So don't do that.

More Entries