Bugzilla – Attachment 81525 Details for
Bug 21682
Stock Rotation: Update DB is failing with strict_sql_modes ON
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21682: Prequel addition of default_exists
Bug-21682-Prequel-addition-of-defaultexists.patch (text/plain), 2.73 KB, created by
Mark Tompsett
on 2018-10-29 17:05:24 UTC
(
hide
)
Description:
Bug 21682: Prequel addition of default_exists
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2018-10-29 17:05:24 UTC
Size:
2.73 KB
patch
obsolete
>From 5911f43651e1a9907640c79e637b70e5e73ad960 Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >Date: Mon, 29 Oct 2018 16:56:19 +0000 >Subject: [PATCH] Bug 21682: Prequel addition of default_exists > >prove t/db_dependent/Installer.t >perldoc C4::Installer >-- There should be something for default_exists >--- > C4/Installer.pm | 26 +++++++++++++++++++++++++- > t/db_dependent/Installer.t | 5 ++++- > 2 files changed, 29 insertions(+), 2 deletions(-) > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index a1c47149f8..70bde03e38 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -30,7 +30,7 @@ use vars qw(@ISA @EXPORT); > BEGIN { > require Exporter; > @ISA = qw( Exporter ); >- push @EXPORT, qw( foreign_key_exists index_exists column_exists ); >+ push @EXPORT, qw( foreign_key_exists index_exists column_exists default_exists ); > }; > > =head1 NAME >@@ -525,6 +525,15 @@ sub index_exists { > return $exists; > } > >+=head2 default_exists >+ >+ my $default_check = default_exists($table_name,$field_name); >+ >+Determine if a particular field has a default value. >+This is useful to prevent errors when there is no default value to drop. >+ >+=cut >+ > sub column_exists { > my ( $table_name, $column_name ) = @_; > my $dbh = C4::Context->dbh; >@@ -537,6 +546,21 @@ sub column_exists { > return $exists; > } > >+ >+sub default_exists { >+ my ( $table_name, $column_name ) = @_; >+ my $dbh = C4::Context->dbh; >+ my @results = $dbh->selectall_array(qq{SHOW CREATE TABLE $table_name;}); >+ my $table_definition = $results[0][1]; # only 1 result, and the 2nd entry is the definition. >+ my @lines = split /\n/, $table_definition; >+ my @default_lines = grep { /DEFAULT/ } @lines; >+ my $return_value = 0; >+ if ( grep { /\`$column_name\`/ } @default_lines ) { >+ $return_value = 1; >+ } >+ return $return_value; >+} >+ > =head1 AUTHOR > > C4::Installer is a refactoring of logic originally from installer/installer.pl, which was >diff --git a/t/db_dependent/Installer.t b/t/db_dependent/Installer.t >index 0b4cfa2d5b..283600517a 100644 >--- a/t/db_dependent/Installer.t >+++ b/t/db_dependent/Installer.t >@@ -22,7 +22,7 @@ > # Add more tests here!!! > > use Modern::Perl; >-use Test::More tests => 15; >+use Test::More tests => 17; > use Koha::Database; > > BEGIN { >@@ -64,3 +64,6 @@ ok( ! index_exists( 'borrowers', 'xxx'), 'Constraint xxx does not exist' ); > > ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' ); > ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' ); >+ >+ok( default_exists( 'stockrotationrotas', 'cyclical' ), "Stock Rotation's cyclical field has a default" ); >+ok( ! default_exists( 'stockrotationrotas', 'rota_id' ), "Stock Rotation's rota_id field has no default" ); >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21682
:
81280
|
81347
|
81348
|
81525
|
81526
|
81527
|
81528
|
81529
|
81769
|
81770
|
81787
|
81788
|
81815