2013年9月4日水曜日

[SQL Server] SQL Serverでテーブル定義取得(全テーブル)

SQL Serverで、テーブル定義らしいものを取得するクエリです。
これとの違いは、データベース内のすべてのテーブルについて出力します。

select
 obj.name as 'テーブル名'
,col.name as '名称'
,(select top 1 name from systypes where systypes.xtype = col.xtype) as '型'
,col.length as '桁数'
,case isnull(col.scale,0)
 when 0 then ' '
 else cast( col.scale as char(10) )
 end '小数部'
,case  col.isnullable
 when 0 then '○'
 else ' '
 end 'nn'
,isnull((select case colid when 0 then '' else '○' end  from sysindexkeys as keys where col.id = keys.id  and col.colid = keys.colid and keys.indid = 1),' ') as 'pk'
,isnull((select top 1 ex.value from sys.extended_properties as ex where col.id = ex.major_id and ex.minor_id = col.colid and ex.name = 'ms_description' ),' ') as 'コメント'
from syscolumns as col
inner join sysobjects as obj on col.id = obj.id
where obj.name in  (select name from sysobjects where xtype = 'u')

2013年4月26日金曜日

PowerShot Nが届きました


Canon PowerShot Nが届きました。
動作がキビキビしてて気持ちいいですね。
ゴールデンウィーク中に色々と使って見たいと思います。

2013年4月23日火曜日

[c#]VSテストプロジェクトで単体テストのカバレッジが100%にならなかった点の対策

Visual Studio Team System 2008にてテストプロジェクトを利用して、単体テストを行っています。
また、このエディションではコードカバレッジを取れるので100%にすることも要件にしています。

その中で見た目は処理が通っているのですが、カバレッジが100%にならないケースが出てきました。
以下がその例です。


public void Method01(System.Windows.Forms.Control.ControlCollection list)
{
    List<control> wk = new List<control>();
    foreach (Control tmp in list)
    {
        if (tmp is Label) continue;
        wk.Add(tmp);
    }
}


Collectionをforeachしているだけなのですが、これが問題のようです。
詳しい理由はわかりませんが、裏方さんのコードに通らないパスがあるっポイです。
とにかく、Collectionをforeachするとダメなので、Listをforeachするように変える処理を入れます。


//CollectionをListに変換する
public List<t> ConvertList<t>(ICollection collection)
{
    List<t> ret = new List<t>();
    IEnumerator tmp = collection.GetEnumerator();
    
    while(tmp.MoveNext()) {
        ret.Add((T)tmp.Current);            
    }
    return ret;
}


それで、foreachの所でこのメソッドを使います。


public void Method01(System.Windows.Forms.Control.ControlCollection list)
{
    List<control> wk = new List<control>();
    foreach (Control tmp in ConvertList<Control>(list))
    {
        if (tmp is Label) continue;
        wk.Add(tmp);
    }
}


これでカバレッジが100%になるようになりました。