2010年9月27日 星期一

PostgreSQL Schema 相關資訊取得方式

--列出所有資料表
SELECT * FROM information_schema.tables where table_schema='public'

--列出所有 Sequence
SELECT * FROM information_schema.sequences where sequence_schema='public'

--列出所有 Trigger
SELECT * FROM information_schema.routines where routine_schema='public' and data_type='trigger'

--列出角色可用資料表清單
select * from information_schema.role_table_grants where table_schema='public' and table_name in (SELECT table_name FROM information_schema.tables where table_schema='public')

--列出色角可用 Trigger
select * from information_schema.role_routine_grants where routine_schema='public' and routine_name in (SELECT routine_name FROM information_schema.routines where routine_schema='public' and data_type='trigger')

--列出可用角色清單
select * from information_schema.enabled_roles

--http://www.postgresql.org/docs/8.2/static/sql-grant.html
grant all on _data_history_sequence_seq to "postgres";

--http://www.postgresql.org/docs/8.2/static/sql-revoke.html
revoke all on _data_history_sequence_seq from "postgres";

2010年9月3日 星期五

在 PostgreSQL 如何透過 SQL 中斷其他 Connection?

首先要得知資料庫中有那些連線正在活動:
select * from pg_stat_activity


pg_stat_activity 是一個資料表,裡面包含了許多資訊,其中比較重要的是「procpid」欄位,如果要中斷別人的資料庫連線,需要這個欄位的資料當參數。


中斷資料庫連線:
select pg_terminate_backend(123);


pg_terminate_backend() 是一個函數,裡面要傳的參數就是「procpid」的資料,執行完成後,該條連線就會被中斷。


這些動作都需要權限才能執行。

2010年8月17日 星期二

如何讓 Windows 7 Bitlock 重新上鎖

簡單一條 Command:

manage-bde -lock P:

2010年8月4日 星期三

.Net Windows Form 拖拉放的用法

基本上是 DragEnter 事件要設定 Effect 屬性,與 DragDrop 事件要處理使用者放下來的資料就行了:

private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}

private void Form1_DragDrop(object sender, DragEventArgs e)
{
foreach(string each in e.Data.GetFormats())
Console.WriteLine(each);
}

2010年8月3日 星期二

Postgresql 的 information_schema 完整說明

http://www.postgresql.org/docs/current/static/information-schema.html

2009年11月17日 星期二

C# 的 Decimal 小數點很麻煩...

最近在算成績時發現,float 真的是不能拿來算成績,不只是不適合算錢,連滿分只有100分的成績也不能算,會算出一堆誤差,花了一堆時間查了半天終於發現有個叫「decimal」型態,有效位數非常大,專用在財務方面的資料型態,decimal 捨入計算誤差非常非常少,後來就全面使用 decimal 來算成績,可是又發現計算結果總是有「.00」出現,就算計算結果是整數,還是有那個00...要拿掉非常麻煩...,又搞了半天,終於發現終極解法,就是運算、儲存時全部用 decimal ,但是要輸出到報表就全部轉型成 float、double,雖然還是有點麻煩,不過算是較簡單的解法了。float、double 不適合運算,但是運算結果輸出去到是很適合,因為成績的圍範就滿分100,最多小數到2位,跟本不會超出 float 的圍範...吧....

我的目得只是要計算結果不能有誤差,但是結果的尾數是0的要去掉...就這樣..

2009年11月9日 星期一

Postgresql Changing a Column's Data Type

Changing a Column's Data Type

To convert a column to a different data type, use a command like:

ALTER TABLE products ALTER COLUMN price TYPE numeric(10,2);

This will succeed only if each existing entry in the column can be converted to the new type by an implicit cast. If a more complex conversion is needed, you can add a USING clause that specifies how to compute the new values from the old.

PostgreSQL will attempt to convert the column's default value (if any) to the new type, as well as any constraints that involve the column. But these conversions might fail, or might produce surprising results. It's often best to drop any constraints on the column before altering its type, and then add back suitably modified constraints afterwards.