Saturday, September 26, 2009

Great Lives: Boris Johnson on Samuel Johnson


This was an interesting program, my father has always admired Samuel Johnson while I have found the way he is portrayed in the press, is often a bit smug, jingoistic and offensive:


Matthew Parris presents the biographical series in which his guests choose someone who has inspired their lives.

Boris Johnson, the Mayor of London, nominates Samuel Johnson, writer of the great dictionary. Dr Johnson's biographer, Peter Martin, joins the discussion.


As for Boris Johnson, I personally find him arrogant, boorish, out-of-touch and a perfect example of why the country shouldn't be dominated by a clique lead from the old upper-class institutions of eton-charthouse-winchester-harrow-oxbridge... This is quite a complex problem as these institution certainly are the elite of educators, have incredible strong histories, attract many of the very best teachers and students. Despite a brief period in the 60s & 70s when a more open society and new state institutions became fashionable, these old class-riddled institutions have few rivals.


Anyway I was intrigued by this program, mediated by the Mathew Paris, one of the very few conservative MPs, I like and respect (I'm please to say that I admired Mathew Paris' before I learnt that he was also gay man).


I elarnt quite a lot about Samuel Johnson and I was left with a slightly more favourable impression of him. Although I am still mystified why anyway would say anything so misogynistic and plain offensive as his awful quip regarding women preachers:

Sir, a woman's preaching is like a dog's walking on his hind legs. It is not done well; but you are surprised to find it done at all.


Despite my more positive outlook regarding Samuel Johnson, my contempt and dislike of Boris Johnson increased another notch.. I don't understand why he would praise The Sun and The Mail for the bold rudeness, political incorrectness.. I can see the point he is trying to make, but to me it is so weak but maybe to a more conservative mind these are qualities?


Matthew Paris, as a openly gay brought up with great finesse, a quote from one of Boris Johnson's "political incorrect" speeches:

if gay marriage was OK - and I was uncertain on the issue - then I saw no reason in principle why a union should not be consecrated between three men, as well as two men, or indeed three men and a dog.


It was a quote Boris foresaw that Matthew was going to raise and he tried to "talk over" Matthew, almost shouting him down to take control of the conversation and to try to drive the conversation away from this intensely nasty, bullying quip. However it was with great finesse, after Boris had blustered the conversation towards his own safe terriority, that Matthew


If you want to see more of the same, I have more on a blog post from May 2007:


http://davetravelogue.blogspot.com/2008/05/new-london-mayor-boris-vs-ken.html


Lastly both men, while have rare talents and are hard-working (workaholics?) the have common flaws.. their arrogance and conceit, alienate as many people as they inspire?


jingo |ˈji ng gō|

noun ( pl. -goes) dated chiefly derogatory

a vociferous supporter of policy favoring war, esp. in the name of patriotism.

PHRASES

by jingo! an exclamation of surprise.

