[Rt-commit] rt branch, 4.2/indexes-management-case-sensitivity, created. rt-4.1.23-1-g8573c62
Ruslan Zakirov
ruz at bestpractical.com
Mon Sep 16 13:00:59 EDT 2013
The branch, 4.2/indexes-management-case-sensitivity has been created
at 8573c6271efd4a9986ba7df8bcde3620d773a4bd (commit)
- Log -----------------------------------------------------------------
commit 8573c6271efd4a9986ba7df8bcde3620d773a4bd
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Mon Sep 16 20:59:26 2013 +0400
make index management code case insensitive
with mysql on some systems table name in DDL queries
is case sensitive.
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 0d7440b..c9a5c54 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1464,6 +1464,7 @@ sub DropIndex {
my $res;
if ( $db_type eq 'mysql' ) {
+ $args{'Table'} = $self->_CanonicTableNameMysql( $args{'Table'} );
$res = $dbh->do(
'drop index '. $dbh->quote_identifier($args{'Name'}) ." on $args{'Table'}",
);
@@ -1485,6 +1486,20 @@ sub DropIndex {
return ($res, $res? "Dropped $desc" : "Couldn't drop $desc: ". $dbh->errstr);
}
+sub _CanonicTableNameMysql {
+ my $self = shift;
+ my $table = shift;
+ return $table unless $table;
+ # table name can be case sensitivity in DDL
+ # use LOWER to workaround mysql "bug"
+ return ($self->dbh->selectrow_array(
+ 'SELECT table_name
+ FROM information_schema.tables
+ WHERE table_schema = ? AND LOWER(table_name) = ?',
+ undef, scalar RT->Config->Get('DatabaseName'), lc $table
+ ))[0] || $table;
+}
+
sub DropIndexIfExists {
my $self = shift;
my %args = (Table => undef, Name => undef, @_);
@@ -1500,6 +1515,9 @@ sub CreateIndex {
my $self = shift;
my %args = ( Table => undef, Name => undef, Columns => [], CaseInsensitive => {}, @_ );
+ $args{'Table'} = $self->_CanonicTableNameMysql( $args{'Table'} )
+ if RT->Config->Get('DatabaseType') eq 'mysql';
+
my $name = $args{'Name'};
unless ( $name ) {
my %indexes = $self->Indexes;
diff --git a/t/api/db_indexes.t b/t/api/db_indexes.t
index 8453804..947a59c 100644
--- a/t/api/db_indexes.t
+++ b/t/api/db_indexes.t
@@ -123,4 +123,47 @@ note "test ->CreateIndex and ->IndexesThatBeginWith methods";
ok $status, $msg;
}
+note "Test some cases sensitivity aspects";
+{
+ {
+ my %res = $handle->IndexInfo( Table => 'groupmembers', Name => 'groupmembers1' );
+ is_deeply(
+ \%res,
+ {
+ Table => 'groupmembers', Name => 'groupmembers1',
+ Unique => 1, Functional => 0,
+ Columns => ['groupid', 'memberid']
+ }
+ );
+ }
+
+ {
+ my ($status, $msg) = $handle->DropIndex( Table => 'groupmembers', Name => 'groupmembers1' );
+ ok $status, $msg;
+
+ my %indexes = $handle->Indexes;
+ ok !grep $_ eq 'groupmembers1', @{ $indexes{'groupmembers'} };
+ }
+
+ {
+ my ($name, $msg) = $handle->CreateIndex(
+ Table => 'groupmembers', Name => 'groupmembers1',
+ Unique => 1,
+ Columns => ['groupid', 'memberid']
+ );
+ ok $name, $msg;
+
+ my %indexes = $handle->Indexes;
+ ok grep $_ eq 'groupmembers1', @{ $indexes{'groupmembers'} };
+ }
+
+ {
+ my ($status, $msg) = $handle->DropIndexIfExists( Table => 'groupmembers', Name => 'groupmembers1' );
+ ok $status, $msg;
+
+ my %indexes = $handle->Indexes;
+ ok !grep $_ eq 'groupmembers1', @{ $indexes{'groupmembers'} };
+ }
+}
+
done_testing();
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list