Thursday, May 28, 2009
Laan SQL Formatter (alpha) is online!
code.laanfamily.com
Also, I will soon be releasing an NHibernate Appender which raps this functionality into a FormattedSqlFileAppender, once I get the appender subclassing working correctly.
Currently, the formatter (and even the parser, behind the scenes) is quite limited. It only supports SELECT statements, without UNION and SELECT..INTO modifiers. I believe there is full expression syntax parsing, but some aspects of expressions are still not formatted - e.g., bracketed sub expressions.
I will keep modifying it over time, as time permits (baby is now 6 weeks away!), but hopefully I can quickly implement INSERT, UPDATE and DELETE, CREATE TABLE and CREATE VIEW statements fairly rapidly. Then I'll work towards doing batched SQL instead of single statements, which will open the door for stored procedures.
Stay tuned!
P.S. Interested in the code? check it: http://code.google.com/p/sqlformat/
Wednesday, September 03, 2008
NHibernate SQL Logger
As a traditional SQL 'backend' developer, I've always relied on SQL Profiler to let me know what is happening in the back end at any given point, but now that I'm using NHibernate for our persistence layer, I've found that the SQL that is generated is not very readable. If you've used NHibernate you'll know what I mean!
Besides the aliased fields, I don't like the fact that the entire statement is packed onto one line, and is using the sp_exec statement for parameter passing - Not very readable.
In order to remedy this, I configured an appender within log4net that allows the SQL to be pushed to its own file, with the following config:
<logger name="NHibernate.SQL"><appender-ref ref="nh"/><level value="ALL" /></logger>
where "nh" is just a standard Log4Net file appender. This works, but still means I have to dissect the SQL and reformat it as I go.
Of course, this is not ideal, so I have decided to write a small log4net appender that formats this output. The only problem is that I will need to write an SQL formatter! Not trivial.
In the interim, I have written a rough 'formatter' which simply uses find and replace to get the SQL slightly readable. It places each field on its own line, and creates distinct blocks for each join.
SELECTFieldA,FieldB,FieldCFROM dbo.Table1 AS T1JOIN dbo.Table2 AS T2ON T1.Field1 = T2.Field1JOIN dbo.Table3 AS T3ON T2.Field2 = T3.Field2WHERE T3.Field4 = 1AND T2.FieldA <> 0
It’s not perfect, and will place new lines in regardless of whether they are necessary, but it does substitute parameters so generally it does the job!
If you happen to read this and think this sounds like something you *must* have, let me know.. It’s quite easy to use, simply reference the assembly, and place this into the log4net config:
<appender name="sqlFormatter" type="NHibernate.Appender.NHibernateAppender,NHibernate.Appender"><param name="FileName" value="C:\Logs\MatrixSQL.log"/></appender>
and then reference it accordingly within the NHibernate.SQL logging level:
<logger name="NHibernate.SQL"><appender-ref ref="sqlFormatter"/><level value="ALL" /></logger>
The next step will be to build a reasonable SQL parser, so that I can create a syntax tree of the statements in order to present them neatly.
To get this happening I will need a tokeniser (lexer), a grammar parser, and a formatter. Sounds like an interesting project. I’ll make this project available on GoogleCode at some point, assuming that I’m making progress.
Sunday, April 29, 2007
Chào ban! - Greetings from North Vietnam
Vietnam is so under-developed and filthy but fantastically cultural!! Life here is like nothing of what we're used to. Communication is really bad here - no one speaks English!! There are people hawking their wares of all sorts all over the streets... our money means so much to them. Amazingly, there are no beggars to be seen! Stray cats and dogs everywhere. No fast food chains. People eat on road side stalls and squat on little stools on the footpaths. Ladies in traditional Ao Dai (Vietnamese get ups) walking the streets with rice paddy cone shaped hats and carrying poles on their shoulders with baskets hanging off them storing fruit or snacks to sell, or balancing baskets of goods on top of their heads in the middle of the city. And the traffic!! Sheez -We have never seen so many motorbikes in all our life!! It's just like on telly! Hardly any traffic lights, no one obeys road rules, everyone drives on the wrong side of the road, playing chicken is standard play and the adrenelin pumps each time you attempt to cross the road! You'll definitely find the famous 25c bowls of noodles here, but they are Lin size, not Ben size! Meals at regular restaurants and cafes are about $1-2, beers are ridiculously cheap between 50c and $1. The only place in the world where cans of iced tea or coke are more expensive than beer. Alcohol in general is dirt cheap. Ben's drink of the trip is Long Island Iced Tea. At $5 a pop, you can just imagine...
Hanoi has such a French influence. The architecture is pretty and lots of French words everywhere. It was FREEZING!! No one told us we had to bring jackets!! It averaged 15-18 degrees during our stay! We had to buy parkas and beanies from the locals just to keep warm! I was chuffed at my $5 purchase that certainly did it's job at keeping me cozy! Ben's parka purchase was not so easy - try looking for a jacket to fit a 6'3" anglo built male in a country where the average male is my height and half Ben's build! Nevertheless, we managed to find a Nike rip-off for $25 (+pants) which was almost too warm for Ben's liking!
Hoi An is a gorgeous town stuck in old school. Roads in the old town are not bitumen and the shops are all like you see in an old Chinese movie - lots of wood and lanterns. We got lots of cool stuff tailored for really cheap - I got a long woolly duffle coat, and some beautiful traditional chinese silk brocade cheongsams and outfits made - The whole lot for under $100! I also took some dresses for them to copy and they did a fantastic job! Ben got 18 shirts, 3 pants and 3 pairs of shoes made (mind you, there ain't no way we were going to find size 13 shoes off the shelf for Mr Big Foot over here). We are very impressed by the workmanship of the tailors - much better than our Thai experience!! Only problem now with our limited wardrobe space, is that we're not sure where we're going to keep the clothes at home! Looks like we're going to have to buy a bigger house! Tomorrow we're off to My Son to check our the remains of the old Champa Kingdom
Everyone keeps asking us if we're married or here on our honeymoon! If I had a dollar for every time I was asked if I am Vietnamese, I'd be rich!! Apparently I look Vietnamese to the locals?? - or they're just trying to get me to buy something...
Saturday, April 28, 2007
Return to Malaysia
KL is just as we had remembered it from when we were last here 18 months ago – hot, humid, polluted and oh so chaotic. Staying at the KL Hilton, it was disappointing that we only once got time out from our hectic schedule to swim in the gorgeous lagoon style pool. Apart from the fact that we had no time, the weather wasn’t the greatest in KL during our stay – it was overcast, windy and rainy most of the time.
Breakfast at the KL Hilton is the best you could ever image. Of course, the staple western fare was always on offer, but in gourmet varieties – 2 separate egg stations to make your eggs any way you like – poached was the favourite on our table! There was not only regular pork bacon, but there was a newie for us – beef bacon! The boys weren’t fans, but I quite preferred it! There was a huge patisserie section (jam donuts were to become bf’s essential for every day of our trip); every cereal under the sun; fresh fruit platters with papaya, dragon fruit, guava and the sweetest pineapple in the world; a “dessert” station serving fresh waffles, pancakes and French toast with divine condiments to boot – brother couldn’t decide, so he divided his waffles into 4 sections with differing combos! The highlight for us was the international fare – roti canai, roti murtabak, pandan chicken, nasi lemak, just to name but a few. Also in contending top position was the fresh juice station where an attendant was waiting to juice up your favourite fresh juice concoction. We loved green apple and guava! And to help prevent and combat against potentially pooey bellies, a daily shot of yakult was on hand – even dairy nazi bf got in on the game! The only problem about the KL Hilton having such a great spread, was that we spent the rest of our holiday comparing every breakfast to the Hilton's! Truely the best breaky ever!
Day 2 – Road trip to Taiping. After breaky, we were met by our driver to be chauffeured in a comfy van for the 3 ½ hour journey north. All siblings were knocked out within the first ½ hour – we all get incredible motion sickness, so after a round of avomine, we were gone for all money. The mandatory stop an hour out of Taiping at the roadside eatery and jumbu stalls was quite an experience… As we piled into the car after a quick loo visit and snack grab, our driver was approached by about half a dozen suspect Malay and Indian rather gruff looking males. A mild argument ensued which started to make best friend rather uncomfortable and we all began to feel a bit nervous – perhaps we watch too much tv, but when you’re out in the middle of nowhere, and your driver is being harassed by local thugs, is not a pleasant sight nor situation to be in. After what seemed like an eternity, the driver jumped back in the car and we took off like the clappers. Seems the story goes that the thugs were repo men who troll the roads with a list of in arrears vehicles to look out for and attempt to sort out! Slight mix up with our vehicle as the repo men had mistook the registration number of our vehicle for another – Phew! - we didn’t at all fancy the
Day 4 – our last day in KL. We kicked off the day with some last minute shopping. Brother spent most of the day finalising his camera and best friend’s laptop purchase but not without bank dramas – HSBC “The world’s local bank”, gave no end of stress when they locked their account after multiple ATM transactions from attempting to withdrawal a bucket load of cash to pay for their purchases. HSBC can be applauded for their security measures, but boy did it put them through grief trying to unfreeze their account from overseas! The rest of us coupled off, spending the day shopping at Mid Valley. Bf was less than impressed, as shopping is most definitely not his favorite past time! We met with our cousin Julian for lunch - it had probably been 20 years since we'd seen him last! Laden with purchases, burning feet and aching bodies, we made our way back to the Hilton for our last supper in KL together – dinner at the Hilton’s Senses Restaurant where world renowned Chef Cheong Liew ran the pot (he also has the Grange Restaurant in the Hilton Adelaide). Our 5 course degustation menu was immensely enjoyed by all, with the most immpecable service you could ever imagine. Seriously, if I could grab all the service staff with me and fly them home, I would. Eloquently sufficed, we ended the night in our room swapping photos between us before we turned down for the night.
Morning brought on a weird and somber mood for all. We met early at breakfast with the harsh reality that our holiday together had finally come to an end, but more horribly, it was goodbye - brother and best friend were returning to London. Lucky for all, our goodbyes were short and sweet. We arrived at the airport all 6 of us, running behind schedule of course! Brother and best friend were the first to fly out, so they had to make their dash quickly. After tight hugs and kisses all round, they disappeared quickly, bolting through the terminal to catch their plane. My tears flooded like the River Nile and I sobbed all the way to our terminal. I’m not sure why – I’ll be seeing them in less than a year when they return for their wedding! I’m such a sook. What made me feel better was the comfort in bf’s arms, and knowing we were about to embark on an amazing journey – 3 weeks in Vietnam and Cambodia!
Thursday, February 01, 2007
DIY - Home Theatre PC (HTPC)
I recently built, configured and installed a PC into the lounge, to function as my entertainment hub. So many people have asked me what is involved in doing it themselves so I thought I'd write down what I learnt.

Hopefully this article will not be too technical, but it may be a difficult goal given the subject matter.
What is a HTPC?
If you've seen mine, then you already know - if not, the HTPC is a PC designed for the lounge, acting as the media hub of the house. It can record scheduled TV (Free-To-Air) whilst playing movies (or other recordings), listening to music or even while you're out. All interaction is via a remote control, much like using a DVD player. Other features include photo album viewing, checking the weather and watching downloaded movies (eg Torrents)
Get Your Facts Right
There is so much information on the web about the HTPC that you can't possibly start without reading as much as you possibly can about what to expect. Even with my 10 years within the IT industry (as a programmer, so not a techie) I still read article after article for 3 months in order to fully understand what would be required - and I still missed some things!
It was important for me to find good reliable reading material from an Australian perspective, so my first stop was to join (and remain) a member of xpmediacenter which has been extremely beneficial in every way. Before buying anything, get online, read and ask what others have used for various hardware concerns. Not doing this early enough cost me quite a bit!
Define Your Requirements
The most import requirement is budget. This will define the entire project and will ensure you are satisfied with the outcome. The other important requirements have to do with functionality, capacity, and aesthetics.
Personally, my requirement was to limit myself to AU$2500, able to display HD video and playback HD audio to provide total 'front end' capability to the 42" HD plasma TV and 5.1/DTS Sound System, and with the capacity to record and play TV concurrently.
If I'd known then what I know now, I'd say it's extremely important to consider heat (i.e. noise and ventilation) as well as the above 'features'. The sound of an overworked CPU fan will ruin the quiet scenes in any movie!
Be Prepared for Problems
You may never encounter any, but it is possible - If you are building the box, or even just configuring the software, you will inevitably have issues - mostly they will be simple, such as installing a driver or a codec, or they might be more complex and require some experimentation or even outside help. The best thing you can do is ensure that everything has been configured, and tested, prior to demonstrating to family and friends! I actually had mine in the study for over a month as I ironed out all the problems (it turned out that the original DVICo TV card was a dud!)
What You Will Need
The core hardware components that your HTPC will need are:
- TV Tuner card (Analog or Digital) - more likely you will want at least 2 - so you can record and watch two stations concurrently - the current version of MCE only allows 2 cards to be installed without resorting to registry hacks
- Quality Audio card (on board will do) - If you intent to play music, or watch DVDs via your AV Receiver system, you will want a coax / spdif capable sound card
- Graphics card with digital (or HD digital) output, or analogue output, depending on your TV - personally, I wouldn't touch analogue, since it is being phased out within the next few years. Also, 3D Gaming features are not required, and will probably cause problems due to heat so these types of cards should be avoided if possible. If you wish to route the video to yuor TV via the receiver, you will need to ensure that the AV catoers for the cable type that the TV supports - for this reason, I have implemented my solution using Component Video, even though the TV does support HDMI.
- Hard drive - get the largest, fastest, quietest one you can afford (get two!). This will be used a lot so don't skimp here. Recording HD TV will 'cost' 4Gb/hr, so you will need plenty if you plan on keeping all your favourite shows on the machine. I bought a 320Gb drive and have almost filled it up, only 3 months into operation.. If you have a lot of music, a second drive for music and AVIs might be a good idea, since MCE only allows one HDD to be indicated for storing TV recordings.
- Internet via Network card / Wireless card - Although not essential, not having the Internet on hand will severely handicap your system.. (Dial up is probably not going to cut it). If you wish to stream HD over wireless then you must get the latest 802.11g or 802.11n standard which supports high data transfer rates.
- AV Receiver style case - with LCD or VFD display (VFD is what Receivers generally use, as it is brighter but uses less power), and front USB, Firewire, etc ports for convenient access
- Remote Control device - the MS one comes with a keyboard as well..
- Wireless keyboard / mouse - you probably won't use them that much, but can be handy for surfing the net, or searching for a stored track or video! (You will need to consider where they will reside - mine is on the bottom shelf of the coffee table
- Silent / Quiet operation - generally, this will require either silent pipe technology, or passive cooling - this approach can be a bit risky if the air flow within and around the case is hampered, but you will thank yourself when this is all working right.
Putting the Bits in the Box
Although I have considerable experience with building PCs, I chose to use a hardware supplier to build and deliver the final product - I didn't have the time, nor did I want the issues that often arise due to hardware installation problems - still, this can be a rewarding part of the project, so it's a matter of choice.
Depending on who you use, they might even setup and configure Media Center for you.
Its Nothing Without Software
Although MS has just released Vista, I implemented my solution of Windows Media Center Edition (MCE), which is a hybrid of XP Home and Pro, with the Media Center functionality bundled in. The best feature of MCE is that all hardware you buy will be designed to 'Just Work' with it. It should be a breeze to get MCE to find and configure all the necessary bits and pieces. This was the case for me and others I've spoken to so far..
There are several alternatives to using Windows and MCE, which might be considered. You could choose a Windows based commercial package, or use the open source Media Portal, or you could go MS-free completely by choosing a Linux implemenation, such as MythTV. Although these solutions have lots going for them, I chose MS MCE since it is the most well known, and as such, most if not all hardware simply 'Just Works' with it.
There are a few things that you will need manual configure after MCE is installed:
- Electronic Program Guide - Although in the US this 'Just Works', in Australia, it's a different story. Apparently, due to legal problems with the TV stations here, the guide is not published.. You will need to install Blade Runnner Pro (BRP) and every week will need to run it (from MCE) and manually import the listings into MCE (from the TV Settings menu) - slightly annoying, but not the end of the world. BRP requires an account with a homebrew TV listings website called OzTivo (maintained by users!) to work, but this is easily configured.. You can even add to it if you like
- AnyDVD - Necessary to overcome the region restrictions technology that Media Center enforces. Not free, but I'm sure you can afford it!
- Codecs - every media format requires one, and unfortunately they don't all come with Windows, or MCE. Codecs are required for both encoding (burning, converting) and decoding (viewing) so they are essential. Different codecs provide different quality and performance, and so in general, shop around!
There are a few collections of decent codecs called K-Lite, or ffdshow (don't know about much about this one) to name a few that include most of the usual decoders you will require. In theory, if a file you wish to watch or listen to doesn't work, try it in Media Player (MP) since MCE uses this as it's display engine (if it works in MP, it should work in MCE). MP will notify you what the missing codec is or perhaps, if it's well known, it may even download it for you.
Video codecs for decoding the stream coming from the TV tuner will require a decoder that will probably come with your new DVD player (if not, you'll have to buy it) such as CyberDVD or PowerDVD or one supplied with your graphics card (ie from NVidia). - Some DVD Burning software - not sure which one is best.. This is still on my to do list. Such a feature should have come 'out of the box' with MCE, such that you can burn recorded TV to a DVD.. It appears that you require an MPEG-2 encoder such as one from Sonic (publisher: Roxio?) to do this.
- Noise - I still need to replace my fan that makes too much noise. It is not the constant whirling noise that one would expect however, I could probably get used to that - Instead, it is a constantly changing high (not piercing though) pitch that sounds like the fan is off-balanced. I am looking at a cooling tower (like the Noctua NH-U12F CPU Heatsink with 120mm fan)
- TV Recording archival - Burning to DVD and converting to MPEG4 (DivX, Xvid). I'm sure that it is quite possible to convert the TV recordings, however these features are not a part of the basic MCE install. I have looked at several alternatives, however at this stage nothing has stood out as being the perfect solution. A solution I will explore when time permits is MyTV ToGo, however I don't have any good information on it at this stage
- Scheduled recordings from Standby - I have nto yet worked out how to reliably start MCE from standby automatically (ie when a show that I want to see is on) without doing it myself. This solution would involve reliably starting and returning to standby in time to record any shows I would like.. I have found a free tool called MCE Standby Tool which might do the trick though.
From what I've read, it appears that MCE will start from standby correctly to start recording from the schedule, however in my case, it appears that either Windows or some drivers don't like restarting MCE after standby - I generally have to reboot after doing it as I have find that I have no valid TV tuner cards afterwards. Apparently MCE will fix this but I don't know yet.. - Finding out more about the Registry Hacks required in order to have more tuner cards. 2 more should do the trick!
- Vista - There are several early adopters of Vista (Premium and Ultimate include MCE) however I am yet to attempt it myself - when time permits I will create a new partition and have a play..
Some Further Reading
- Microsoft MCE page
- XPMediaCenter.com.au (AUS oriented)
- TheGreenButton.com (US oriented)
- www.dvbowners.com (Digital TV)
- www.avsforum.com (Audio Video related)
- Microsoft codecs FAQ
- General FAQ from AVSforum MCE2005 FAQ (very handy info here!)
- Setting up Blade Runner Pro with OzTivo
Products I recommend and use
- Silverstone LC16 case, with VFD
- iMon RF Remote (mine came bundled with the case)
- Gigabyte S775, GA-965P-DQ6 (on board 5.1DD/DTS)
- DNTV Live! Dual Hybrid PCI-E S2 TV Tuner card (I'll probably buy another soon)
- NVidia GeForce 6800GS (passively cooled)
If you're still reading this, you can see now that building and running a HTPC is not a casual affair - like most things to do with computers, and in particular with cutting edge technology, there is a lot to consider, and a lot to learn. Luckily there are a lot of knowledgeable people at the various forums who are willing and able to help out.
As you can see, I still have an outstanding list myself, but these features are not essential for my needs at this point. Hopefully I will solve these issue soon and will provide an update.
If you are still willing to undertake this project then I think you will be very happy with the final result. I know I am, and even my once-sceptical girlfriend is now a convert.
All the best.
Wednesday, December 14, 2005
Life: "Spikers" win the Monday Social 'A' Summer V-Ball Competition
Highlights of the game included being down throughout the whole game, but hanging on just enough to stay in touch, and finally getting back to even at around 30 a piece. After trading advantage point several times each (in OT), finally the Spikers were able to win the Grand Final with a deft touch by yours truly - A comfortable set by Big Al gave me the opportunity to get a good jump, and an easy purchase on a solid spike was on offer, but instead (somewhat cheekily) I placed the ball in the dead zone (centre court) with a casual flick of the wrist. The look on the opposition's faces said it all. Dirty.
Granted, it's not normally how you'd want to win a game, but, with pride and $100 drinks voucher at the local pub (The Winston, Pirie St) on offer, winning came first.
Congratulations to all the boys in team Drink Spikers (Paul, Tim, Al, and myself) - it was a good team effort, can't wait to crack the $100!!
P.S. Thanks also to our cheer squad (Lin and Donna) who watched the entire game - especially to Lin who dolled out the medallions (with complimentary kisses) to the lads and Tim for buying the beer!
Friday, November 25, 2005
Politics: Peak Oil makes it to Australian TV
Although they covered the topic in some detail, it was only a 15 minute segment on a channel that is rarely watched by the mainstream public. If only this type of journalism was being done on the big channels. Instead, 60 minutes is covering the latest human interest stories (Not that I mind, it just seems the world has more pressing stories to tell!).
The most compelling fact of this story was the hands-up poll conducted by an Australian Oil man at an Industry conference, who asked the assembly, how many think we've already reached the 'peak'.. 50% or so said yes.. Scary. You'd think those people would have an inside look..