Ticket #1224 (closed defect: fixed)

Opened 2 weeks ago

Last modified 1 week ago

[PATCH] Several instances of MySQL-only sql

Reported by: bribera Assigned to: scott
Priority: high Milestone: 5.1
Component: backend Version:
Severity: blocker Keywords: postgresql
Cc: neuro

Description

[1686] added some more MySQL-only syntax to Typo:

  • There are two virtually identical functions in the Page and Article models that get a set of publication dates for menus. This change uses the 'date_format' function in the SELECT clause, but that function only exists in MySQL.
  • There is one instance of backticks (`) being used unnecessarily to quote table names. MySQL doesn't require them in this scenario, and no other database will actually accept them.

Running 'rake' on a fresh copy with a PostgreSQL backend produces several instances of the following:

ActiveRecord::StatementInvalid in 'Admin::ContentController test_list'
PGError: ERROR:  syntax error at or near "."
LINE 1: ...tions.article_id = contents.id   WHERE (`contents`.id > 0) A...

Additionally, hitting /admin/pages and /admin/content produce this SQL error:

PGError: ERROR:  function date_format(timestamp without time zone, "unknown") does not exist
HINT:  No function matches the given name and argument types. You may need to add explicit type casts.
: SELECT date_format(created_at, '%Y-%m') AS publication FROM contents WHERE type = 'Page' GROUP BY publication

This patch resolves all of the above issues.

Before applying this patch, I get 2 PostreSQL-related rake test errors. Both before & after applying it I one rake test error which has nothing to do with these changes:

Test::Unit::AssertionFailedError in 'Admin::UsersController rough port of the old functional test test_edit'
Password doesn't match confirmation.
<false> is not true.
./spec/controllers/admin/users_controller_spec.rb:50:in `test_edit'

Attachments

postgresql_safe_fixes.diff (3.1 kB) - added by bribera on 05/02/08 00:29:20.
Remove/quarantine non-generic SQL syntax from models & admin controllers
defined_adapters.diff (1.1 kB) - added by bribera on 05/03/08 08:58:33.
Check for defined adapters in case we don't have one of them.

Change History

05/02/08 00:29:20 changed by bribera

  • attachment postgresql_safe_fixes.diff added.

Remove/quarantine non-generic SQL syntax from models & admin controllers

(follow-up: ↓ 3 ) 05/02/08 02:58:07 changed by sprewell

I get an error when trying to use this patch (maybe cuz I don't have mysql installed?):

uninitialized constant ActiveRecord::ConnectionAdapters::MysqlAdapter?

05/02/08 09:54:03 changed by neuro

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in rev 1694

(in reply to: ↑ 1 ) 05/03/08 08:56:02 changed by bribera

  • status changed from closed to reopened.
  • resolution deleted.

Replying to sprewell:

I get an error when trying to use this patch (maybe cuz I don't have mysql installed?): uninitialized constant ActiveRecord::ConnectionAdapters::MysqlAdapter?

That's weird -- I thought Rails shipped with these adapters by default. In any case, this new patch with *defined?()* checks should take care of instances without certain adapters.

05/03/08 08:58:33 changed by bribera

  • attachment defined_adapters.diff added.

Check for defined adapters in case we don't have one of them.

05/03/08 21:04:35 changed by neuro

  • status changed from reopened to closed.
  • resolution set to fixed.

Definitely fixed in rev 1695.