... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)



jTDS truncates VARCHAR and NVARCHAR stored procedure output parameter values that are longer than 4000 characters for NVARCHAR, 8000 for VARCHAR. This is a consequence of the fact that jTDS is still using the old SQL Server 2000 version of the TDS protocol. The jTDS developers are aware of this problem, but the comments in the bug report suggest that it may be a while before the problem is corrected. In the meantime, the work-around is to replace the output parameter with a single row, single column result set. If one is reluctant (or unable) to change the stored procedure, then the following sequence will work as well:

EXEC dbo.myproc(..., @result OUTPUT)
SELECT @result


Iterating Over Tables/Databases in SQL Server

SQL Server provides an undocumented stored procedure that is handy for applying commands to all of the tables within a catalog, sp_MSforeachtable:

sp_MSforeachtable 'print ''?'''

The question mark will be replaced by the table name. In a similar vein, we can iterate over all databases using sp_MSforeachdb. These procedures could disappear at any time, but they have been present in all versions from 7.0 to 2008R2 so far.

Both procedures accept the following arguments:

  • @command1 - the command to run for each table
  • @replacechar - the placeholder character for the table name (default '?')
  • @command2 - another command to execute for each table
  • @command3 - another command to execute for each table
  • @precommand - a command to execute before iterating
  • @postcommand - a command to execute after iterating


Lambdas In Java

With Oracle's takeover of Java, interest in functional programming appears to be renewed. As the Java language evolves in this direction, perhaps it needs a new name. How about one of these names?

  • Visual J++
  • C#
  • !C#
  • C##
  • OpenC#Beans



git am vs. Windows

Using git on Windows you may find that if you create a patch using git format-patch and try to apply it using git am, the patch file will fail to apply. The error message is "patch does not apply". If you inspect the patch file, you might be baffled because the patch does apply, that is, the context lines in the diff exactly match (byte for byte) the file being patched.

The problem is that git am invokes git mailsplit to split the patch file into individual patches -- and the latter component strips carriage-return characters by default. Consequently, the patch context fails to match the target files and the patch fails.

If you use git am --ignore-space-change to apply the patch, then it will succeed but any newly added lines will not conform to the Windows newline convention. The lines will end with a linefeed only.

A better solution is to use git am --keep-cr. This arranges to pass the --keep-cr option to git mailsplit, leaving the Windows-style line-endings in place. The patch will then be applied successfully. You can make this behaviour the default through a configuration variable in the am section of the git configuration file:

        keep-cr = true


View dangling GIT commits in GITK

You can use GITK to view commits that have no external references by using this command:

gitk --all $(git log -g --pretty=format:%h)


Cylon Programming Principle

Introducing the Cylon Programming Principle: "In well-designed software, there is only one god." (And his name is Singleton?)


Eclipse Forms vs. Context Menus

If you are using Eclipse's form toolkit infrastructure, you might run into an problem where you try to install a context menu but it does not appear. If you are using FormToolkit.adapt(Composite) to adapt a custom composite to a form, you must install your menu after adapting it. Otherwise, your menu will be replaced by the parent's menu. This may seem to be reasonable behaviour -- except when the parent widget has no menu at all.


XML Tricks in SQL Server 2005

Here are some stupid pet XML tricks in SQL Server 2005...

To XML-escape text stored in a column:

SELECT CAST('' AS XML).query('sql:column("v.v")')
FROM (SELECT '<>''"&' AS v) AS v

To XML-escape text stored in a variable:

SELECT @myText = '<>''"&'
SELECT CAST('' AS XML).query('sql:variable("@myText")')

To extract individual nodes from XML:

SELECT result.node.query('.')
FROM (SELECT CAST('<x><a/><b/><c/></x>' AS XML) AS x) AS x
CROSS APPLY x.x.nodes('/x/*') AS result(node)

Use XML to perform concatenation aggregation:

  strings AS (SELECT 'a' AS s UNION SELECT 'b' UNION SELECT 'c')
  (SELECT s AS 'text()' FROM strings FOR XML PATH(''))

Generate nested XML, avoiding FOR XML EXPLICIT:

  1 AS "@id"
, 2 AS "a/b/c"
, (SELECT v AS "e"
   FOR XML PATH('d'), TYPE )
, 3 AS "text()"
, 4 AS "data()"
FOR XML PATH('element'), ROOT('root')

Use XML namespaces:

( DEFAULT 'urn:default'
, 'urn:a' AS "a"

Blog Archive