Commit f6753fea authored by Vitaly Lipatov's avatar Vitaly Lipatov

quota groups table and all $table

parent d1112823
......@@ -3995,7 +3995,7 @@ sub groups {
. " THEN 1 ELSE 0 END,"
. " CASE WHEN groups.id IN($grouplist) THEN 1 ELSE 0 END,"
. " isactive, membercontrol, othercontrol"
. " FROM groups"
. " FROM `groups`"
. " LEFT JOIN bug_group_map"
. " ON bug_group_map.group_id = groups.id"
. " AND bug_id = ?"
......
......@@ -700,7 +700,7 @@ sub bz_alter_column {
{
# Check for NULLs
my $any_nulls
= $self->selectrow_array("SELECT 1 FROM $table WHERE $name IS NULL");
= $self->selectrow_array("SELECT 1 FROM `$table` WHERE $name IS NULL");
ThrowCodeError('column_not_null_no_default_alter', {name => "$table.$name"})
if ($any_nulls);
}
......@@ -1121,7 +1121,7 @@ sub bz_rename_table {
sub bz_set_next_serial_value {
my ($self, $table, $column, $value) = @_;
if (!$value) {
$value = $self->selectrow_array("SELECT MAX($column) FROM $table") || 0;
$value = $self->selectrow_array("SELECT MAX($column) FROM `$table`") || 0;
$value++;
}
my @sql = $self->_bz_real_schema->get_set_serial_sql($table, $column, $value);
......@@ -1520,7 +1520,7 @@ sub _check_references {
# reserved words.
my $bad_values = $self->selectcol_arrayref(
"SELECT DISTINCT tabl.$column
FROM $table AS tabl LEFT JOIN $foreign_table AS forn
FROM `$table` AS tabl LEFT JOIN $foreign_table AS forn
ON tabl.$column = forn.$foreign_column
WHERE forn.$foreign_column IS NULL
AND tabl.$column IS NOT NULL"
......@@ -1530,7 +1530,7 @@ sub _check_references {
my $delete_action = $fk->{DELETE} || '';
if ($delete_action eq 'CASCADE') {
$self->do(
"DELETE FROM $table WHERE $column IN (" . join(',', ('?') x @$bad_values) . ")",
"DELETE FROM `$table` WHERE $column IN (" . join(',', ('?') x @$bad_values) . ")",
undef, @$bad_values
);
if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE) {
......@@ -1551,7 +1551,7 @@ sub _check_references {
}
elsif ($delete_action eq 'SET NULL') {
$self->do(
"UPDATE $table SET $column = NULL
"UPDATE `$table` SET $column = NULL
WHERE $column IN ("
. join(',', ('?') x @$bad_values) . ")", undef, @$bad_values
);
......
......@@ -700,7 +700,7 @@ sub bz_setup_database {
print "Converting table storage format to UTF-8. This may take a", " while.\n";
foreach my $table ($self->bz_table_list_real) {
my $info_sth = $self->prepare("SHOW FULL COLUMNS FROM $table");
my $info_sth = $self->prepare("SHOW FULL COLUMNS FROM `$table`");
$info_sth->execute();
my (@binary_sql, @utf8_sql);
while (my $column = $info_sth->fetchrow_hashref) {
......@@ -980,7 +980,7 @@ sub _bz_raw_column_info {
sub bz_index_info_real {
my ($self, $table, $index) = @_;
my $sth = $self->prepare("SHOW INDEX FROM $table");
my $sth = $self->prepare("SHOW INDEX FROM `$table`");
$sth->execute;
my @fields;
......@@ -1028,7 +1028,7 @@ sub bz_index_info_real {
sub bz_index_list_real {
my ($self, $table) = @_;
my $sth = $self->prepare("SHOW INDEX FROM $table");
my $sth = $self->prepare("SHOW INDEX FROM `$table`");
# Column 3 of a SHOW INDEX statement contains the name of the index.
return @{$self->selectcol_arrayref($sth, {Columns => [3]})};
......
......@@ -2282,7 +2282,7 @@ sub get_add_column_ddl {
# XXX - Note that although this works for MySQL, most databases will fail
# before this point, if we haven't set a default.
(push(@statements, "UPDATE $table SET $column = $init_value"))
(push(@statements, "UPDATE `$table` SET $column = $init_value"))
if defined $init_value;
if (defined $definition->{REFERENCES}) {
......@@ -2427,7 +2427,7 @@ sub _set_nulls_sql {
}
my @sql;
if (defined $default) {
push(@sql, "UPDATE $table SET $column = $default" . " WHERE $column IS NULL");
push(@sql, "UPDATE `$table` SET $column = $default" . " WHERE $column IS NULL");
}
return @sql;
}
......
......@@ -191,7 +191,7 @@ sub get_alter_column_ddl {
my @statements;
push(
@statements, "UPDATE $table SET $column = $set_nulls_to
@statements, "UPDATE `$table` SET $column = $set_nulls_to
WHERE $column IS NULL"
) if defined $set_nulls_to;
......@@ -385,7 +385,7 @@ sub column_info_to_column {
# Unfortunately, the only way to do this in DBI is to query the
# database, so we have to break the rule here that Schema normally
# doesn't touch the live DB.
my $ref_sth = $dbh->prepare("SELECT $col_name FROM $table LIMIT 1");
my $ref_sth = $dbh->prepare("SELECT $col_name FROM `$table` LIMIT 1");
$ref_sth->execute;
if ($ref_sth->{mysql_is_auto_increment}->[0]) {
if ($type eq 'MEDIUMINT') {
......
......@@ -440,7 +440,7 @@ sub create {
sub ValidateGroupName {
my ($name, @users) = (@_);
my $dbh = Bugzilla->dbh;
my $query = "SELECT id FROM groups " . "WHERE name = ?";
my $query = "SELECT id FROM `groups` " . "WHERE name = ?";
if (Bugzilla->params->{'usevisibilitygroups'}) {
my @visible = (-1);
foreach my $user (@users) {
......
......@@ -1025,7 +1025,7 @@ sub _add_unique_login_name_index_to_profiles {
my ($table, $field) = (@$i);
if ($dbh->bz_table_info($table)) {
print " Updating $table.$field...\n";
$dbh->do("UPDATE $table SET $field = $u1 " . "WHERE $field = $u2");
$dbh->do("UPDATE `$table` SET $field = $u1 " . "WHERE $field = $u2");
}
}
$dbh->do("DELETE FROM profiles WHERE userid = $u2");
......@@ -1651,7 +1651,7 @@ sub _convert_groups_system_from_groupset {
# Convert all existing groupset records to map entries before removing
# groupset fields or removing "bit" from groups.
my $sth = $dbh->prepare("SELECT bit, id FROM groups WHERE bit > 0");
my $sth = $dbh->prepare("SELECT bit, id FROM `groups` WHERE bit > 0");
$sth->execute();
while (my ($bit, $gid) = $sth->fetchrow_array) {
......@@ -1746,7 +1746,7 @@ sub _convert_groups_system_from_groupset {
# Get names of groups added.
my $sth2 = $dbh->prepare(
"SELECT name FROM groups
"SELECT name FROM `groups`
WHERE (bit & $added) != 0
AND (bit & $removed) = 0"
);
......@@ -1758,7 +1758,7 @@ sub _convert_groups_system_from_groupset {
# Get names of groups removed.
$sth2 = $dbh->prepare(
"SELECT name FROM groups
"SELECT name FROM `groups`
WHERE (bit & $removed) != 0
AND (bit & $added) = 0"
);
......@@ -1772,7 +1772,7 @@ sub _convert_groups_system_from_groupset {
# missing groups.
$sth2 = $dbh->prepare(
"SELECT ($added & ~BIT_OR(bit))
FROM groups"
FROM `groups`"
);
$sth2->execute();
my ($miss) = $sth2->fetchrow_array;
......@@ -1786,7 +1786,7 @@ sub _convert_groups_system_from_groupset {
# missing groups.
$sth2 = $dbh->prepare(
"SELECT ($removed & ~BIT_OR(bit))
FROM groups"
FROM `groups`"
);
$sth2->execute();
($miss) = $sth2->fetchrow_array;
......@@ -1823,7 +1823,7 @@ sub _convert_groups_system_from_groupset {
# Get names of groups added.
my $sth2 = $dbh->prepare(
"SELECT name FROM groups
"SELECT name FROM `groups`
WHERE (bit & $added) != 0
AND (bit & $removed) = 0"
);
......@@ -1835,7 +1835,7 @@ sub _convert_groups_system_from_groupset {
# Get names of groups removed.
$sth2 = $dbh->prepare(
"SELECT name FROM groups
"SELECT name FROM `groups`
WHERE (bit & $removed) != 0
AND (bit & $added) = 0"
);
......@@ -1864,7 +1864,7 @@ sub _convert_groups_system_from_groupset {
# Identify admin group.
my ($admin_gid)
= $dbh->selectrow_array("SELECT id FROM groups WHERE name = 'admin'");
= $dbh->selectrow_array("SELECT id FROM `groups` WHERE name = 'admin'");
if (!$admin_gid) {
$dbh->do(q{INSERT INTO groups (name, description)
VALUES ('admin', 'Administrators')}
......@@ -2134,7 +2134,7 @@ sub _setup_usebuggroups_backward_compatibility {
my $sth = $dbh->prepare(
"SELECT groups.id, products.id, groups.name,
products.name
FROM groups, products
FROM `groups`, products
WHERE isbuggroup != 0"
);
$sth->execute();
......@@ -2495,7 +2495,7 @@ sub _fix_group_with_empty_name {
# Note that there can be at most one such group (because of
# the SQL index on the name column).
my ($emptygroupid)
= $dbh->selectrow_array("SELECT id FROM groups where name = ''");
= $dbh->selectrow_array("SELECT id FROM `groups` where name = ''");
if ($emptygroupid) {
# There is a group with an empty name; find a name to rename it
......@@ -2503,7 +2503,7 @@ sub _fix_group_with_empty_name {
# group_$gid and add _<n> if necessary.
my $trycount = 0;
my $trygroupname;
my $sth = $dbh->prepare("SELECT 1 FROM groups where name = ?");
my $sth = $dbh->prepare("SELECT 1 FROM `groups` where name = ?");
my $name_exists = 1;
while ($name_exists) {
......@@ -2948,7 +2948,7 @@ sub _rederive_regex_groups {
my $dbh = Bugzilla->dbh;
my $regex_groups_exist = $dbh->selectrow_array(
"SELECT 1 FROM groups WHERE userregexp = '' " . $dbh->sql_limit(1));
"SELECT 1 FROM `groups` WHERE userregexp = '' " . $dbh->sql_limit(1));
return if !$regex_groups_exist;
my $regex_derivations
......@@ -4154,13 +4154,13 @@ sub _fix_flagclusions_indexes {
# Remove duplicated entries
my $dupes = $dbh->selectall_arrayref("
SELECT type_id, product_id, component_id, COUNT(*) AS count
FROM $table "
FROM `$table` "
. $dbh->sql_group_by('type_id, product_id, component_id') . "
HAVING COUNT(*) > 1", {Slice => {}});
say "Removing duplicated entries from the '$table' table..." if @$dupes;
foreach my $dupe (@$dupes) {
$dbh->do(
"DELETE FROM $table
"DELETE FROM `$table`
WHERE type_id = ? AND product_id = ? AND component_id = ?",
undef, $dupe->{type_id}, $dupe->{product_id}, $dupe->{component_id}
);
......
......@@ -128,7 +128,7 @@ sub _load_from_db {
$object_data = $dbh->selectrow_hashref(
qq{
SELECT $columns FROM $table
SELECT $columns FROM `$table`
WHERE $id_field = ?}, undef, $id
);
}
......@@ -159,7 +159,7 @@ sub _load_from_db {
map { trick_taint($_) } @values;
$object_data
= $dbh->selectrow_hashref("SELECT $columns FROM $table WHERE $condition",
= $dbh->selectrow_hashref("SELECT $columns FROM `$table` WHERE $condition",
undef, @values);
}
return $object_data;
......@@ -386,7 +386,7 @@ sub _do_list_select {
}
if (!$objects) {
my $sql = "SELECT $cols FROM $table";
my $sql = "SELECT $cols FROM `$table`";
if (defined $where) {
$sql .= " WHERE $where ";
}
......@@ -533,7 +533,7 @@ sub update {
my $columns = join(', ', map {"$_ = ?"} @update_columns);
$dbh->do("UPDATE $table SET $columns WHERE $id_field = ?",
$dbh->do("UPDATE `$table` SET $columns WHERE $id_field = ?",
undef, @values, $self->id)
if @values;
......@@ -565,7 +565,7 @@ sub remove_from_db {
my $dbh = Bugzilla->dbh;
$dbh->bz_start_transaction();
$self->audit_log(AUDIT_REMOVE) if $self->AUDIT_REMOVES;
$dbh->do("DELETE FROM $table WHERE $id_field = ?", undef, $self->id);
$dbh->do("DELETE FROM `$table` WHERE $id_field = ?", undef, $self->id);
$dbh->bz_commit_transaction();
if ($self->USE_MEMCACHED) {
......@@ -645,7 +645,7 @@ sub any_exist {
my $table = $class->DB_TABLE;
my $dbh = Bugzilla->dbh;
my $any_exist
= $dbh->selectrow_array("SELECT 1 FROM $table " . $dbh->sql_limit(1));
= $dbh->selectrow_array("SELECT 1 FROM `$table` " . $dbh->sql_limit(1));
return $any_exist ? 1 : 0;
}
......
......@@ -625,7 +625,7 @@ sub group_controls {
# Include name to the list, to allow us sorting data more easily.
my $query = qq{SELECT id, name, entry, membercontrol, othercontrol,
canedit, editcomponents, editbugs, canconfirm
FROM groups
FROM `groups`
LEFT JOIN group_control_map
ON id = group_id
$where_or_and product_id = ?
......
......@@ -2054,12 +2054,12 @@ sub build_subselect {
# unconditionally, so we return the subselect and let the DB optimizer
# restrict the search based on other search criteria.
my $not = $negate ? "NOT" : "";
return "$outer $not IN (SELECT DISTINCT $inner FROM $table WHERE $cond)";
return "$outer $not IN (SELECT DISTINCT $inner FROM `$table` WHERE $cond)";
}
# Execute subselects immediately to avoid dependent subqueries, which are
# large performance hits on MySql
my $q = "SELECT DISTINCT $inner FROM $table WHERE $cond";
my $q = "SELECT DISTINCT $inner FROM `$table` WHERE $cond";
my $dbh = Bugzilla->dbh;
my $list = $dbh->selectcol_arrayref($q);
return $negate ? "1=1" : "1=2" unless @$list;
......@@ -2484,7 +2484,7 @@ sub _user_nonchanged {
my $table = $first_join->{table};
my $columns = "bug_id";
$columns .= ",isprivate" if @{$first_join->{extra}};
my $new_table = "SELECT DISTINCT $columns FROM $table AS $as $join_sql";
my $new_table = "SELECT DISTINCT $columns FROM `$table` AS $as $join_sql";
$first_join->{table} = "($new_table)";
# We always want to LEFT JOIN the generated table.
......
......@@ -176,7 +176,7 @@ sub rename_field_value {
my %queries = @{
$dbh->selectcol_arrayref(
"SELECT $id_field, query FROM $table WHERE query LIKE ?",
"SELECT $id_field, query FROM `$table` WHERE query LIKE ?",
{Columns => [1, 2]},
"\%$old_sql\%"
)
......@@ -193,7 +193,7 @@ sub rename_field_value {
# boolean charts. Users will have to fix those themselves.
$query =~ s/\bvalue\Q$chart_id\E=\Q$old\E\b/value$chart_id=$new/i;
}
$dbh->do("UPDATE $table SET query = ? WHERE $id_field = ?", undef, $query, $id);
$dbh->do("UPDATE `$table` SET query = ? WHERE $id_field = ?", undef, $query, $id);
Bugzilla->memcached->clear({table => $table, id => $id});
}
......
......@@ -276,7 +276,7 @@ sub GenerateUniqueToken {
$column ||= "token";
my $dbh = Bugzilla->dbh;
my $sth = $dbh->prepare("SELECT 1 FROM $table WHERE $column = ?");
my $sth = $dbh->prepare("SELECT 1 FROM `$table` WHERE $column = ?");
while ($duplicate) {
++$tries;
......
......@@ -1630,7 +1630,7 @@ sub visible_groups_direct {
}
else {
# All groups are visible if usevisibilitygroups is off.
$sth = $dbh->prepare('SELECT id FROM groups');
$sth = $dbh->prepare('SELECT id FROM `groups`');
}
$sth->execute();
......@@ -1694,7 +1694,7 @@ sub derive_regexp_groups {
$sth = $dbh->prepare(
"SELECT id, userregexp, user_group_map.group_id
FROM groups
FROM `groups`
LEFT JOIN user_group_map
ON groups.id = user_group_map.group_id
AND user_group_map.user_id = ?
......
......@@ -48,7 +48,7 @@ sub CheckGroupID {
ThrowUserError("group_not_specified") unless $group_id;
(
detaint_natural($group_id) && Bugzilla->dbh->selectrow_array(
"SELECT id FROM groups WHERE id = ?",
"SELECT id FROM `groups` WHERE id = ?",
undef, $group_id
)
) || ThrowUserError("invalid_group_ID");
......
......@@ -717,7 +717,7 @@ sub userDataToVars {
) THEN 1 ELSE 0 END)
AS derivedmember,
COUNT(directbless.group_id) AS directbless
FROM groups
FROM `groups`
LEFT JOIN user_group_map AS directmember
ON directmember.group_id = id
AND directmember.user_id = ?
......
......@@ -391,7 +391,7 @@ sub DoPermissions {
my $groups
= $dbh->selectall_arrayref(
"SELECT DISTINCT name, description FROM groups WHERE id IN ("
"SELECT DISTINCT name, description FROM `groups` WHERE id IN ("
. $user->groups_as_string
. ") ORDER BY name");
foreach my $group (@$groups) {
......
......@@ -250,7 +250,7 @@ sub get_next_event {
}
}
elsif ($mailto_type == MAILTO_GROUP) {
my $sth = $dbh->prepare("SELECT name FROM groups " . "WHERE id=?");
my $sth = $dbh->prepare("SELECT name FROM `groups` " . "WHERE id=?");
$sth->execute($mailto);
my $groupname = $sth->fetch->[0];
my $group_id = Bugzilla::Group::ValidateGroupName($groupname, $owner);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment