がんふぃーるど室長の不定期ブログ

ただいま助手と悪戦苦闘中!

  ホーム :: 連絡をする :: 同期する  :: Login
投稿数  90  :: 記事 7 :: コメント 15113 :: トラックバック 13

ニュース


自己紹介

名前:がんふぃーるど
肩書:室長
種別:人間・男
資格一覧:
MCP 70-215 Installing, Configurating, and Administering Microsoft Windows 2000 Server
MCTS .NET Framework 2.0 - Distributed Applications
MCTS .NET Framework 2.0 - Web Applications

犬紹介


名前:なうら
肩書:助手
種別:犬・狆・メス
誕生日:2006/7/9
特技:鼻水飛ばし、甘噛、奇襲・急襲・強襲、そそう、お手、お座り、待て

記事カテゴリ

書庫

日記カテゴリ

ギャラリ

Oracleにはアプリケーションコンテキストというものがあります。ASP.NETで言うところの「セッション」みたいなもので、基本はKey-Valueで構成される情報を保持しています。Oracleのマニュアルを見るとCREATE CONTEXT文というのがちゃんと用意されており、ユーザ定義のアプリケーションコンテキストを使用すればかなり柔軟なアプリケーションを作成することが可能です。

今回は御触りということで、ユーザ定義のアプリケーションコンテキストは使用せずに組込みのアプリケーションコンテキスト「USERENV」を少しだけ使用します。

アプリケーションコンテキスト「USERENV」

USERENVにはセッションに関する情報がほぼ詰め込まれています。今回はこの中の「CLIENT_IDENTIFIER」を使用します。理由は至って簡単-ODP.NETのOracleConnection.ClientIdからお手軽に設定できるからです。

その他の値については下記のOracleのドキュメントを参照してください。

http://otndnld.oracle.co.jp/document/products/oracle11g/111/doc_dvd/server.111/E05750-02/functions.htm#11790

アプリケーションコンテキストの確認方法

アプリケーションコンテキスト確認用の関数があるので、それを使用します。

SYS_CONTEXT(namespace, parameter [, length ])

namespaceにUSERENV

parameterにCLIENT_IDENTIFIER

を指定します。lengthはオプショナルな設定値なので今回は無視(デフォルト値は256)

 ※USERENV関数というのもありますが下位互換用です。またUSERENV関数にはCLIENT_IDENTIFIERを取得する機能は存在しないので、基本SYS_CONTEXTを使用します。

ODP.NETでCLIENT_IDENTIFIERの設定

先に言ってしまいましたが、ODP.NETの以下のプロパティを設定します。

OracleConnection.ClientId

このプロパティは接続をOpenした後にのみ設定可能です。ClientIdは接続中つねに有効になり、Closeと共に解放されます(nullが設定される)。

using (OracleConnection conn = new OracleConnection("user id=XXXX; password=YYYY; data source=xe"))
{
    conn.Open();

    conn.ClientId = "30";
    command = conn.CreateCommand();
    command.CommandText = "SELECT SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') FROM DUAL";
    result = command.ExecuteScalar();
    Console.WriteLine(result.Equals(System.DBNull.Value) ? "null" : result.ToString());
}

アプリケーションコンテキストを使用してVIEWへ値を動的に渡す

アプリケーションコンテキストは関数を通して取得できるということで、VIEWなどに対して動的に値を渡すことが可能です。VIEWであれば、使用しているSQL側でWHERE句に条件を設定することで同じことが当然できますが、セキュリティ的な要件をVIEWでコントロールしたい場合などに役立ちます。(Oracleではセキュリティに関して、仮想プライベートデータベースという便利な機能がありますが、今回はそれを使用しません。)

ためしに以下のようなVIEWをOracleのHRスキーマ上に作成します。

-- マネージャ直下の部下を参照できるVIEW
CREATE OR REPLACE VIEW HR.EMPLOYEES_UNDER_MANAGER1
AS
SELECT * FROM HR.EMPLOYEES WHERE MANAGER_ID = SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER')

このVIEWはClientIdに社員IDが設定されていることを前提に作られています。ClientIdの値を変えることで返却される行が変更されます。

 

次回はユーザ定義のアプリケーションコンテキストの作成方法について説明しようと思います。

投稿日時 : 2008年8月18日 1:38

コメント

# re: アプリケーションコンテキスト その1 - Oracle 2008/08/18 1:42 がんふぃーるど
書き忘れた…ツール(SqlDeveloperやOSqlEdit)からCLIENT_IDENTIFIERを設定するためには以下の関数を使用
DBMS_SESSION.SET_IDENTIFIER (client_id VARCHAR2);
これでSQLのデバッグ時も安心。

# gHaIqjrhwq 2014/08/04 4:05 http://crorkz.com/
ummzWU Im thankful for the blog post.Much thanks again. Will read on...

# IiolGvisVTVpTOUUBNx 2014/08/07 2:42 http://crorkz.com/
21HJAi Im grateful for the blog article.Thanks Again. Will read on...

# chanel tasche 2.55 Kopie 2015/09/07 13:03 eiaodomlj@aol.com
i haven't observed A person fine retort in favor for obama
chanel tasche 2.55 Kopie http://www.replicasbag.net/de/-c87_88/

# cheap cartier love bracelet pink gold 2017/06/27 11:25 derxdwspelslxefswkdesdxmzk@hotmal.com
Just wish to say your article is as amazing. The clarity in your put up is simply cool and that i can think you're a professional in this subject. Well along with your permission let me to grab your feed to stay updated with approaching post. Thanks a million and please carry on the rewarding work.
cheap cartier love bracelet pink gold http://www.mywristwatchreview.com/

# Knockoff cartier love bracelet white gold 2017/07/05 18:51 deshzjcxncmxiefscsmassczjsw@hotmal.com
Please pray for me and make miracles happen. I was in a relationship for almost 4 years. We were truly in love and had a special relationship that we came this far and we had ups and downs but we still worked it through. In the first 2 in a half years or so we were close together and happy. Than in the third year a lot has changed towards him with his attitude in a mean and cold way towards me, he made us distance, we didnt have that physical connection anymore, but he was still with me i dont know why. And he was always having financial problems and other problems as well and i was always there for him and tried to help and i felt like he took me for granted and kept us going for that. Than as he suppose he had family problems and stress so he started acting even more negative towards me like i did harm to him. Than after he slowly pushed me away but wasnt speaking up . After all that he ended up hanging out with his old buddies that are bad influences and he does “weed” and he acts like a total different person now like i never exist for him and he doesnt care about me at all after all i went through for him. I dont understand how he could change like that towards me when i loved him and cared. Its been a little over a month we havent been together and it hurts and kills me and i got into depression because i never went through this in any relationship. Please pray for me to help us get back i know there is hope between me and him if we came this far for a reason. I need miracle to happen .
Knockoff cartier love bracelet white gold http://www.banglegold.net/category/cartier-love-bracelet-white-gold-fake/

コメントの投稿

タイトル:
名前:
Url:
コメント: