Skip to content

Commit 9782223

Browse files
yahondaclaude
andcommitted
Merge upstream/master and resolve conflicts
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 parents aa754f7 + 3a7a307 commit 9782223

File tree

16 files changed

+351
-52
lines changed

16 files changed

+351
-52
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: Bug report
3+
about: Report a bug in ruby-plsql
4+
---
5+
6+
### Steps to reproduce
7+
Provide a minimal PL/SQL and Ruby script that demonstrates the issue.
8+
9+
### Expected behavior
10+
Tell us what should happen.
11+
12+
### Actual behavior
13+
Tell us what happens instead.
14+
15+
### System configuration
16+
**ruby-plsql version**:
17+
18+
**Ruby version**:
19+
20+
**Ruby on Rails version** (if applicable):
21+
22+
**Oracle Database version** (paste the output of `select * from v$version`):

.github/dependabot.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ updates:
44
- package-ecosystem: "github-actions"
55
directory: "/"
66
schedule:
7-
# Check for updates to GitHub Actions every weekday
8-
interval: "daily"
7+
interval: "weekly"

.github/workflows/release.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,32 @@ jobs:
2323
- name: Build gem
2424
run: gem build ruby-plsql.gemspec
2525
- name: Upload gem artifact
26-
uses: actions/upload-artifact@v4
26+
uses: actions/upload-artifact@v7
2727
with:
2828
name: gem-cruby
2929
path: "*.gem"
3030

