Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
f7dfa43d
Commit
f7dfa43d
authored
Apr 17, 2005
by
mkanat%kerio.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 290407: Fix up bz_alter_column and break out a bz_alter_column_raw
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=Tomas.Kopal, a=justdave
parent
f18c6f0b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
22 deletions
+46
-22
DB.pm
Bugzilla/DB.pm
+46
-22
No files found.
Bugzilla/DB.pm
View file @
f7dfa43d
...
...
@@ -363,38 +363,62 @@ sub bz_add_column {
sub
bz_alter_column
{
my
(
$self
,
$table
,
$name
,
$new_def
)
=
@_
;
# You can't change a column to be NOT NULL if you have no DEFAULT,
# if there are any NULL values in that column.
if
(
$new_def
->
{
NOTNULL
}
&&
!
exists
$new_def
->
{
DEFAULT
})
{
# Check for NULLs
my
$any_nulls
=
$self
->
selectrow_array
(
"SELECT 1 FROM $table WHERE $name IS NULL"
);
if
(
$any_nulls
)
{
die
"You cannot alter the ${table}.${name} column to be NOT NULL"
.
" without\nspecifying a default, because there are NULL"
.
" values currently in it."
;
}
}
my
$current_def
=
$self
->
bz_column_info
(
$table
,
$name
);
if
(
!
$self
->
_bz_schema
->
columns_equal
(
$current_def
,
$new_def
))
{
my
@statements
=
$self
->
_bz_real_schema
->
get_alter_column_ddl
(
$table
,
$name
,
$new_def
);
my
$old_ddl
=
$self
->
_bz_schema
->
get_type_ddl
(
$current_def
);
my
$new_ddl
=
$self
->
_bz_schema
->
get_type_ddl
(
$new_def
);
print
"Updating column $name in table $table ...\n"
;
print
"Old: $old_ddl\n"
;
print
"New: $new_ddl\n"
;
foreach
my
$sql
(
@statements
)
{
$self
->
do
(
$sql
);
# You can't change a column to be NOT NULL if you have no DEFAULT,
# if there are any NULL values in that column.
if
(
$new_def
->
{
NOTNULL
}
&&
!
exists
$new_def
->
{
DEFAULT
})
{
# Check for NULLs
my
$any_nulls
=
$self
->
selectrow_array
(
"SELECT 1 FROM $table WHERE $name IS NULL"
);
if
(
$any_nulls
)
{
die
"You cannot alter the ${table}.${name} column to be"
.
" NOT NULL without\nspecifying a default, because"
.
" there are NULL values currently in it."
;
}
}
$self
->
bz_alter_column_raw
(
$table
,
$name
,
$new_def
,
$current_def
);
$self
->
_bz_real_schema
->
set_column
(
$table
,
$name
,
$new_def
);
$self
->
_bz_store_real_schema
;
}
}
# bz_alter_column_raw($table, $name, $new_def, $current_def)
#
# Description: A helper function for bz_alter_column.
# Alters a column in the database
# without updating any Schema object. Generally
# should only be called by bz_alter_column.
# Used when either: (1) You don't yet have a Schema
# object but you need to alter a column, for some reason.
# (2) You need to alter a column for some database-specific
# reason.
# Params: $table - The name of the table the column is on.
# $name - The name of the column you're changing.
# $new_def - The abstract definition that you are changing
# this column to.
# $current_def - (optional) The current definition of the
# column. Will be used in the output message,
# if given.
# Returns: nothing
#
sub
bz_alter_column_raw
{
my
(
$self
,
$table
,
$name
,
$new_def
,
$current_def
)
=
@_
;
my
@statements
=
$self
->
_bz_real_schema
->
get_alter_column_ddl
(
$table
,
$name
,
$new_def
);
my
$new_ddl
=
$self
->
_bz_schema
->
get_type_ddl
(
$new_def
);
print
"Updating column $name in table $table ...\n"
;
if
(
defined
$current_def
)
{
my
$old_ddl
=
$self
->
_bz_schema
->
get_type_ddl
(
$current_def
);
print
"Old: $old_ddl\n"
;
}
print
"New: $new_ddl\n"
;
$self
->
do
(
$_
)
foreach
(
@statements
);
}
# XXX - Need to make this cross-db compatible
# XXX - This shouldn't print stuff to stdout
sub
bz_add_field
($$$)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment