Tuesday, April 10, 2007

Shameful

In the end, every great power is as great as its credibility, and the only consolation after these last two weeks is that Britain doesn't have much more left to lose.

Ouch. I tried to convince myself that the decision to allow the 15 to give interviews was part of a cunning strategy. Then I saw this post. I am utterly appalled.

Monday, April 09, 2007

Goodbye Magna Carta article in the Times about the ridiculous anti protest legislation brought in by this government. I was rather ashamed to read the following:

Twenty miles from London, along the Thames, you will find a field opposite an island in the river. The field contains a monument erected by the American Bar Association. In the field next to it there is a memorial garden to John F Kennedy commemorating his role in the civil rights movement. Why on earth, you may imagine, are there American monuments in fields by the Thames? There are no other monuments. There is nothing to commemorate anything British.

Perhaps an important figure in American history was born there? Nope. The site is far more important to the American people than that. On that unmarked island in 1215 something was written down that more than 500 years later became the fifth amendment of the American Bill of Rights. “No freeman shall be taken, imprisoned . . . or in any other way destroyed . . . except by the lawful judgment of his peers, or by the law of the land. To no one will we sell, to none will we deny or delay, right or justice.”

Contrast this with the way we seem to have taken it for granted and allowed our freedoms to be eroded. At least the guys mentioned in the article are doing something about it.

Tuesday, April 03, 2007

Your Personality Profile

You are elegant, withdrawn, and brilliant.
Your mind is a weapon, able to solve any puzzle.
You are also great at poking holes in arguments and common beliefs.

For you, comfort and calm are very important.
You tend to thrive on your own and shrug off most affection.
You prefer to protect your emotions and stay strong.

My first question on asktom

Yay! My first question has been answered on asktom.

Monday, March 26, 2007

A common requirement when importing data into a table is to log any errors which occur due to constraint violation. This often leads to people processing data in a Cursor FOR LOOP and doing one insert at a time so that they can catch and log the error:

BEGIN
FOR source_rec IN (SELECT * FROM all_objects a)
LOOP
BEGIN
INSERT INTO t1
(col1
,col2
,col3)
VALUES
(source_rec.owner
,source_rec.object_name
,source_rec.subobject_name);
EXCEPTION
WHEN OTHERS THEN
--log error using PLVISION
plvexc.recngo;
END;
END LOOP;
END;

Another option is to use the EXCEPTIONS INTO clause of ENABLE constraint:
DECLARE
l_exc_count INTEGER;
BEGIN
--Disable unique constraint
EXECUTE IMMEDIATE 'ALTER TABLE t1 DISABLE CONSTRAINT UNQ_CONST1';
--Copy data (inc duplicates) from source table
INSERT INTO t1 (SELECT * FROM t2);
--The EXCEPTIONS table can be created using $ORACLE_HOME/rdbms/admin/utlexcpt.sql.
EXECUTE IMMEDIATE 'ALTER TABLE t1 ENABLE CONSTRAINT UNQ_CONST1 EXCEPTIONS INTO EXCEPTIONS';
--If constraint is violated it will still be disabled at this point
SELECT COUNT(1) INTO l_exc_count FROM t3;
IF l_exc_count > 0
THEN
--Copy invalid rows to errors table
EXECUTE IMMEDIATE 'CREATE TABLE errors_tab as SELECT * FROM t1,exceptions e where t1.rowid=e.row_id';

DELETE FROM t1
WHERE ROWID IN (SELECT minrid
FROM (SELECT object_id
,MIN(e.row_id) minrid
FROM EXCEPTIONS e
,t_dups t
WHERE t.ROWID = e.row_id
GROUP BY object_id));
END IF;
END;

Cool new feature in Oracle 10gR2 is the LOG ERRORS clause

Comment at asktom had the following:

insert /*+ APPEND */ into t select * from t2
LOG ERRORS REJECT LIMIT UNLIMITED;

Further details here

Friday, March 16, 2007

Record Exists

Copied from some tips put together by Chris Rudd, ultimately sourced from Steven Feuerstein
/*
Note that the following shows three ways of checking if a record exists which have very similar response times, one way (implicit cursor) which is bad, and a fifth way
( select count(*) ) which is a VERY BAD THING and will result in broken fingers for anyone found using it!
*/
SET VERIFY OFF
@ssoo
DECLARE
/* Different approaches to answering "at least one?" */
CURSOR empcur
IS
SELECT employee_id
FROM employee_big WHERE department_id = &&secondparm;
v NUMBER;
b BOOLEAN;
BEGIN
plvtmr.set_factor (&&firstparm);
plvtmr.capture;
FOR i IN 1 .. &&firstparm
LOOP
BEGIN
SELECT employee_id INTO v FROM employee_big
WHERE department_id = &&secondparm;
b := TRUE;
EXCEPTION
WHEN NO_DATA_FOUND THEN b := FALSE;
WHEN TOO_MANY_ROWS THEN b := TRUE;
END;
END LOOP;
PLVtmr.show_elapsed ('Implicit');

