Creating database structure to support countries and their states

•January 5, 2009 • Leave a Comment

As part of the project I am working on right now I need to implement a database structure to maintain countries with their corresponding states. I found a few websites/blogs that helped a little, but nothing really suited my needs, although the country and states/provinces codes are based on the ISO format: http://www.maxmind.com/app/iso3166. I though posting on this as it might help someone else out there!

After creating your database, open a new query window in SQL Server Management Studio and create a table for the countries…

USE YOUR_DATABASE_NAME; GO
CREATE TABLE Countries(
CountryID            INT             NOT NULL IDENTITY (1,1),
CountryName            VARCHAR(256) NOT NULL,
CountryCode            VARCHAR(256) NULL,
CountryDescription    VARCHAR(256) NULL
CONSTRAINT CountryPK PRIMARY KEY (CountryID));
GO


then a second table containing the states.

CREATE TABLE Country_States(
StateID                INT             NOT NULL IDENTITY (1,1),
CountryID            INT             NOT NULL,
StateName            VARCHAR(256) NOT NULL,
StateCode            VARCHAR(256) NULL,
StateDescription    VARCHAR(256) NULL
CONSTRAINT StatePK PRIMARY KEY (StateID),
CONSTRAINT Country_StatesCountryFK FOREIGN KEY (CountryID) REFERENCES Countries (CountryID));
GO

Once the tables are created, stored procedures are used to fill in the tables. I left the country description blank.

Populate Countries Script

Then populate the country_states table…

Populate Country_States Script

There are some drawbacks with this structure.; There can be states in different countries having the same state code. For example, WA stands for Washington state in the US but is also used to denote WesternAustralia state in Australia. When building your application or importing data from that needs to compare the statecode, make to consider the country in which the state is or simply change the state code.

SQL injection + IIS logfiles parsing

•August 12, 2008 • 1 Comment

During the past 2 weeks, we’ve been hacked at work. SQL injection was the method used and it gave us a little headache at the beginning, but I’ve written a script removing the extra string added in every fields of affected tables. Luckily, it affected only one database on the server. We are now in the process of modifying the code in out pages and there’s heaps to do! Most of the websites are coded in Co ld Fusion few years ago (I am new in the company…), so it’s a pain in the bum, let me tell you…

In the process, I looked through the IIS logfiles using logparser (see at the end for the link) to track down any unusual activities on the website. Log parser is amazingly useful to analyze IIS logfiles.

Once you’ve downloaded and installed logparser 2.2, you can analyze any logfiles generated by IIS.

  1. In IIS, right-click on the website you wish to analyze the logfiles
  2. A new window opens; in the ‘Enable Logging’ section, click Properties
  3. Go in the directory shown at the bottom of this window and copy the logfiles you want into logparser root directory (Usually C:\Program Files\Log Parser 2.2)
  4. Execute logparser; a command prompt window will open
  5. It’s time to run queries to analyze the log files!

Log parser commands are just like SQL commands. This

logparser “SELECT DISTINCT date, cs-uri-stem, c-ip, Count(*), AS Hits, FROM ex*.log GROUP BY date, c-ip, cs-uri-stem HAVING Hits>50 ORDER BY date, c-ip, Hots DESC”

will give a list of the how many times an IP address has hit a file on one day. Only hits over 50 will be displayed.

IIS log files are structured by columns with headers. For example, columns c-ip represents the IP address. To know more on what field to display, just open a logfile into notepad and look the headers.

You can then lookup the IP doing a whois or tracert in the command prompt or just visit a website such as http://cqcounter.com/whois or http://whois.domaintools.com

Log Parser 2.2

http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en

SiteFinity CMS – First impressions

•August 11, 2008 • Leave a Comment

The company I am working for hosts many websites in which information displayed needs to be updated from time to time. There is a Content Management System (CMS) behind it, but it is complete rubbish.

Last week, I started to work with SiteFinity (www.sitefinity.com) and built a starter website to explore the possibilities of using that CMS in the future. The platform used by this CMS is .NET 2.0 and uses master pages as templates, so it is possible to stick controls into the ContentPlaceHolder later on. I’ve worked with SiteFinity’s API for a couple hours today and I was able to represent an existing website in a couple of hours. It is very easy to create you own template(s) and theme(s) and import the whole thing in the CMS tool administration section. It worked like a charm. I am using the community version (free) and I could do everything I wanted to do without any problems. I will be playing more with this tool in the upcoming weeks and will post along the way.

Karloo Pool Bush Walk

•August 10, 2008 • 2 Comments
Karloo Pool

Karloo Pool

Today, I woke up early and looked at the weather forecasts; fine, late afternoon showers or two. I decided to go for a bush walk in the southern suburbs as trackworks were underway in the northen suburbs. I bought the Syndey Morning Herald bush, park and city walks acouple weeks ago as it seemed to be well written. Karloo Pool through the Bottlebrush Forest looked nice, so I decided to go at 10h30ish.

I got the train to Heathcote station and followed the instructions in the book… It says to go over the tracks and make a right on Wilson Parade. There’s no indication to tell the name of the street I am walking on, so I keep going and going and going way passed 100 metres without any “supposed to be there” sign indicating the start of the track. After walking in circle for about an hour, 20 of which was raining, I saw a sign saying “Wilson Parade”, which is on the other side of the train track!!! The book I have is not very clear on exactly where to go when you get off the train and I lost an hour walking around like a moron. To anyone doing this walk, if your coming from the city, DO NOT cross over the train tracks, go right instead, heading to the fire station. This is Wilson Parade. If your coming from Waterfall, cross over the tracks. Make a right on Wilson Parade and you will see the sign making the start on the track.

The walk is great and not that difficult. The landscape is superb and Karloo pool is great! It’s winter time, so noboby was swimming having dip, though I can imagine that’ll be awesome in the summer. I’ve met 5 people

Karloo Pool

Karloo Pool

during my journey, only one person were sitting on the rocks where the pool were… After a couple of pictures around I made my way at the pond and he was gone, leaving me alone for the whole time I spent in this lovely area. I sat down a bit, took some pictures and can easily imagine myself swimming around there in summer! The walk back was good and I got back just on time ti catch the train back in the city! That was a sweet day…

Karloo Pool

Karloo Pool

Crow

Crow

Karloo Pool

Karloo Pool

Karloo Pool Bush Walk

Karloo Pool Bush Walk

Karloo Pool Bush Walk

Karloo Pool Bush Walk

Karloo Pool

Karloo Pool

Manny to get rid of his dreadlocks.. say what?

•August 9, 2008 • Leave a Comment
Manny Ramirez

Manny Ramirez

I am a massive baseball fan and I love watching Manny Ramirez, how he plays the game in such a relax fashion. I went on the MLB website and came across a headline saying that Manny has to get rid of his dreadlocks. What the hell is this??!! According to the LA Dodgers website, Joe Torre asked Manny to have an haircut and get rid of his dreadlocks… Harden up Joe and the Dodgers executives! They’re about to sell bandannas with dreadlocks attached to it which will sell like crazy! Furthermore, Manny’s dreadlocks are his trademark. Hopefully, Manny won’t show up without a hair on his head!

http://mlb.mlb.com/news/article.jsp?ymd=20080808&content_id=3276836&vkey=news_la&fext=.jsp&c_id=la

Welcome

•August 9, 2008 • Leave a Comment

Welcome to my official blog. There will be more coming up soon as I am setting it up. I will try to post as many as I can on my daily/weekly/monthly activities at work or over my freetime.

Please, feel free to post comments!

Pascal