datamapper / dm-oracle-adapter Goto Github PK
View Code? Open in Web Editor NEWOracle Adapter for DataMapper
Home Page: http://datamapper.org/
License: MIT License
Oracle Adapter for DataMapper
Home Page: http://datamapper.org/
License: MIT License
OJDBC needs URIs in form of:
jdbc:oracle:thin:@[Host][:Port]/SID
The Problem is the @
character in the URIs which is required in the ODJBC URIs. It is present in the URI if you specify a Host.
Examples (JDBC-URI visible by accessing the do_jdbc Connection directly):
DataMapper.setup(:default, {:adapter => "oracle", :database => "MY_SID"})
# => JdbcURI: "jdbc:oracle:thin:MY_SID" (lacking the "@")
DataMapper.setup(:default, {:adapter => "oracle", :database => "@MY_SID"})
# => JdbcURI: "jdbc:oracle:thin:@MY_SID" (Yay!)
The last Hack seems to do the trick, BUT DataMapper seems to find the "@" in it's internal DM-URI and is assuming the credentials are already specified somewhere else. So it will ignore the :username and :password parameters seen in the following example:
DataMapper.setup(:default, {:adapter => "oracle", :database => "@MY_SID", :username => "SCOTT", :password => "TIGER"})
# No Username and password arriving in do_jdbc Connection
DataMapper.setup(:default, {:adapter => "oracle", :database => "SCOTT/TIGER@MY_SID"})
# Works! But I hate it :-)
For completeness reasons the jdbc URI with :host parameter:
DataMapper.setup(:default, {:adapter => "oracle", :database => "MY_SID", :host => "localhost", :username => "SCOTT", :password => "TIGER"})
# => JdbcURI: "jdbc:oracle:thin:@//localhost/MY_SID" (looks a bit strange but works)
See https://github.com/datamapper/dm-oracle-adapter/issues#issue/2
Created by Martin Gamsjaeger (snusnu) - 2011-03-30 14:33:26 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1501
When you want ojdbc to use a database specified in TNSNAMES.ora you'll have to specify the location of the TNSNAMES.ora file:
if RUBY_PLATFORM =~ /java/
java.lang.System.setProperty("oracle.net.tns_admin", "/opt/oracle/network/admin")
end
This must be done in the application somewhere.
AFAIK @rsim's oracle-enhanced adapter for ActiveRecord is doing this in the adapter by looking at an environment variable called "TNS_ADMIN" (which is used by sqlplus to locate the TNSNAMES.ora).
I'm running ruby 2.0 on Mac,
here's the Gemfile:
gem 'sinatra'
gem 'thin'
~ #gem 'dm-postgres-adapter'
and because I couldn't find README file I setup like this:
DataMapper.setup(:default, 'oracle://system:manager@localhost:1521/XE')
Hi,
I'm using DataMapper and dm-oracle-adapter. I have a table at Oracle like this:
ID_ICON NOT NULL NUMBER(3)
ICON_PT VARCHAR2(200)
STATUS NUMBER(1)
ID_ICON is the Primary Key.
So, I have a model like this:
class Icon
include DataMapper::Resource
storage_names[:default] = "icon"
property :id, Serial, :field => 'id_icon'
property :icon_pt, String
property :icon_es, String
property :icon_en, String
property :status, Integer
end
Supose that I have a registry at this table with ID 1. When I try to find it, like this:
@icon = Icon.get(1)
It simply can't find that record!
But the record is there:
Icon.all
=> [#<Icon @id=1 @icon_pt="a" @icon_es="b" @icon_en="c" @status=2>]
This is the query that the server is doing:
SQL (3.920ms) SELECT "ID_ICON", "ICON_PT", "ICON_ES", "ICON_EN", "STATUS" FROM "ICON" WHERE ("ID_ICON" = :1) AND rownum <= :2
What Am I missing?
Thank you in advance.
Hi,
I found a (known) problem with Oracle and was asked in the Datamapper IRC channel to report it here. Even though it's Oracle at fault, perhaps you could create a work-around for it.
Here's an example of the issue demonstrated in the Ruby console:
irb(main):011:0* Item.count
=> 76
irb(main):012:0> Item.count(:serial => 'asdf')
=> 1
irb(main):013:0> Item.count(:serial.not => 'asdf')
=> 75
irb(main):014:0> Item.count(:serial => '')
=> 0
irb(main):015:0> Item.count(:serial.not => '')
=> 0
As you can see, counting the records works when a proper string is specified. However, when the string is empty the count is always 0. As this is not a problem with Datamapper, it can be reproduced with SQL as well. Here's an example:
SQL> select count() from items;
76
SQL> select count() from items where serial='asdf';
1
SQL> select count() from items where not(serial='asdf');
75
SQL> select count() from items where serial='';
0
SQL> select count(*) from items where not(serial='');
0
Using != or <> works the same way.
The database version is Oracle Database 10g Release 10.2.0.1.0 - 64bit Production, but this is probably an issue with other versions as well. The problem exists in other finder methods as well, such as .all. The problem stems from Oracle treating an empty string as null. Googling reveals more information: http://www.google.com/search?q=oracle+empty+string+null
Consider this:
class Post
include DataMapper::Resource
property :id, Serial
property :user_id, Integer
property :created_at, Time
end
Post.all(:user_id => 123, :order => [:created_at]).to_a
The generated sql will look like this:
SELECT "ID", "USER_ID", "CREATED_AT" FROM "POSTS" WHERE ("USER_ID" = :1)
The order by clause has gone missing.
Here is what I'm able to track down:
At https://github.com/datamapper/dm-oracle-adapter/blob/master/lib/dm-oracle-adapter/adapter.rb#L121
no_order
is set to true and the thus the order by clause is never generated.
I don't fully understand
https://github.com/datamapper/dm-oracle-adapter/blob/master/lib/dm-oracle-adapter/adapter.rb#L108
and
https://github.com/datamapper/dm-oracle-adapter/blob/master/lib/dm-oracle-adapter/adapter.rb#L117
But from the comment, I think it is only for some special cases where only one record is needed?
If you could help me understand what those two conditional statements mean, I don't mind working on a fix for this.
Thanks!
AQ
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.