plvtmr.capture;
FOR i IN 1 .. &&firstparm
LOOP
OPEN empcur;
FETCH empcur INTO v;
b := empcur%FOUND;
CLOSE empcur;
END LOOP;
PLVtmr.show_elapsed ('Explicit');

plvtmr.capture;
FOR i IN 1 .. &&firstparm
LOOP
SELECT COUNT(*) INTO v
FROM employee_big WHERE department_id = &&secondparm;
b := v > 0;
END LOOP;
PLVtmr.show_elapsed ('COUNT');

/* Ohio OUG Contributions.... */
plvtmr.capture;
FOR i IN 1 .. &&firstparm
LOOP
SELECT COUNT(1) INTO v
FROM employee_big WHERE department_id = &&secondparm
AND ROWNUM <> 0;
END LOOP;
PLVtmr.show_elapsed ('COUNT ROWNUM<2'); department_id =" &&secondparm);"> @atleastone 1000 20
Implicit Elapsed: .45 seconds. Factored: .00045 seconds.
Explicit Elapsed: .12 seconds. Factored: .00012 seconds.
COUNT Elapsed: 2.21 seconds. Factored: .00221 seconds.
COUNT ROWNUM<2> @atleastone 20000 20
Implicit Elapsed: 8.06 seconds. Factored: .0004 seconds.
Explicit Elapsed: 2.46 seconds. Factored: .00012 seconds.
COUNT Elapsed: 42.21 seconds. Factored: .00211 seconds.
COUNT ROWNUM<2 Elapsed: 2.42 seconds. Factored: .00012 seconds.
EXISTS Elapsed: 2.63 seconds. Factored: .00013 seconds.

* /

END;
/

Thursday, March 08, 2007

Ask Tom "Hierarchical query"

Ask Tom "Hierarchical query"

Nice bit in follow up comments about collapsing rows using analytics.

Tuesday, February 20, 2007

Mr Eugenides: Menteurs

I'm not sure why the mendacity of this government still causes me to burst a blood vessel every now and then but this is extraordinary:

Mr Eugenides: Menteurs

Tuesday, February 13, 2007

Bad science - Gillian McKieth gets fisked

Ben Goldacre has a great piece in today's Guardian where he comprehensively demolishes the scientific pretensions of Gillian McKeith, who presents You are what you eat on Channel 4.

"McKeith is a menace to the public understanding of science. She seems to misunderstand not nuances, but the most basic aspects of biology - things that a 14-year-old could put her straight on. She talks endlessly about chlorophyll, for example: how it's "high in oxygen" and will "oxygenate your blood" - but chlorophyll will only make oxygen in the presence of light. It's dark in your intestines, and even if you stuck a searchlight up your bum to prove a point, you probably wouldn't absorb much oxygen in there, because you don't have gills in your gut. In fact, neither do fish. In fact, forgive me, but I don't think you really want oxygen up there, because methane fart gas mixed with oxygen is a potentially explosive combination. Future generations will look back on this phenomenon with astonishment."

hat tip to Tom Coates and the poor little greek boy.

Wednesday, November 29, 2006

Tuesday, September 05, 2006

Stuff I find useful

Here is a list of some of the software I find useful:

Visual Studio 2005
Cygwin - Free unix style utilities such as grep, xwindows client etc.
SQL Developer - Free ide from Oracle. Extensible plug-in architecture.
Firefox - Much better browser than Internet Explorer. Configurable.
CruiseControl.Net Continuous integration tool
Enterprise Architect - UML tool
Textpad/UltraEdit32 - Text editors, UltraEdit has more features but textpad is more lightweight.
Refactor! - Refactoring addin for Visual Studio

