Skip Menu |

This queue is for tickets about the SQL-Translator CPAN distribution.

Report information
The Basics
Id: 65844
Status: resolved
Priority: 0/
Queue: SQL-Translator

People
Owner: Nobody in particular
Requestors: bellaire [...] ufl.edu
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.11011



Subject: return scalar ref for default current_timestamp regardless of case
Sqlt-parser-mysql is written to parse a default value of 'CURRENT_TIMESTAMP' and return it as a ref in column_info, per the following entry from the changelog: # ---------------------------------------------------------- # 0.09002 2008-12-05 # ---------------------------------------------------------- * parsing MySQL CURRENT_TIMESTAMP as scalar ref so it can be produced without quotes (jgoulah) However this logic fails if the SQL is written in lower case. This will cause spurious diffs against columns with a default of 'current_timestamp', for example when using with dbix-class for migrations. This patch fixes the parser so that it matches current_timestamp for defaults in a case-insensitive manner, and stores them as a ref in column info in either case.
Subject: sqlt-parser-mysql-current-timestamp.patch
diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 60a8602..531be84 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -484,7 +484,7 @@ field_qualifier : /collate/i WORD } } -field_qualifier : /on update/i 'CURRENT_TIMESTAMP' +field_qualifier : /on update/i /\bCURRENT_TIMESTAMP\b/i { $return = { 'ON UPDATE' => $item[2],
From: bellaire [...] ufl.edu
Sorry, uploaded the wrong file. Previous patch is broken, this one is correct.
Subject: sqlt-parser-mysql-current-timestamp.patch
diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 60a8602..b480d82 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -595,7 +595,7 @@ not_null : /not/i /null/i unsigned : /unsigned/i { $return = 0 } default_val : - /default/i 'CURRENT_TIMESTAMP' + /default/i /\bCURRENT_TIMESTAMP\b/i { $return = \$item[2]; }
Patch is sensible, but please also add tests to ensure this keeps working in the future. t/02mysql-parser.t already tests this around line 480, simply add variations with different casing and whatnot. Also the \b part of the regex seems odd - if CURRENT_TIMESTAMP is quoted it is no longer a function no?
On Thu Feb 17 12:03:35 2011, bellaire@ufl.edu wrote: Show quoted text
> Sqlt-parser-mysql is written to parse a default value of > 'CURRENT_TIMESTAMP' and return it as a ref in column_info, per the > following entry from the changelog: > > # ---------------------------------------------------------- > # 0.09002 2008-12-05 > # ---------------------------------------------------------- > * parsing MySQL CURRENT_TIMESTAMP as scalar ref so it can be produced > without quotes (jgoulah) > > However this logic fails if the SQL is written in lower case. This > will cause spurious diffs against columns with a default of > 'current_timestamp', for example when using with dbix-class for
migrations. Show quoted text
> > This patch fixes the parser so that it matches current_timestamp for > defaults in a case-insensitive manner, and stores them as a ref in > column info in either case.
Sanified parser based on your idea (your patch was *not* used). Cheers! http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/SQL-Translator.git;a=commitdiff;h=0a2833d8ee24159420d7cb9a5b4184e4d0eb5b1a