31+
build-jruby:
32+
name: Build gem (JRuby)
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v6
36+
- name: Set up Ruby
37+
uses: ruby/setup-ruby@v1
38+
with:
39+
ruby-version: 'jruby-10.0.5.0'
40+
rubygems: latest
41+
- name: Build gem
42+
run: gem build ruby-plsql.gemspec
43+
- name: Upload gem artifact
44+
uses: actions/upload-artifact@v7
45+
with:
46+
name: gem-jruby
47+
path: "*.gem"
48+
3149
release:
32-
name: Push gem to RubyGems
33-
needs: [build-cruby]
50+
name: Push gems to RubyGems
51+
needs: [build-cruby, build-jruby]
3452
runs-on: ubuntu-latest
3553
environment: rubygems
3654
permissions:
@@ -39,17 +57,21 @@ jobs:
3957
actions: read
4058
steps:
4159
- name: Download CRuby gem
42-
uses: actions/download-artifact@v4
60+
uses: actions/download-artifact@v8
4361
with:
4462
name: gem-cruby
63+
- name: Download JRuby gem
64+
uses: actions/download-artifact@v8
65+
with:
66+
name: gem-jruby
4567
- name: Set up Ruby
4668
uses: ruby/setup-ruby@v1
4769
with:
4870
ruby-version: '4.0'
4971
rubygems: latest
5072
- name: Configure RubyGems credentials
5173
uses: rubygems/configure-rubygems-credentials@main
52-
- name: Push gem
74+
- name: Push gems
5375
run: |
5476
for gem in *.gem; do
5577
echo "Pushing $gem"

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.com/rsim/ruby-plsql.svg?branch=master)](https://travis-ci.com/rsim/ruby-plsql)
1+
[![Test](https://github.com/rsim/ruby-plsql/actions/workflows/test.yml/badge.svg)](https://github.com/rsim/ruby-plsql/actions/workflows/test.yml)
22

33
ruby-plsql
44
==========
@@ -120,6 +120,22 @@ plsql.activerecord_class = ActiveRecord::Base
120120
and then you do not need to specify plsql.connection (this is also safer when ActiveRecord reestablishes connection to database).
121121

122122

123+
### JRuby JDBC connection:
124+
125+
When using JRuby, the `connect!` method with `:host` and `:database` options uses the thin-style service name syntax by default:
126+
127+
```ruby
128+
# Connects using service name syntax: jdbc:oracle:thin:@//localhost:1521/MYSERVICENAME
129+
plsql.connect! username: "hr", password: "hr", host: "localhost", database: "MYSERVICENAME"
130+
```
131+
132+
If you need to connect using the legacy SID syntax (for Oracle databases older than 12c), prefix the database name with a colon:
133+
134+
```ruby
135+
# Connects using SID syntax: jdbc:oracle:thin:@localhost:1521:MYSID
136+
plsql.connect! username: "hr", password: "hr", host: "localhost", database: ":MYSID"
137+
```
138+
123139
### Cheat Sheet:
124140

125141
You may have a look at this [Cheat Sheet](http://cheatography.com/jgebal/cheat-sheets/ruby-plsql-cheat-sheet/) for instructions on how to use ruby-plsql
@@ -135,7 +151,7 @@ or include gem in Gemfile if using bundler.
135151

136152
In addition install either ruby-oci8 (for MRI/YARV) or copy Oracle JDBC driver to $JRUBY_HOME/lib (for JRuby).
137153

138-
If you are using MRI Ruby implementation then you need to install ruby-oci8 gem (version 2.0.x or 2.1.x)
154+
If you are using MRI Ruby implementation then you need to install ruby-oci8 gem (version 2.1 or higher)
139155
as well as Oracle client, e.g. [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html).
140156

141157
If you are using JRuby then you need to download latest [Oracle JDBC driver](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html) - either ojdbc7.jar for Java 8 and 7, ojdbc6.jar for Java 6, 7, 8 or ojdbc5.jar for Java 5. You can refer [the support matrix](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#01_03) for details.

lib/plsql/jdbc_connection.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,31 @@
4848
module PLSQL
4949
class JDBCConnection < Connection # :nodoc:
5050
def self.create_raw(params)
51+
url = jdbc_connection_url(params)
52+
new(java.sql.DriverManager.getConnection(url, params[:username], params[:password]))
53+
end
54+
55+
def self.jdbc_connection_url(params)
5156
database = params[:database]
52-
url = if ENV["TNS_ADMIN"] && database && !params[:host] && !params[:url]
57+
if ENV["TNS_ADMIN"] && database && database !~ %r{\A[:/]} && !params[:host] && !params[:url]
5358
"jdbc:oracle:thin:@#{database}"
5459
else
55-
database = ":#{database}" unless database.match(/^(\:|\/)/)
56-
params[:url] || "jdbc:oracle:thin:@#{params[:host] || 'localhost'}:#{params[:port] || 1521}#{database}"
60+
return params[:url] if params[:url]
61+
62+
raise ArgumentError, "database or url option is required" if database.nil? || database.empty?
63+
64+
host = params[:host] || "localhost"
65+
port = params[:port] || 1521
66+
67+
if database =~ /^:/
68+
# SID syntax: jdbc:oracle:thin:@host:port:SID
69+
"jdbc:oracle:thin:@#{host}:#{port}#{database}"
70+
else
71+
# service name syntax: jdbc:oracle:thin:@//host:port/service_name
72+
database = "/#{database}" unless database =~ /^\//
73+
"jdbc:oracle:thin:@//#{host}:#{port}#{database}"
74+
end
5775
end
58-
new(java.sql.DriverManager.getConnection(url, params[:username], params[:password]))
5976
end
6077

6178
def set_time_zone(time_zone = nil)

lib/plsql/oci8_patches.rb

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/plsql/oci_connection.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414
raise LoadError, "ERROR: ruby-plsql could not load ruby-oci8 library. #{msg}"
1515
end
1616

17-
require "plsql/oci8_patches"
18-
1917
# check ruby-oci8 version
20-
required_oci8_version = [2, 0, 3]
21-
oci8_version_ints = OCI8::VERSION.scan(/\d+/).map { |s| s.to_i }
22-
if (oci8_version_ints <=> required_oci8_version) < 0
23-
raise LoadError, "ERROR: ruby-oci8 version #{OCI8::VERSION} is too old. Please install ruby-oci8 version #{required_oci8_version.join('.')} or later."
18+
if Gem::Version.new(OCI8::VERSION) < Gem::Version.new("2.1.0")
19+
raise LoadError, "ERROR: ruby-oci8 version #{OCI8::VERSION} is too old. Please install ruby-oci8 version 2.1.0 or later."
2420
end
2521

2622
module PLSQL

lib/plsql/procedure.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def get_field_definitions(argument_metadata) # :nodoc:
391391
when "TABLE", "VIEW"
392392
@schema.select_all(
393393
"SELECT column_id, column_name, data_type, data_length, data_precision, data_scale, char_length, char_used
394-
FROM ALL_TAB_COLS WHERE OWNER = :owner AND TABLE_NAME = :type_name
394+
FROM ALL_TAB_COLUMNS WHERE OWNER = :owner AND TABLE_NAME = :type_name
395395
ORDER BY column_id",
396396
@schema_name, argument_metadata[:type_name]) do |r|
397397

@@ -464,6 +464,23 @@ def get_element_definition(argument_metadata) # :nodoc:
464464

465465
if elem_type_package != nil
466466
element_metadata[:fields] = get_field_definitions(element_metadata)
467+
elsif elem_type_name && elem_type_name =~ /\A(.+)%ROWTYPE\z/
468+
# TABLE OF table%ROWTYPE: Oracle stores elem_type_name as "TABLE_NAME%ROWTYPE"
469+
rowtype_table_name = $1
470+
check_owner = elem_type_owner || @schema_name
471+
object_type_row = @schema.select_first(
472+
"SELECT object_type FROM ALL_OBJECTS WHERE owner = :owner AND object_name = :name AND object_type IN ('TABLE', 'VIEW')",
473+
check_owner, rowtype_table_name)
474+
if object_type_row
475+
element_metadata[:type_owner] ||= check_owner
476+
element_metadata[:type_name] = rowtype_table_name
477+
element_metadata[:sql_type_name] = build_sql_type_name(check_owner, nil, rowtype_table_name)
478+
element_metadata[:data_type] = "PL/SQL RECORD"
479+
element_metadata[:type_object_type] = object_type_row[0]
480+
element_metadata[:fields] = get_field_definitions(element_metadata)
481+
else
482+
raise ArgumentError, "Could not resolve #{check_owner}.#{rowtype_table_name} to a table or view for #{elem_type_name}"
483+
end
467484
end
468485
when "TYPE"
469486
r = @schema.select_first(

lib/plsql/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def raw_connection=(raw_conn) # :nodoc:
4141
# or
4242
#
4343
# plsql.connection = java.sql.DriverManager.getConnection(
44-
# "jdbc:oracle:thin:@#{database_host}:#{database_port}/#{database_service_name}",
44+
# "jdbc:oracle:thin:@//#{database_host}:#{database_port}/#{database_service_name}",
4545
# database_user, database_password)
4646
#
4747
def connection=(conn)

lib/plsql/variable.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def find(schema, variable, package, override_schema_name = nil)
99
AND type = 'PACKAGE'
1010
AND UPPER(text) LIKE :variable_name",
1111
override_schema_name || schema.schema_name, package, "%#{variable_upcase}%").each do |row|
12-
if row[0] =~ /^\s*#{variable_upcase}\s+(CONSTANT\s+)?([A-Z0-9_. %]+(\([\w\s,]+\))?)\s*(NOT\s+NULL)?\s*((:=|DEFAULT).*)?;\s*(--.*)?$/i
12+
if row[0] =~ /^\s*#{variable_upcase}\s+(CONSTANT\s+)?([A-Z0-9_. %]+(\([\w\s,]+\))?)\s*(NOT\s+NULL)?\s*((:=|DEFAULT).*)?;\s*(--.*)?$/i ||
13+
row[0] =~ /^\s*#{variable_upcase}\s+(CONSTANT\s+)?([A-Z0-9_. %]+(\([\w\s,]+\))?)\s*(NOT\s+NULL)?\s*(:=|DEFAULT)\s*$/i
1314
return new(schema, variable, package, $2.strip, override_schema_name)
1415
end
1516
end

0 commit comments

Comments
 (0)