ORIGIN late 17th cent. (originally a conjuror's word): by jingo (and the noun sense) come from a popular song adopted by those supporting the sending of a British fleet into Turkish waters to resist Russia in 1878. The chorus ran: “We don't want to fight, yet by Jingo! if we do, We've got the ships, we've got the men, and got the money too.”


nepotism |ˈnepəˌtizəm|

noun

the practice among those with power or influence of favoring relatives or friends, esp. by giving them jobs.

DERIVATIVES

nepotist |ˈnɛpətəst| noun

nepotistic |ˌnepəˈtistik| |ˈnɛpəˈtɪstɪk| |-ˈtɪstɪk| adjective

ORIGIN mid 17th cent.: from French népotisme, from Italian nepotismo, from nipote ‘nephew’ (with reference to privileges bestowed on the “nephews” of popes, who were in many cases their illegitimate sons).


misogynist |məˈsäjənist|

noun: a man who hates women.

adjective: reflecting or inspired by a hatred of women : a misogynist attitude.

DERIVATIVES

misogynistic |məˌsäjəˈnistik| |məˈsɑdʒəˈnɪstɪk| |-ˈnɪstɪk| adjective


finesse

noun

1 masterly finesse skill, skillfulness, expertise, subtlety, flair, panache, élan, polish, artistry, virtuosity, mastery.

2 a modicum of finesse tact, tactfulness, discretion, diplomacy, delicacy, sensitivity, perceptiveness, savoir faire.

3 a clever finesse winning move, trick, stratagem, ruse, maneuver, artifice, machination.


Thursday, September 24, 2009

70-433 SQL Server - Common Table Expressions

Firstly looking on wikipedia:


CTE can be thought of as an alternatives to derived tables (subquery), views, and inline user-defined functions


CTEs are define by the WITH statement and enable you to seperately define a complex sub-select statement separately making your queries more readable/logical.


Some of the most frequent uses of a Common Table Expression include creating tables on the fly inside a nested select, and doing recursive queries. Common Table Expressions can be used for both selects and DML statements. The natural question is, if we have been using TSQL for this long without Common Table Expressions, why start using them now? There are several benefits to learning CTEs. Although new to SQL Server, Common Table Expressions are part of ANSI SQL 99, or SQL3. Therefore, if ANSI is important to you, this is a step closer. Best of all, Common Table Expressions provide a powerful way of doing recursive and nested queries in a syntax that is usually easier to code and review than other methods.
http://www.databasejournal.com/features/mssql/article.php/3502676/Common-Table-Expressions-CTE-on-SQL-2005.htm


The following simple example demonstrates the syntax:


USE AdventureWorks GO  
WITH MyCTE( ListPrice, SellPrice) AS (   
SELECT ListPrice, ListPrice * .95   
FROM Production.Product ) 
 
SELECT * FROM MyCTE  GO

The above myCTE can then be in place of a table in the immediate next SQL statement.


Above the MAXRECURSION statement limits the number of times the sub-query will run

70-433 SQL Server Powershell

It would be nice to see some good examples of SQL Server power shell, Martin Bell's blog went through some of Microsoft Book On Line (BOL) examples; but I didn't immediately see where and why powershell scripting would help (the idea sounds great as I am big fan of Unix shell scripting).

I suspect somewhat like JavaScript which was not used in a particularly flexible or subtle way at first, that powershell has enormous potential and it just needs people to understand and use it to it's full capacity (in a possibly similar way to jquery libraries "on top of basic JavaScript")?

The 70-433 requires basic familiarity:

"Get-Item . | Get-ChildItem" cmdlet


returns "index names for table employees" when applied to the "indexes location"

(i.e. path SQLSERVER:SQL\Srv1\DEFAULT\Databases\Tables\Employees\Indexes)


returns "column names for table employees" when applied to the "columns location"

(i.e. path SQLSERVER:SQL\Srv1\DEFAULT\Databases\Tables\Employees\Columns)



"Get-Item . | Get-Member -type Properties " cmdlet


returns "all properties for table employees" when applied to the "tables location"

(i.e. path SQLSERVER:SQL\Srv1\DEFAULT\Databases\Tables\Employees)

70-433 SQL Server - SERVICEs & QUEUEs

CREATE SERVICE service_name [AUTHORIZATION owner_name] ON QUEUE [schema_name.]queue_name 

  [(contract_name | [DEFAULT]) [,...n];


A SERVICE (aka "Service Broker") require a QUEUE to be created, for example


CREATE QUEUE myQueue WITH STATUS=ON, ACTIVATION (

  STATUS=OFF, PROCEDURE_NAME=myProcForMessageHandling,

  MAX_QUEUE_READERS=3, EXECUTE AS SELF);


The above queue is ON and will receive messages, however as it's ACTIVATION STATUS=OFF messages will be held.


To change the "message type" handled use the ALTER SERVICE statement... 

70-433 SQL Server - Database Mail (based on SMTP)

Configured by the "Database Mail Configuration Wizard": SMTP accounts, security settings, system parameters ...

 

sysmail_delete_mailitems_sp -- houeskeeping typically based on sent_before (i.e. date sent) and sent_status (e.g. has the mail been 'sent')

sp_send_dbmail -- stored procedure to send email


NB The older SQL Mail was based on MAPI profiles and is harder to configure and administrate - Database Mail was introduced in SQL2005


70-433 SQL Server - changetable

Setting up a CHANGETABLE


Standard change tracking for developers ...


alter table employee enable change_tracking with (track_columns_updated = ON);


select e.empID, e2.salary FROM (CHANGETABLE(CHANGES employee,NULL))  as e

JOIN dbo.classes e2 on e.empID = e2.empID;


you can also restrict your changetable results, for example, to check the salary changes for empID=42:


CHANGETABLE(VERSION employee, (empID), (42)) as e


70-433 SQL Server - change_tracking

Configuring your DB for CHANGE_TRACKING


Basic configuration / housekeeping to be agreed with your DBA ...


ALTER DATABASE HR SET CHANGE_TRACKING = ON 

(CHANGE_RETENTION = 40 DAYS, AUTO_CLEANUP = ON);


and to disable change tracking:


ALTER DATABASE HR SET CHANGE_TRACKING = OFF;


(NB the DBA or Developer should disable change tracking on your select tables as well)


70-433 SQL Server - full-text search and stoplists

Create basic full-text search:


  CREATE FULLTEXT INDEX on Courses (Summary) KEY INDEX courseID;


Now if you want to perform a full-text search


  select courseID, summary from courses where contains (*, ' "SQL" AND "2008" ');


If you want to ignore a certain word, say 'CBT', you need to create a STOPLIST


CREATE FULLTEXT STOPLIST myStopList FROM SYSTEM STOPLIST;

ALTER FULLTEXT STOPLIST myStopList ADD 'CBT';


now when you create a full-text search, you can include the STOPLIST:


CREATE FULLTEXT INDEX on Courses (Summary) KEY INDEX CustID

  WITH STOPLIST = myStopList;


70-433 SQL Server - Query() method on XML elements

Setup example XML element:


declare @myXML xml

SET myXML = '

   

    eve

    matthey

 

 

    stef

    amar

 

 

    miriam

    tricky

 


Query example XML element:


Select @myXML.query('{/Root/employee[@employee=2]/surname}};


Expected results


amar


Reusing myXML, we could use sp_xml_preparedocument and OPENXML


DECLARE @docHandle int

EXEC sp_xml_preparedocument @docHandle, @myXML


70-433 SQL Server XML Indexes - basic usage examples

The emp table has two columns "xml data type" columns: emp_xml & dept_xml


each column have it's own "PRIMARY XML INDEX" and then also multiple (secondary) "XML INDEX" (FOR PATH, FOR VALUE or FOR PROPERTY)


CREATE PRIMARY XML INDEX emp_xml_pri ON emp(emp_xml);

CREATE XML INDEX emp_xml_value ON emp(emp_xml) USING XML INDEX emp_xml_pri FOR VALUE;

CREATE XML INDEX emp_xml_path ON emp(emp_xml)  USING XML INDEX emp_xml_pri FOR PATH;

CREATE XML INDEX emp_xml_prop ON emp(emp_xml)  USING XML INDEX emp_xml_pri FOR PROPERTY;




70-433 SQL Server XML Indexes

XML Indexes are a new concept for me, this Microsoft support page gives some good background.

Let start with the following slightly controversial (over-simplification):

Although not everyone would agree, one of the main reasons for the success of the relational database has been the inclusion of the SQL language. SQL is a set-based declarative language. As opposed to COBOL (or most .NET-based languages for that matter), when you use SQL, you tell the database what data you are looking for, rather than how to obtain that data. The SQL query processor determines the best plan to get the data you want and then retrieves the data for you. As query-processing engines mature, your SQL code will run faster and better (less I/O and CPU) without the developer making changes to the code. What development manager wouldn't be pleased to hear that programs will run faster and more efficiently with no changes to source code because the query engine gets better over time?

So how can we access data in XML format efficiently:

In the early days of XML, imperative programming (navigation through the XML DOM) was all the rage. The XQuery language in general and XQuery inside the database in particular make it possible for the query engine writers to approach the task of optimizing queries against XML. The chances of success are good because these folks have 20 years or so of practical experience optimizing SQL queries against the relational data model. The SQL Server 2005 implementation of XQuery over the built-in XML data type holds the same promise of a declarative language, with optimization through a query engine

The 70-433 exam appears to require basic familarity with the following XML functions:

Table 1. XML Data Type Functions

NameSignatureUsage
existbit = X.exist(string xquery)Checks for existence of nodes, returns 1 if any output returned from query, otherwise 0
valuescalar = X.value(

string xquery, string SQL type)

Returns a SQL scalar value from a query cast to specified SQL data type
queryXML = X.query(string xquery)Returns an XML data type instance from query
nodesX.nodes(string xquery)Table-value function used for XML to relational decomposition. Returns one row for each node that matches the query.
modifyX.modify(string xml-dml)A mutator method that changes the XML value in place


The article goes on to detail how this mapped and represented in internal SQL Server database objects.. interesting stuff.




psychology and power of arms (AK-47)


The following tells so much about the terrible power of the arms trade and the military.

Natasha Mitchell: The SPLA told you, there's a line in the book "always remember the gun is your mother and father now". Tell me about the relationship that you had as a boy to the AK-47 you were given. It was taller than you when you first got it.

Emmanuel Jal: An AK-47 gives you so much power when you hold it in your hand. With this thing I can shoot an elephant down. With this thing I'm equal as an adult, I can make an adult scream and beg for mercy. And the way it was brought to us was we were told: "this is your father and this is your mother". And it kind of makes sense. When you have an AK-47 you will not go hungry, you eat anywhere you pass, any village that you go to - you just sit under the tree and people will bring you food. That's the power it had. When you don't have it you become like a child again, you become vulnerable. And also the way we are trained with the movement is, it's like we idolise it, it's more important than your family members. If my father was against me I would fight my father, that's how we took it.


Emmanuel Jal is now a rapper, a powerful voice, rapping about his terrible experiences as a child soldier in the Sudanese Civil War.

This program is shocking a living hell in our time, but Emmanuel is able to communicate these living horrors with a great sense of humanity.

Normally I don't like rap but hear it works well.

Emmanuel Jal: Emma is my angel because she came at the right moment and she smuggled me, she risked her life smuggling me into Kenya.

Natasha Mitchell: I guess you wondered if she picked you or you picked her?

Natasha Mitchell: She decided to pick me, I don't know why me? Why did she pick me? I don't understand, I have no answer.

This one goes to Emma McCune
Angel to the rescue one afternoon
I'm here because you rescued me
I'm proud to carry your legacy
Thank you
Bless you
R I Peace

What would I be if Emma never rescued me?
What would I be?
What would I be, another starving refugee?
What would I be?
What would I be if Emma never rescued me?
Yeah e yeah yeah e yeah



Monday, September 7, 2009

gay icons: Noel Coward


I understand why people might persceive Noel Coward as outdated - but he is a gay icon for me

This graphic captures the joy of Coward's world for me!!

Noel Coward’s Outdated Defiance

First published in The Washington Times, June 12, 2009

Noel Coward's "Design for Living" — now in revival by the Shakespeare Theatre Company — shocked audiences when it premiered on Broadway in 1933. It's not hard to see why.

The play, about a polyandrous relationship between two men and a woman, makes no apologies for its liberationist view of sex and relationships and could hardly be more direct in its sympathetic presentation of gay attachment. "Design for Living" was considered so risque that Coward had to wait until 1939 before staging a production in London for fear of offending British censors.

Seen today, the play shocks, but for an altogether different reason: Its message is so outdated that it's bewildering why any theater would put it on except for its curatorial interest as a period artifact.

http://www.indegayforum.org/news/show/31850.html



Sunday, September 6, 2009

70-433 SQL Server GROUP BY ... WITH ROLLUP

GROUP BY ... WITH ROLLUP 

the GROUPING function (with the SELECT statement:


SELECT (CASE WHEN (GROUPING(Name) = 1) THEN 'TOTAL' ELSE Name END) as Name, Salary, SUM(Salary) AS Sal 

FROM Employee GROUP BY Salary, Name with ROLLUP

HAVING Salary ...


"if the CASE statement is not used with the GROUPING function, the value NULL will be displayed in the Name column for aggregate row"




I have two queries. One of them makes sense to me, the other don't. First one:

SELECT gender AS 'Gender', count(*) AS '#'
    FROM registrations
    GROUP BY gender WITH ROLLUP

That gives me this:

Gender       #
Female      20
Male        19
NULL        
39

So, I get the count, and the total count. What I expected. Next one:

SELECT c.printable_name AS 'Country', count(*) AS '#'
    FROM registrations r
    INNER JOIN country c ON r
.country = c.country_id
    GROUP BY country WITH ROLLUP

Country         #
Denmark         9
Norway         10
Sweden         18
United States   1
Uzbekistan      1
Uzbekistan     39

Same result. But why do I get Uzbekistan for the total??

Answer: Because you're not SELECTing the item that you're GROUPing BY. If you said:

GROUP BY c.printable_name

You'd get the expected NULL. However you're grouping by a different column so MySQL doesn't know that printable_name is taking part in a rollup-group, and selects any old value from that column, in the join of all registrations. (So it is possible you will see other countries than Uzbekistan.)

This is part of a wider problem with MySQL being permissive on what you can SELECT in a GROUP BY query. For example, you can say:

SELECT gender FROM registrations GROUP BY country;

and MySQL will happily pick one of the gender values for a registration from each country, even though there is no direct causal link (aka “functional dependency”) between country and gender. Other DBMSs will refuse the above command on the grounds that there isn't guaranteed to be one gender per country.(*)

http://stackoverflow.com/questions/659845/mysql-total-group-by-with-rollup-curiosity