FXCop Code analysis tool
NUnit - Unit testing tool for .Net
Quest Code Tester for Oracle(previously known as QUTE)
SharpDevelop 2.0 - Open Source IDE for .Net (C#,VB and Boo). It includes a tool for converting VB to C# and vice versa.
Oracle Developer Tools - Addin for Visual Studio

Tuesday, April 18, 2006

Troubleshooting automated builds with CruiseControl.Net, PVCS and MSBuild

Following on from our efforts to automate our build process, I have been experimenting with Continuous Integration using CruiseControl.Net. This integrates the various parts of the build process such as source control, build tools, testing tools etc. and can remove a lot of the grunt work from performing builds. The cool thing about it is that it can be set up to poll the source control system for modifications and trigger a build whenever one of the source files changes so you get early notice of when the build is broken.

The tool is fairly well documented using a wiki. As with many wikis though, some parts of the documentation receive more attention than others. This caused me a few problems as we are using an old version of PVCS for source control and the PVCS docs are a bit thin. I got it working after a bit of trial and error and subsequent browsing of other areas of the site for different source control providers gave some tips that appear to be common to all source providers, so a common section would have been useful.

Installation was fairly simple and I proceeded to set up a simple test project:

<sourcecontrol type="pvcs">
<!--client executable-->
<executable>X:\VM\Win32\Bin\pcli.exe</executable>
<!--PVCS Database-->
<project>S:\PVCS Databases</project>
<subproject>/LIBRARY/.Net/NullableDateTimePicker</subproject>
<workingDirectory >C:\development\LIBRARY\.Net\NullableDateTimePicker</workingDirectory>
<!--<recursive >true</recursive>-->
<autoGetSource >True</autoGetSource>
<labelOrPromotionName >shared_DEV</labelOrPromotionName>
</sourcecontrol>
This configuration did not work and I had to investigate a bit more how it works. What seems to happen is that CruiseControl issues a succession of pcli commands and use the output from each to build further batch files for use by the next command. On my system, these batch files were saved to my temp directory:
C:\Documents and Settings\myname\Local Settings\Temp

When the next command attempted to use the file as input, the directory name was not escaped so the embedded spaces caused it to fail. I worked around this by setting my TEMP and TMP environment variables to point to C:\agtemp\temp this allowed me to proceed to the next step.

Now that the pcli commands were succesfully running, I had to change a source file in order to trigger the build. When I did this, I noticed that the pcli command produced by CruiseControl only got changed files when I had assumed that it would get all files in the project. This does make sense as the structure in PVCS does not neccesarily map directly to the .Net project structure. You are supposed to already have all the source code available in your working directory before starting CruiseControl which then just gets subsequent modifications before performing the build. If you need to get all of it then you can do a get for a specific label or promotion group by adding a </labelorpromotionname> element whose value corresponds to your label or promotion group.

Finally, I wasn't getting any executables even though the build was reported as succesful. This was another mistaken assumption on my part as I thought that it would automatically call MSBuild for the project. I added an MSBuild task to the project and configured it to call my solution file which then resulted in a shiny new dll in the release folder.

Thursday, April 13, 2006

Automating builds with PVCS and MSBuild

We are currently using PVCS version 6.8 as the Source Code Control system on a large .Net project. The project consists of 30 Assemblies so the builds take quite a while. I have been trying to get automated builds working so that we can run them as an overnight job. The script turned out to be quite simple in the end but working out the right combination of options was a trial and error process. Here is the script we used in the end:

REM -aworkpath Path to place workfiles in. Overrides default workspace for project
REM -bpprojpath path to base project to use when resolving references, required when -a or -o specified
REM -prDBpath to PVCS database
REM -z recursive flag, operate on specified project and all sub-projects
REM -gPromotionGroup get files with specified promotion group or higher
REM entity project to operate on

x:\vm\win32\bin\pcli get -bp"/Billing/Source" -gGBDEV -pr"X:\VM\vmdevint" -aH:\gettest -z "/Billing/Source"
REM cd to workpath
cd H:\gettest
REM
REM C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\msbuild /logger:EmailLogger,"C:\EmailLogger\bin\Release\EmailLogger.dll";To=buildmanager@tempuri.org;From=buildmanager@tempuri.org;Subject=BuildLog:%DATE%;Host=mail.tempuri.org Billing.sln
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\msbuild Billing.sln

The commented out call to msbuild includes a call to a custom logger that will email the results of the build. The source code for the logger was obtained from this blog

Friday, March 31, 2006

Photos

I've been playing with a number of different sites recently to store my digital photos and order prints. One of the nicest for sharing photos is flickr.com. The UI is very slick and it is very flexible in the way that you can organize photos. Unfortunately, you cannot (yet) order prints from a UK supplier from the site.

Most of the UK print shops (Jessops, SupaSnaps etc.) have some online ordering and photo-sharing facilities, however they often have limits on the amount of time that photos will be kept for and/or storage limits. Also, the bulk upload facilities often rely on ActiveX controls which is a pain if you use Firefox as your browser or a non-Windows OS such as Linux.

I have finally settled on photobox.co.uk. The browser based bulk upload tool is a java applet so it works on linux and they also allow you to upload files by FTP. There is an initial storage limit of 200 Mb but this increases by 50Mb for each order placed.

Friday, March 24, 2006

Finally resurrecting this blog

As I am on holiday this week I have finally got around to resurrecting my blog. I originally opened it as somewhere to store links to sites I'd found on the internet but
del.icio.us is a much better alternative.

Thursday, September 02, 2004

mono-debugger

Tried to compile mono-debugger-0.9 from source and got a similar error in wrapper.c to that in this post

Wednesday, August 25, 2004

What is Mono?

What is Mono?

Mono is an open source implementation of the .Net platform