Created
February 7, 2011 15:03
-
-
Save praveend/814491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 0c3e07e35581052c2058fdc835a05e085c9b8af0 Mon Sep 17 00:00:00 2001 | |
From: Praveen Devarao <praveendrl@in.ibm.com> | |
Date: Mon, 7 Feb 2011 20:24:36 +0530 | |
Subject: [PATCH] Added visitor ibm_db to handle ibm_db specifics | |
--- | |
lib/arel/visitors.rb | 2 ++ | |
1 files changed, 2 insertions(+), 0 deletions(-) | |
diff --git a/lib/arel/visitors.rb b/lib/arel/visitors.rb | |
index 8410b2b..6370b1b 100644 | |
--- a/lib/arel/visitors.rb | |
+++ b/lib/arel/visitors.rb | |
@@ -6,6 +6,7 @@ require 'arel/visitors/postgresql' | |
require 'arel/visitors/mysql' | |
require 'arel/visitors/mssql' | |
require 'arel/visitors/oracle' | |
+require 'arel/visitors/ibm_db' | |
require 'arel/visitors/join_sql' | |
require 'arel/visitors/where_sql' | |
require 'arel/visitors/order_clauses' | |
@@ -22,6 +23,7 @@ module Arel | |
'oracle_enhanced' => Arel::Visitors::Oracle, | |
'sqlite' => Arel::Visitors::SQLite, | |
'sqlite3' => Arel::Visitors::SQLite, | |
+ 'ibm_db' => Arel::Visitors::IbmDB, | |
} | |
ENGINE_VISITORS = Hash.new do |hash, engine| | |
-- | |
1.6.0 | |
From 6228ece599f06450e6369e21efaf2d8ec75d6036 Mon Sep 17 00:00:00 2001 | |
From: Praveen Devarao <praveendrl@in.ibm.com> | |
Date: Mon, 7 Feb 2011 20:29:53 +0530 | |
Subject: [PATCH] Added visitor ibm_db to handle ibm_db specifics | |
--- | |
lib/arel/visitors/ibm_db.rb | 52 +++++++++++++++++++++++++++++++++++++++++++ | |
1 files changed, 52 insertions(+), 0 deletions(-) | |
create mode 100644 lib/arel/visitors/ibm_db.rb | |
diff --git a/lib/arel/visitors/ibm_db.rb b/lib/arel/visitors/ibm_db.rb | |
new file mode 100644 | |
index 0000000..6e2ebcd | |
--- /dev/null | |
+++ b/lib/arel/visitors/ibm_db.rb | |
@@ -0,0 +1,52 @@ | |
+# +-----------------------------------------------------------------------+ | |
+# | | | |
+# | Copyright (c) 2011 IBM Corporation | | |
+# | | | |
+# | Permission is hereby granted, free of charge, to any person obtaining | | |
+# | a copy of this software and associated documentation files (the | | |
+# | "Software"), to deal in the Software without restriction, including | | |
+# | without limitation the rights to use, copy, modify, merge, publish, | | |
+# | distribute, sublicense, and/or sell copies of the Software, and to | | |
+# | permit persons to whom the Software is furnished to do so, subject to | | |
+# | the following conditions: | | |
+# | | | |
+# | The above copyright notice and this permission notice shall be | | |
+# | included in all copies or substantial portions of the Software. | | |
+# | | | |
+# | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | | |
+# | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | | |
+# | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.| | |
+# | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR | | |
+# | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | | |
+# | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | | |
+# | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | | |
+# | | | |
+# +-----------------------------------------------------------------------+ | |
+ | |
+# | |
+# Author: Praveen Devarao <praveendrl@in.ibm.com> | |
+# | |
+ | |
+module Arel | |
+ module Visitors | |
+ class IbmDB < Arel::Visitors::ToSql | |
+ def visit_Arel_Nodes_SelectStatement o | |
+ limit = offset = nil | |
+ sqlSegment = [ | |
+ o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join, | |
+ ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?), | |
+ ].compact.join ' ' | |
+ | |
+ # Add limit offset segments | |
+ limit = o.limit.expr if o.limit | |
+ offset = o.offset.expr if o.offset | |
+ @engine.connection.add_limit_offset!(sqlSegment,{:limit=>limit,:offset=>offset}) | |
+ | |
+ # Append lock clause and join | |
+ [ sqlSegment, | |
+ (visit(o.lock) if o.lock), | |
+ ].compact.join ' ' | |
+ end | |
+ end | |
+ end | |
+end | |
-- | |
1.6.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment