Saturday, June 09, 2012
Thursday, April 02, 2009
New Blog Location
Bowing to capabilities such as source code list, I have relocated my blog to tangentlin.wordpress.com
Thursday, March 12, 2009
SQL Tip 1 - SELECT ALL OR by Something Query
Many times we would run into situation where user would want to select data limited by a criteria, or "all". For example, let's say we build a UI where user can list all the users by a certain State or all States.
Let's say the State information is specified by the parameter @State, which can be a validate two character state abbreviation, or 'ALL'
Most queries would be written as:
IF @State = 'ALL'
BEGIN
SELECT * FROM User
END
ELSE
BEGIN
SELECT * FROM User WHERE State = @State
END
So far so good, huh? Well, there are a few issues with this approach
- Poor code reusability. The first part of SQL is redudant in both conditional branches (SELECT * FROM User). This is fine when the queries are simple. I have seen some complex SQL queries that are miles long, this means developers would have to copy the complex select statement a few places.
- With there is only one condition, we only need one branch. However, what if we have a complex query condition, such as gender (Male, Female or All), department (certain department, or all), status (full-time, part-time, contractor or all), etc ... You can see the query can grow exponentially complicated. So in a case where customer requests an "Advanced Search" feature with 5 criteria, we can look at potentially 2 ^ 5 = 32 if branches for the SQL query.
There is a much simpler approach that would address the two problems above. It also improves the readability of your code as well.
Let's take the first sample (by state), and rewrite it as follow
SELECT * FROM User WHERE (@State = 'ALL' OR State = @State)
That's it! The @State = 'ALL' takes care of the 'All' situation! So, in a case where you want to take care other situations such as department, and status, your SQL query would look like
SELECT * FROM User WHERE (@State = 'ALL' OR State = @State)
AND (@Department = 'ALL' OR Department = @Department)
AND (@State = 'ALL' OR Status = @Status)
The number of AND/OR pairs is linearly equal to the number of criteria, not exponential!
Saturday, February 28, 2009
Flex 3.3 and Flash Player 10.0.22 coming?
Just notice a massive commit of Flex framework from its repository, along with a commit comment
"Merge 3.x revisions 5042,5072-5073,5090-5091 -> trunk
This includes the latest released player 10.0.22.87"
I also notice that the Flex 3 reference posted on Adobe's website is now "3.3" ... something new must be coming ...
Custom Effects MXML declaration gotcha
Creating composit effects such as Parallel and Sequence is easy in Adobe Flex, you can declare it and have children effects directly under it. For example:
...
The Adobe documentation indicates that the "children" attribute is optional. So the above declaration is essentially the same as:
...
However, if I declare a component that inherits from Sequence, I will have to explicitly declare child effects in the "children" tag. Or the effects would be treated as component declaration instead of child effects.
Friday, February 27, 2009
Clean Up your Vault versioned _sgbak directories
Source Gear Vault would create a hidden directory, _sgbak, in the directories it versions. Unlike _svn directories or _cvs directories which also uses it for configuration purpose, _sgbak is mostly serving what the name says (backup). For example, if you are in the event of reverting your file back to an earlier version but having no connection to the server, you can simply dig out the file from _sgbak, and manually revert it yourself.
That said, over time the _sgbak directory grows, making it difficult to copy from one environment to another. Unlike TortoiseSVN which supplies a tool to export the directory right from shell, in many cases I end up doing it by hand. But now, there is a quicker way, just create a batch file (.bat or .cmd with the following content, the code will recursively remove all the _sgbak directories from the place where you run the batch file.
@ECHO OFF
FOR /R %%f IN (_sgbak) DO IF EXIST "%%f" (
ATTRIB -h "%%f"
rd /s /q "%%f"
)
Migrating from Virtual PC to VMWare
After reading numerous posts (here) about the astounding performance achievement of VMWare, I have decided that VMWare Workstation 6.5 is worth the 2 Franklin's. My initial impression out of the box has been good so far. Not only the performance is impressive, but also tools such as defragging the virtual image is much more streamline than that on VPC.
VMWare also provided a tool to convert VPC or even an entire PC to a virtual machine. Yesterday I have decided to convert my 12GB VPC to VMWare. Well, while most seem to work as expected after the conversion, I have noticed a serious "mouse" issue rendering VMWare almost unusable. Here are a few gotcha's you need to be aware of:
- Uninstall VPC tools from VPC before the conversion, VPC's mouse driver is in direct conflict with VMWare. If you have forgotten to do so, the world has not ended yet, you can do so manually (see later in this blog)
- Shutdown the VPC instance as VMWare would not convert VPC that is in suspense mode. However, you can get around this by renaming the .VSV file though there could be some unknown consequence in certain scenario.
- Avoid installing VMWare's mouse driver. I am a little confused about this, but for now, it works.
- Windows XP would think a lot of hardware change has been made because the conversion essentially changes "VPC hardware" to "VMWare hardware." Therefore XP would ask for reactivation. Install VMWare tools prior to the activation so you don't have to activate it again after installing VMWare's drivers.
To manually disable VPC's mouse, you have to do this via keyboard as your mouse in VMWare is all screwy.
- Use Windows-R to bring up the Run dialog box, type in regedit
- Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Class\{4D36E96F-E325-11CE-BFC1-08002BE10318 using arrow keys.
- Once you have seen a list of value pairs on the right side containing a key named UpperFilters, hit the tab key, navigate to the item, an hit Enter at the entry
- In the popup window, you will see one or two lines of values, eliminate the line that reads msvmmouf. The tab to the OK button and hit ENTER.
- Reboot, and enjoy!
I take no credit for the above discovery, some genius has figured it out over here.
Thursday, February 19, 2009
UIComponent discovery: IFocusManagerContainer
Recently I have developed a few components that derived the base class of UIComponent instead of Container. In most cases, things went hunky dory. However, I start to realize that some components fail miserably. For example, if my component uses ButtonBar (such as ToggleButtonBar), any interaction with the ButtonBar inside that component would throw a Type #1003 error. Upon close inspection, it has to do with a null focusManager property assignment to ButtonBar.
After hours of tearing hair, I have decided to try my luck by reading the UIComponent implementation. I have found that if the a UIComponent does not contain an interface of IFocusManagerContainer, its parent container would not pass in the focus manager.
Tuesday, January 13, 2009
Weird Bug in Flex Skins
I have torn my hair this after dealing with a strange bug in Flex skinning. When I created custom skins for the button, all of a sudden the skins would appear outside the boundry of the button. In addition to the fringe, when buttons are rolled over, sometimes the skin is partially drawn. I will detail this with screenshots later on.
Eventually, I went through and "break-apart" all of skin clips so that they don't contain any references of common movie clip, the problem goes away. The moral of the story I learn from it is that -- "Try to limit the use of movieclips/graphics referenced elsewhere." Otherwise, the dimesions of the skin would be unpredictible.
Subscribe to:
Posts (Atom)