Copy Tab URLs in Firefox

February 23, 2010

I have no idea whether this function is common knowledge, but yesterday I discovered that copying the URLs of all open tabs of a window is quite simple in Firefox (3.5).

First, execute Bookmarks, Select All Bookmarks... and save the tabs into a bookmark folder.

Next, locate the new folder in your bookmarks, right-click and select Copy.

The effect is that the clipboard now holds all the URLs contained in the folder.

If you paste as plain text (e.g. Notepad), only the URLs will show. If you paste as rich text (Word, Outlook), you get hyperlinks.

Searching the intertubes brings up a lot of add-ons that might save you a click or two, but its good to know that the function is essentially built-in.


Verifying Foreign Keys in MS SQL Server

February 18, 2010

During a recent data check we noticed that foreign key columns contained values which were not stored in the referenced tables. The foreign key constraints were there, but they had been deactivated with the WITH NOCHECK clause.

This blog post was quite helpful to understand disabled and trusted foreign key constraints.

Using this information, I wrote the following script to verify foreign key constraints

DECLARE @t sysname, @fk sysname, @s NVARCHAR(1000)

DECLARE c CURSOR FOR
SELECT t.name, fk.name
FROM sys.foreign_keys fk
INNER JOIN sys.objects t ON t.object_id = fk.parent_object_id
ORDER BY 1, 2

OPEN c 
FETCH c INTO @t, @fk

WHILE @@FETCH_STATUS = 0 BEGIN
	
	SET @s = 'ALTER TABLE ' + @t + 
		' WITH CHECK CHECK CONSTRAINT ' + @fk
	PRINT @s
	
	BEGIN TRY
	EXEC (@s)
	END TRY
	BEGIN CATCH
		PRINT 'Conflict in ' + @t + N'.' + @fk
		DBCC CHECKCONSTRAINTS (@t)
	END CATCH
	
	FETCH c INTO @t, @fk
END

CLOSE c
DEALLOCATE c

SELECT t.name, fk.name, fk.is_disabled, fk.is_not_trusted
FROM sys.foreign_keys fk
INNER JOIN sys.objects t ON t.object_id = fk.parent_object_id
WHERE fk.is_not_trusted = 1
ORDER BY 1, 2

The script tries to enable each foreign key constraint it finds in the database using the WITH CHECK CHECK CONSTRAINT clause.

If the check fails, it calls DBCC CHECKCONSTRAINTS which returns the set of recordings violating the foreign key constraint.

Finally, the list of all foreign keys is selected which are set to “not trusted” (see linked blog above).

The result of the script execution shows you which tables and records need to be cleaned up.

Run the script repeatedly after data cleanup until a single empty result set is returned.


Integrated Database Versioning and Documentation with dbscript 1.01

February 16, 2010

I have written about the planned features for dbscript 1.01 in recent posts, and the new version was released yesterday.

This is the updated table of Documentation Generators in dbscript 1.01:

Generated Documentation

MS SQL Server Oracle PostgreSql
dbscript HTML view
dbscript Single HTML view
HTML (single file) view view view
MediaWiki view view view
ScrewTurn Wiki (V2) view view view
ScrewTurn Wiki (V3) view view view
Word HTML view

The Documentation Generators in the first two lines are part of the dbscript web application (see demo links above).

This means that a developer can import a database schema (or upload a SQL DDL script) which will be stored as a version of a schema or database, define a Documentation Generator, and immediately view all information on this schema inside dbscript without requiring a third party application.

Developers are free to adjust the shipped XSLT style sheets according to their layout and content needs.

Documentation Contents

All XSLTs have been cleaned up to include information about table constraints and indexes, view indexes and triggers, and database triggers.

The information about table indexes is now displayed in separate tables, rather than inside the columns table.

Documentation also includes descriptions of database objects and columns.

Generic Projects

Users can create generic (i.e. database-independent) projects, if they just require the Versioning, UpdateNotifications and Installations features.

Other features

  • Administrators can now delete a whole project with all its information in one go.
  • Acknowledgements page
  • Creating a Documentation Generator adds default Generator Parts for easier setup

dbscript is available for download here.


Update of oraddlscript 0.15

February 15, 2010

Version 0.15 of oraddlscript includes two fixes requested by a user of this utility:

To correctly separate the CREATE PACKAGE and CREATE PACKAGE BODY statements of a package, it is necessary to execute the command

DBMS_METADATA.SET_TRANSFORM_PARAM(
    DBMS_METADATA.SESSION_TRANSFORM, 'SQLTERMINATOR', true);

before calling GET_DDL().

(I am really considering passing SESSION_TRANSFORM parameters from the command line if it should be necessary)

If DDL generation fails, oraddlscript will now additionally output the Oracle error message. This will allow for further debugging if you have database objects that won’t script.

The latest version of oraddlscript is available for download.


Documentation Generators in dbscript 1.01

February 11, 2010

Cleaning up the documentation generators mentioned in my previous post.

dbscript 1.01 will include generators for the formats listed in the tables below:

Generated Documentation

MS SQL Server Oracle PostgreSql
dbscript HTML
dbscript Single HTML
HTML (single file) view view view
MediaWiki view view view
ScrewTurn Wiki (V2) view view view
ScrewTurn Wiki (V3) view view view
Word HTML view

This table lists the XSLT style sheets shipped with dbscript.

Users are free to create their own style sheets or adapt existing style sheets for their use.

Generated Data Diagrams

MS SQL Server Oracle PostgreSql
PNG view view view
Dia view view view

Documentation samples are based on these freely available demo projects:

MS SQL Server AdventureWorks (2005)
Oracle Oracle Demo Schema
PostgreSql OpenNMS

Retrieving an Assembly’s Build Path

February 2, 2010

If you work in a team of several developers, and often come across the question, “Who built this latest version and when?”, here’s how you find out.

If an assembly if compiled with debug information, the StackFrame class contains information about its absolute source file names.

  public static class BuildInfo
  {
    private static string sBuildPath;

    public static string BuildPath
    {
      get
      {
        if (!string.IsNullOrEmpty(sBuildPath))
          return sBuildPath;

        StackFrame sf = new StackFrame(true);
        string s = sf.GetFileName();
        if (!string.IsNullOrEmpty(s))
        {
          int i = s.LastIndexOf("\\");
          if (i == -1)
            sBuildPath = s;
          else
            sBuildPath = s.Substring(0, i);
        }
        else
          sBuildPath = ".";

        return sBuildPath;
      }
    }
  }

If the source files are kept in directories named after the developer (e.g. C:\Team\DeveloperName\Project), it is easy to find out who last released a test version of an application.

To find out the build timestamp of an assembly, use these few lines:

  public static class BuildInfo
  {
    public static DateTime BuildDate
    {
      get
      {
        System.Reflection.Assembly assembly =
          System.Reflection.Assembly.GetExecutingAssembly();
        System.IO.FileInfo fileInfo = 
          new System.IO.FileInfo(assembly.Location);
        return fileInfo.LastWriteTime;
      }
    }
  }

Follow

Get every new post delivered to your Inbox.