Hi,
I Just upgraded from 0.3.3 to 0.3.4.1 and now when I use a join, the
quoting is wrong. It seems that sequel sends the
qualified table names to be quoted, which results in this:
table.`column` being turned into this: `table.`column``.
Tyring to track down where it happens, I'm narrowed it down to the
'fmt = expr.to_a.sort_by { |k, v| k.to_s }.map {|i| compare_expr(i[0],
i[1])}.join(AND_SEPARATOR)'
in expression_list in dataset/sql.rb Line 115 in the file I'm looking
at. doing an expr.inspect before, and a fmt.inspect after,
results in these two outputs:
{:"elements_pages.`element_id`"=>:"elements.`id`"}
"(`elements_pages.`element_id`` = `elements.`id``)"
I suspect it's because each of those are a symbol, which means that
compare_expr (Or rather literal) runs them through the
'quote_column_ref' function one more time
resulting in the incorrect SQL.
As far as I can see, this would only be a problem for MySQL, but until
it's resolved, I'm going to need to revert back to 0.3.3.
Is everything I've said non-sense and I've just done something really
stupid? Or should I raise an issue for this? I've included a simple
example below that will cause the above to happen. Or at least it does
on my system.
(MySQL 5.0.45, MySQL gem 2.7.4, ruby 1.8-111) All compiled on my
system.
-----------
SCHEMA
-----------
CREATE TABLE `pages` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`code` VARCHAR(255) NOT NULL,
`name` VARCHAR(255) NOT NULL
);
CREATE TABLE `elements` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`code` VARCHAR(255) NOT NULL,
`name` VARCHAR(255) NOT NULL
);
CREATE TABLE `elements_pages` (
`element_id` INT UNSIGNED NOT NULL,
`page_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (element_id, page_id),
INDEX (`element_id`),
INDEX (`page_id`)
)
INSERT INTO `elements` (`id`, `code`, `name`) VALUES (1, 'element1',
'element1'), (2, 'element2', 'element2');
INSERT INTO `pages` (`id`, `code`, `name`) VALUES (1, 'page1',
'page1'), (2, 'page2', 'page2');
INSERT INTO `elements_pages` (`element_id`, `page_id`) VALUES ('1',
'1'), ('1', '2');
-----------
RUBY
-----------
require 'rubygems'
require 'sequel'
require 'sequel/mysql'
require 'logger'
log = Logger.new(STDOUT)
log.level = Logger::DEBUG
DB = Sequel::MySQL::Database.new({:database => 'test', :user =>
'root', :password => '[EMAIL PROTECTED]', :logger => log})
elements = DB[:elements]
elements.join(:elements_pages, :element_id => :id).all
-----------
RESULT (Logger only)
-----------
INFO -- : SELECT * FROM elements INNER JOIN elements_pages ON
(`elements_pages.`element_id`` = `elements.`id``)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---