[ruby-oci8-commit] [318] trunk/ruby-oci8: * VERSION: change version from 2.0-svn to 2.0. 0 to pass ruby
nobody at rubyforge.org
nobody at rubyforge.org
Sun Feb 8 07:35:37 EST 2009
Revision: 318
Author: kubo
Date: 2009-02-08 07:35:36 -0500 (Sun, 08 Feb 2009)
Log Message:
-----------
* VERSION: change version from 2.0-svn to 2.0.0 to pass ruby
gem's version string validator.
* ruby-oci8.gemspec: added.
* ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oci8lib.c,
ext/oci8/win32.c: 1. add OCI8::Win32Util.dll_path to
retrieve Oracle home location from the OCI.DLL location.
2. add OCI8::Win32Util.enum_homes to get Oracle home and
NLS_LANG pairs in Windows registry.
* lib/oci8/encoding-init.rb: get NLS_LANG from Windows registry
if environment variable NLS_LANG is not set.
* ext/oci8/oraconf.rb: Change the output encoding of sqlplus to
US7ASCII by setting NLS_LANG. If the output encoding is
incompatible with the default external encoding, it raises
'invalid byte sequence' when using ruby 1.9.
* lib/oci8/datetime.rb: fix for ruby 1.9. Ruby 1.9 Time
class's resolution is nanosecond.
* dist-files: add dist-files, ruby-oci8.gemspec and ext/oci8/win32.c.
Modified Paths:
--------------
trunk/ruby-oci8/ChangeLog
trunk/ruby-oci8/VERSION
trunk/ruby-oci8/dist-files
trunk/ruby-oci8/ext/oci8/extconf.rb
trunk/ruby-oci8/ext/oci8/oci8.h
trunk/ruby-oci8/ext/oci8/oci8lib.c
trunk/ruby-oci8/ext/oci8/oraconf.rb
trunk/ruby-oci8/lib/oci8/datetime.rb
trunk/ruby-oci8/lib/oci8/encoding-init.rb
Added Paths:
-----------
trunk/ruby-oci8/ext/oci8/win32.c
trunk/ruby-oci8/ruby-oci8.gemspec
Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog 2009-02-08 09:45:10 UTC (rev 317)
+++ trunk/ruby-oci8/ChangeLog 2009-02-08 12:35:36 UTC (rev 318)
@@ -1,3 +1,22 @@
+2009-02-08 KUBO Takehiro <kubo at jiubao.org>
+ * VERSION: change version from 2.0-svn to 2.0.0 to pass ruby
+ gem's version string validator.
+ * ruby-oci8.gemspec: added.
+ * ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oci8lib.c,
+ ext/oci8/win32.c: 1. add OCI8::Win32Util.dll_path to
+ retrieve Oracle home location from the OCI.DLL location.
+ 2. add OCI8::Win32Util.enum_homes to get Oracle home and
+ NLS_LANG pairs in Windows registry.
+ * lib/oci8/encoding-init.rb: get NLS_LANG from Windows registry
+ if environment variable NLS_LANG is not set.
+ * ext/oci8/oraconf.rb: Change the output encoding of sqlplus to
+ US7ASCII by setting NLS_LANG. If the output encoding is
+ incompatible with the default external encoding, it raises
+ 'invalid byte sequence' when using ruby 1.9.
+ * lib/oci8/datetime.rb: fix for ruby 1.9. Ruby 1.9 Time
+ class's resolution is nanosecond.
+ * dist-files: add dist-files, ruby-oci8.gemspec and ext/oci8/win32.c.
+
2009-02-06 KUBO Takehiro <kubo at jiubao.org>
* setup.rb: 1. install lib/**/*.yml flies also.
(It is pointed by Nate Wiger that encoding.yml is not installed.)
Modified: trunk/ruby-oci8/VERSION
===================================================================
--- trunk/ruby-oci8/VERSION 2009-02-08 09:45:10 UTC (rev 317)
+++ trunk/ruby-oci8/VERSION 2009-02-08 12:35:36 UTC (rev 318)
@@ -1 +1 @@
-2.0-svn
+2.0.0
Modified: trunk/ruby-oci8/dist-files
===================================================================
--- trunk/ruby-oci8/dist-files 2009-02-08 09:45:10 UTC (rev 317)
+++ trunk/ruby-oci8/dist-files 2009-02-08 12:35:36 UTC (rev 318)
@@ -2,8 +2,10 @@
Makefile
README
VERSION
+dist-files
metaconfig
pre-distclean.rb
+ruby-oci8.gemspec
setup.rb
doc/api.en.html
doc/api.en.rd
@@ -34,6 +36,7 @@
ext/oci8/post-config.rb
ext/oci8/stmt.c
ext/oci8/object.c
+ext/oci8/win32.c
ext/oci8/xmldb.c
lib/.document
lib/oci8.rb.in
Modified: trunk/ruby-oci8/ext/oci8/extconf.rb
===================================================================
--- trunk/ruby-oci8/ext/oci8/extconf.rb 2009-02-08 09:45:10 UTC (rev 317)
+++ trunk/ruby-oci8/ext/oci8/extconf.rb 2009-02-08 12:35:36 UTC (rev 318)
@@ -81,6 +81,11 @@
"ocinumber.o", "ocidatetime.o", "object.o", "apiwrap.o",
"encoding.o", "xmldb.o"]
+if RUBY_PLATFORM =~ /mswin32|cygwin|mingw32|bccwin32/
+ $defs << "-DUSE_WIN32_C"
+ $objs << "win32.o"
+end
+
# Checking gcc or not
if oraconf.cc_is_gcc
$CFLAGS += " -Wall"
Modified: trunk/ruby-oci8/ext/oci8/oci8.h
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.h 2009-02-08 09:45:10 UTC (rev 317)
+++ trunk/ruby-oci8/ext/oci8/oci8.h 2009-02-08 12:35:36 UTC (rev 318)
@@ -436,6 +436,9 @@
void Init_oci8_encoding(VALUE cOCI8);
VALUE oci8_charset_id2name(VALUE svc, VALUE charset_id);
+/* win32.c */
+void Init_oci8_win32(VALUE cOCI8);
+
#ifdef HAVE_TYPE_RB_ENCODING
extern rb_encoding *oci8_encoding;
Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8lib.c 2009-02-08 09:45:10 UTC (rev 317)
+++ trunk/ruby-oci8/ext/oci8/oci8lib.c 2009-02-08 12:35:36 UTC (rev 318)
@@ -160,6 +160,10 @@
Init_oci_object(cOCI8);
Init_oci_xmldb();
+#ifdef USE_WIN32_C
+ Init_oci8_win32(cOCI8);
+#endif
+
#ifdef DEBUG_CORE_FILE
signal(SIGSEGV, SIG_DFL);
#endif
Modified: trunk/ruby-oci8/ext/oci8/oraconf.rb
===================================================================
--- trunk/ruby-oci8/ext/oci8/oraconf.rb 2009-02-08 09:45:10 UTC (rev 317)
+++ trunk/ruby-oci8/ext/oci8/oraconf.rb 2009-02-08 12:35:36 UTC (rev 318)
@@ -712,6 +712,7 @@
sqlplus = "sqlplus"
end
Logging::open do
+ ENV['NLS_LANG'] = 'american_america.us7ascii'
open("|#{@oracle_home}/bin/#{sqlplus} < #{dev_null}") do |f|
while line = f.gets
print line
Added: trunk/ruby-oci8/ext/oci8/win32.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/win32.c (rev 0)
+++ trunk/ruby-oci8/ext/oci8/win32.c 2009-02-08 12:35:36 UTC (rev 318)
@@ -0,0 +1,131 @@
+/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
+/*
+ win32.c - part of ruby-oci8
+
+ Copyright (C) 2009 KUBO Takehiro <kubo at jiubao.org>
+*/
+#include "oci8.h"
+#include <windows.h>
+
+NORETURN(static void raise_error(void));
+
+static void raise_error(void)
+{
+ char msg[1024];
+ int err = GetLastError();
+ char *p;
+
+ sprintf(msg, "%d: ", err);
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ msg + strlen(msg), sizeof(msg) - strlen(msg), NULL);
+ for (p = msg; *p != '\0'; p++) {
+ if (*p == '\n' || *p == '\r') {
+ *p = ' ';
+ }
+ }
+ rb_raise(rb_eRuntimeError, "%s", msg);
+}
+
+static VALUE dll_path(VALUE module)
+{
+ HMODULE hModule;
+ DWORD len;
+ char path[1024];
+
+ hModule = GetModuleHandle("OCI.DLL");
+ if (hModule == NULL) {
+ raise_error();
+ }
+ len = GetModuleFileName(hModule, path, sizeof(path));
+ if (len == 0) {
+ raise_error();
+ }
+ return rb_external_str_new_with_enc(path, len, rb_filesystem_encoding());
+}
+
+
+typedef struct {
+ HKEY hKey;
+ HKEY hSubKey;
+} enum_homes_arg_t;
+
+static VALUE enum_homes_real(enum_homes_arg_t *arg)
+{
+ LONG rv;
+ DWORD type;
+ DWORD idx;
+ char name[1024];
+ DWORD name_len;
+ FILETIME ft;
+
+ rv = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\ORACLE", 0, KEY_ENUMERATE_SUB_KEYS, &arg->hKey);
+ if (rv != ERROR_SUCCESS) {
+ return Qnil;
+ }
+ for (idx = 0; ; idx++) {
+ volatile VALUE oracle_home;
+ volatile VALUE nls_lang;
+
+ /* Get subkey name */
+ name_len = sizeof(name);
+ rv = RegEnumKeyEx(arg->hKey, idx, name, &name_len, NULL, NULL, NULL, &ft);
+ if (rv != ERROR_SUCCESS) {
+ break;
+ }
+ /* Open subkey */
+ if (arg->hSubKey != NULL) {
+ RegCloseKey(arg->hSubKey);
+ arg->hSubKey = NULL;
+ }
+ rv = RegOpenKeyEx(arg->hKey, name, 0, KEY_QUERY_VALUE, &arg->hSubKey);
+ if (rv != ERROR_SUCCESS) {
+ continue;
+ }
+ /* Get ORACLE_HOME */
+ name_len = sizeof(name);
+ rv = RegQueryValueEx(arg->hSubKey, "ORACLE_HOME", NULL, &type, name, &name_len);
+ if (rv != ERROR_SUCCESS || type != REG_SZ) {
+ continue;
+ }
+ oracle_home = rb_locale_str_new_cstr(name);
+ /* Get NLS_LANG */
+ name_len = sizeof(name);
+ rv = RegQueryValueEx(arg->hSubKey, "NLS_LANG", NULL, &type, name, &name_len);
+ if (rv != ERROR_SUCCESS || type != REG_SZ) {
+ continue;
+ }
+ nls_lang = rb_locale_str_new_cstr(name);
+ rb_yield_values(2, oracle_home, nls_lang);
+ }
+ return Qnil;
+}
+
+static VALUE enum_homes_ensure(enum_homes_arg_t *arg)
+{
+ if (arg->hKey != NULL) {
+ RegCloseKey(arg->hKey);
+ arg->hKey = NULL;
+ }
+ if (arg->hSubKey != NULL) {
+ RegCloseKey(arg->hSubKey);
+ arg->hSubKey = NULL;
+ }
+ return Qnil;
+}
+
+static VALUE enum_homes(VALUE module)
+{
+ enum_homes_arg_t arg;
+ arg.hKey = NULL;
+ arg.hSubKey = NULL;
+ return rb_ensure(enum_homes_real, (VALUE)&arg, enum_homes_ensure, (VALUE)&arg);
+}
+
+void Init_oci8_win32(VALUE cOCI8)
+{
+ VALUE mWin32Util = rb_define_module_under(cOCI8, "Win32Util");
+
+ rb_define_module_function(mWin32Util, "dll_path", dll_path, 0);
+ rb_define_module_function(mWin32Util, "enum_homes", enum_homes, 0);
+}
Modified: trunk/ruby-oci8/lib/oci8/datetime.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/datetime.rb 2009-02-08 09:45:10 UTC (rev 317)
+++ trunk/ruby-oci8/lib/oci8/datetime.rb 2009-02-08 12:35:36 UTC (rev 318)
@@ -151,7 +151,10 @@
end
if timezone
begin
- return ::Time.send(timezone, year, month, day, hour, minute, sec, fsec / 1000)
+ # Ruby 1.9 Time class's resolution is nanosecond.
+ # But the last argument type is millisecond.
+ # 'fsec' is converted to a Float to pass sub-millisecond part.
+ return ::Time.send(timezone, year, month, day, hour, minute, sec, fsec / 1000.0)
rescue StandardError
end
end
Modified: trunk/ruby-oci8/lib/oci8/encoding-init.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/encoding-init.rb 2009-02-08 09:45:10 UTC (rev 317)
+++ trunk/ruby-oci8/lib/oci8/encoding-init.rb 2009-02-08 12:35:36 UTC (rev 318)
@@ -5,8 +5,17 @@
# try to get NLS_LANG.
nls_lang = ENV['NLS_LANG']
-if nls_lang.nil? and RUBY_PLATFORM =~ /mswin32|cygwin|mingw32|bccwin32/
- # TODO
+if defined? OCI8::Win32Util
+ dll_path = OCI8::Win32Util.dll_path.upcase
+ if dll_path =~ %r{\\BIN\\OCI.DLL}
+ oracle_home = $`
+ OCI8::Win32Util.enum_homes do |home, lang|
+ if oracle_home == home.upcase
+ nls_lang = lang
+ break
+ end
+ end
+ end
end
if nls_lang
Added: trunk/ruby-oci8/ruby-oci8.gemspec
===================================================================
--- trunk/ruby-oci8/ruby-oci8.gemspec (rev 0)
+++ trunk/ruby-oci8/ruby-oci8.gemspec 2009-02-08 12:35:36 UTC (rev 318)
@@ -0,0 +1,54 @@
+# -*- ruby -*-
+#
+# To make a pure ruby gems package:
+# gem build ruby-oci8.gemspec
+#
+# To make a binary gems package:
+# gem build ruby-oci8.gemspec -- current
+#
+
+if ARGV.size > 3
+ gem_platform = ARGV[3]
+else
+ gem_platform = Gem::Platform::RUBY
+end
+
+spec = Gem::Specification.new do |s|
+ s.name = 'ruby-oci8'
+ s.version = File.read('VERSION').strip
+ s.summary = 'Ruby interface for Oracle using OCI8 API'
+ s.email = 'kubo at jiubao.org'
+ s.homepage = 'http://ruby-oci8.rubyforge.org'
+ s.rubyforge_project = 'ruby-oci8'
+ s.description = <<EOS
+ruby-oci8 is a ruby interface for Oracle using OCI8 API. It is available with Oracle8, Oracle8i, Oracle9i, Oracle10g and Oracle Instant Client.
+EOS
+ s.has_rdoc = true
+ s.authors = ['KUBO Takehiro']
+ s.platform = gem_platform
+ files = File.read('dist-files').split("\n")
+ if gem_platform == Gem::Platform::RUBY
+ s.require_paths = ['lib']
+ s.extensions << 'ext/oci8/extconf.rb'
+ s.required_ruby_version = '>= 1.8.0'
+ else
+ s.require_paths = ['lib', 'ext/oci8']
+ if RUBY_VERSION =~ /^1\.9\./
+ s.required_ruby_version = '~> 1.9.1'
+ else
+ s.required_ruby_version = '~> 1.8.0'
+ end
+ # check files created by a make command.
+ ['ext/oci8/oci8lib.so', 'lib/oci8.rb'].each do |file|
+ raise <<EOS unless File.exist?(file)
+#{file} doesn't exist. Run make in advance.
+EOS
+ #'
+ files << file
+ end
+ end
+ s.files = files
+ s.test_files = 'test/test_all.rb'
+ s.rdoc_options = ['--main', 'README', '--exclude', 'ext/*']
+ s.extra_rdoc_files = ['README']
+end
More information about the ruby-oci8-commit
mailing list