Windows 環境に DBD::Oracle をインストールする方法
普段の開発環境はもちろん本番機と同じく Linux で自分の端末にはさらに VMware 上での環境もあるのですが、ちょっとした作業分担のためにデザイナーさんの端末に同じような開発環境を構築することになりました。いろいろと不便があろうかと思い端末のホスト OS である Windows XP 環境下でシステム構築をすることになりました。
結構ノーマルな環境の端末なのでインストールが結構大変。中でも苦労するのがコンパイルを必要とするモジュール達です。極力 ppm 向けに用意された binary を探してきてインストールするわけですがいつもながら苦労するのは Oracle まわり。過去にいろいろ自分の端末での苦しみを思い出すと、VC++ をインストールして nmake を使ってアレコレやってみたものの ActivePerl 5.8 配下ではどうもうまくいかなかった記憶があります。
という経験もありながらもっと簡単な方法は無いものかと考えてみたところ実は凄く簡単でした。と言うわけで自分への備忘録という意味を含めて情報をまとめました。ちなみに、ActivePerl 5.6 向けには DBD-Oracle が配布されているようなので
2. ppm install DBD-Oracle
ですんなりいける模様です。※今やってるのは Perl 5.8 なので未確認情報ですけど。
Windows 環境に DBD::Oracle をインストールする方法
今回インストールを行ったマシンの環境は、Windows XP 32 bit + Oracle 10g + ActivePerl 5.8.8-817 です。- OTN から Oracle Database 10g Release 2 (10.2.0) for Microsoft Windows (32-bit) 30日間トライアル版をダウンロードする
- Oracle 10g をインストールする。インストール時に OCI をインストールすること。Oracle Server が別途別環境に立ち上がっていて DBD で接続するために Oracle-Client 版をインストールする場合も基本 OCI のみをインストールすればOK。その他のオプションは適当に使いそうなのを。例えばこんな感じで。
- Oracle をインストールすると実は Oracle ディレクトリ配下に Oracle 用の Perl がインストールされる。これは Oracle の管理系ツールがこの Perl で動く CGI だからって理由(詳細忘れましたが確か mod_perl でいろいろ動いているはず)なんです。でもって、当然ながら Oracle 社がちゃんと動作するようにコンパイルした DBD-Oracle が同梱されています。
でもってこの MSWin32-x86-multi-thread というディレクトリを C:\Perl\site\lib 配下にぶち込む。ここは手を抜いたので不要なものとかはちゃんと削除しておいた方がベターですけどね。
- あとはいつも通り $ORACL_HOME\NETWORK/ADMIN/tnsnames.ora をつくって Oracle 周りの設定を淡々と行う。最後に再起動して完了。
以上です。とっても簡単。ようはコピーして再起動だけです。ちなみに Windows 環境の場合はデフォルトの NLS_LANG が sjis になっているので、CGI の中とか httpd.conf とかで NLS_LANG を意図する設定をちゃんと記述してあげないと文字化けします。例えば、面倒なので CGI の頭の方で
とかやっちゃってもとりあえずは動くかと。あとは適当に sysdate でも取得できるか試せばOK。
use strict; use DBI; use Data::Dumper; $ENV{"NLS_LANG"} = "japanese_japan.ja16euc"; my $dbh = DBI->connect('dbi:Oracle:testdb', 'test', 'test123'); my $csr = $dbconn->prepare("SELECT SYSDATE FROM DUAL"); $csr->execute; my $rd = $csr->fetchrow_array; print Dumper($rd); $dbh->disconnect;
っちゅ〜わけで、DBD-Oracle のインストールに VC++ とか gcc for win とかは不要でした〜という備忘録でした。
__追記__
なんだかよくわからないのですが、別環境で ppm install DBD-Oracle やったら普通にインストールできちゃいました。┐(゚〜゚)┌ (謎)
C:\Perl>ppm install DBD-Oracle Downloading DBD-Oracle-1.17...done Unpacking DBD-Oracle-1.17...done Generating HTML for DBD-Oracle-1.17...done Installing to site area...done Downloading DBD-Oracle-1.17 install script...done ORACLE TECHNOLOGY NETWORK DEVELOPMENT AND DISTRIBUTION LICENSE AGREEMENT "We," "us," and "our" refers to Oracle USA, Inc. "You" and "your" refers to the individual or entity that wishes to use the Programs from Oracle unde r this Agreement. "Programs" refers to the Software Products referenced below that you wish to download and use and Program documentation. "License" refers to your right to use the Programs and Program documentation under the terms of this Agreement. The substantive and procedural laws of Califor nia govern this Agreement. You and Oracle agree to submit to the exclusive jurisdiction of, and venue in, the courts of San Francisco, San Mateo, or Santa Clara counties in California in any dispute arising out of or relating to this Agreement. We are willing to license the Programs to you only upon the condition that you accept all of the terms contained in this Agreement. Read the terms ca refully and select the "Accept" button at the bottom of the page to confirm your acceptance. If you are not willing to be bound by these terms, selec t the "Do Not Accept" button and the registration process will not continue. Software Product - Instant Client License Rights License. We grant you a non-exclusive right and license to use the Programs solely for your business purposes and development and testing purposes, subject to the terms of this Agreement. You may allow third parties to use the Programs, subject to the terms of this Agreement, provided such third party use i s for your business operations only. Distribution License We grant you a non-exclusive right and license to distribute the Programs, provided that you do not charge your end users for use of the Programs. Yo ur distribution of such Programs shall at a minimum include the following terms in an executed license agreement between you and the end user that: (1 ) restrict the use of the Programs to the business operations of the end user; (2) prohibit (a) the end user from assigning, giving, or transferring t he Programs or an interest in them to another individual or entity (and if your end user grants a security interest in the Programs, the secured party has no right to use or transfer the Programs); (b) make the Programs available in any manner to any third party for use in the third party's business operations (unless such access is expressly permitted for the specific program license or materials from the services you have acquired); and (c) tit le to the Programs from passing to the end user or any other party; (3) prohibit the reverse engineering (unless required by law for interoperability) , disassembly or decompilation of the Programs and prohibit duplication of the Programs except for a sufficient number of copies of each Program for t he end user's licensed use and one copy of each Program media; (4) disclaim, to the extent permitted by applicable law, our liability for any damages, whether direct, indirect, incidental, or consequential, arising from the use of the Programs; (5) require the end user at the termination of the Agre ement, to discontinue use and destroy or return to you all copies of the Programs and documentation; (6) prohibit publication of any results of benchm ark tests run on the Programs; (7) require the end user to comply fully with all relevant export laws and regulations of the United States and other a pplicable export and import laws to assure that neither the Programs, nor any direct product thereof, are exported, directly or indirectly, in violati on of applicable laws; (8) do not require us to perform any obligations or incur any liability not previously agreed to between you and us; (9) permit you to audit your end user's use of the Programs or to assign your right to audit the end user's use of the Programs to us; (10) designate us as a th ird party beneficiary of the end user license agreement; (11) include terms consistent with those contained in the sections of this Agreement entitled "Disclaimer of Warranties and Exclusive Remedies," "No Technical Support," "End of Agreement," "Relationship Between the Parties," and "Open Source"; and (11) exclude the application of the Uniform Computer Information Transactions Act. You may allow your end users to permit third parties to use the Programs on such end user's behalf for the purposes set forth in the end user license agreement, subject to the terms of such agreement. You shall be financially responsible for all claims and damages to us caused by your failure to inc lude the required contractual terms set forth above in each end user license agreement between you and an end user. We are a third party beneficiary o f any end user license agreement between you and the end user, but do not assume any of your obligations thereunder, and you agree that you will not e nter into any end user license agreement that excludes us as a third party beneficiary and will inform your end users of our rights. If you want to use the Programs for any purpose other than as expressly permitted under this Agreement you must contact us to obtain the appropriate l icense. We may audit your use of the Programs. Program documentation is either shipped with the Programs, or documentation may be accessed online at http://otn.oracle.com/docs. You agree to: (a) defend and indemnify us against all claims and damages caused by your distribution of the Programs in breach of this Agreement and/ or failure to include the required contractual provisions in your end user agreement as stated above; (b) keep executed end user agreements and record s of end user information including name, address, date of distribution and identity of Programs distributed; (c) allow us to inspect your end user ag reements and records upon request; and, (d) enforce the terms of your end user agreements so as to effect a timely cure of any end user breach, and to notify us of any breach of the terms. Ownership and Restrictions We retain all ownership and intellectual property rights in the Programs. You may make a sufficient number of copies of the Programs for the licensed use and one copy of the Programs for backup purposes. You may not: ?use the Programs for any purpose other than as provided above; ?charge your end users for use of the Programs; ?remove or modify any Program markings or any notice of our proprietary rights; ?assign this agreement or give the Programs, Program access or an interest in the Programs to any individual or entity except as provided under this a greement; ?cause or permit reverse engineering (unless required by law for interoperability), disassembly or decompilation of the Programs; ?disclose results of any Program benchmark tests without our prior consent; or, ?use any Oracle name, trademark or logo. Export You agree that U.S. export control laws and other applicable export and import laws govern your use of the Programs, including technical data; additio nal information can be found on Oracle's Global Trade Compliance web site located at http://www.oracle.com/products/export/index.html. You agree that neither the Programs nor any direct product thereof will be exported, directly, or indirectly, in violation of these laws, or will be used for any pu rpose prohibited by these laws including, without limitation, nuclear, chemical, or biological weapons proliferation. Disclaimer of Warranty and Exclusive Remedies THE PROGRAMS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. WE FURTHER DISCLAIM ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT LIMITATION , ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. IN NO EVENT SHALL WE BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, DATA OR DATA USE, INCURRED BY YOU OR ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT, EVEN IF WE HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DA MAGES. OUR ENTIRE LIABILITY FOR DAMAGES HEREUNDER SHALL IN NO EVENT EXCEED ONE THOUSAND DOLLARS (U.S. $1,000). No Technical Support Our technical support organization will not provide technical support, phone support, or updates to you or end users for the Programs licensed under t his agreement. Restricted Rights If you distribute a license to the United States government, the Programs, including documentation, shall be considered commercial computer software a nd you will place a legend, in addition to applicable copyright notices, on the documentation, and on the media label, substantially similar to the fo llowing: NOTICE OF RESTRICTED RIGHTS "Programs delivered subject to the DOD FAR Supplement are 'commercial computer software' and use, duplication, and disclosure of the programs, includi ng documentation, shall be subject to the licensing restrictions set forth in the applicable Oracle license agreement. Otherwise, programs delivered subject to the Federal Acquisition Regulations are 'restricted computer software' and use, duplication, and disclosure of the programs, including docu mentation, shall be subject to the restrictions in FAR 52.227-19, Commercial Computer Software-Restricted Rights (June 1987). Oracle Corporation, 500 Oracle Parkway, Redwood City, CA 94065." End of Agreement You may terminate this Agreement by destroying all copies of the Programs. We have the right to terminate your right to use the Programs if you fail to comply with any of the terms of this Agreement, in which case you shall destroy all copies of the Programs. Relationship Between the Parties The relationship between you and us is that of licensee/licensor. Neither party will represent that it has any authority to assume or create any obli gation, express or implied, on behalf of the other party, nor to represent the other party as agent, employee, franchisee, or in any other capacity. Nothing in this Agreement shall be construed to limit either party's right to independently develop or distribute software that is functionally simila r to the other party's products, so long as proprietary information of the other party is not included in such software. Open Source "Open Source" software - software available without charge for use, modification and distribution - is often licensed under terms that require the use r to make the user's modifications to the Open Source software or any software that the user 'combines' with the Open Source software freely available in source code form. If you use Open Source software in conjunction with the Programs, you must ensure that your use does not: (i) create, or purpo rt to create, obligations of us with respect to the Oracle Programs; or (ii) grant, or purport to grant, to any third party any rights to or immunitie s under our intellectual property or proprietary rights in the Oracle Programs. For example, you may not develop a software program using an Oracle P rogram and an Open Source program where such use results in a program file(s) that contains code from both the Oracle Program and the Open Source prog ram (including without limitation libraries) if the Open Source program is licensed under a license that requires any "modifications" be made freely a vailable. You also may not combine the Oracle Program with programs licensed under the GNU General Public License ("GPL") in any manner that could ca use, or could be interpreted or asserted to cause, the Oracle Program or any modifications thereto to become subject to the terms of the GPL. Entire Agreement You agree that this Agreement is the complete agreement for the Programs and licenses, and this Agreement supersedes all prior or contemporaneous Agre ements or representations. If any term of this Agreement is found to be invalid or unenforceable, the remaining provisions will remain effective. Last updated: 2/16/04 Do you accept the terms of this license ? (y/n) : y Fetching oci.dll.gz (94 Kb) 68Kb/94Kb (72.21%) 94Kb/94Kb (100.00%) Decompressing. oci.dll checksum: OK Fetching oraociei10.dll.gz (28 Mb) 56Kb/28Mb (0.18%) ...snip... 28Mb/28Mb (100.00%) Decompressing...................................... oraociei10.dll checksum: OK done 18 files installed
コメントやシェアをお願いします!
まきすけ
こんにちは。またお世話になります。
WindowsXP + Oracle10g Client + ActivePerl5.8.9 の環境でDBIを使った接続がうまくいかなかったので参考にさせて頂きました。
私の場合、ログインして手動での接続はできるが、タスクでSYSTEM権限を使った実行ができませんでした。
環境変数かな〜と調べていたのですが詰まってしまい、たどり着きました。
ただ、実行時のバージョンチェックで、Ver5.8.3以外はエラーを出してくれるので、MSWin32-x86-multi-threadフォルダの中にあるConfig.pmのバージョンチェック(32行目あたり)をコメントアウトしてやや無理矢理な状態になっています。
# クリティカルなものに使っているわけではないのでまぁ許容範囲かなと…
k.daibaさんの紹介されているStrawberry Perlもよさそうですね。今度試してみます。
k.daiba
Strawberry Perlを使えばCPANがそのまま使えます.
http://strawberryperl.com/
Cコンパイラ(Mingw GCC C/C++ compiler)も同梱してます.細かいことはこれを読んでくださいな
http://win32.perl.org/wiki/index.php?title=Strawberry_Perl