Revision 03457b5b
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/DBUpgrade2/Base.pm | ||
---|---|---|
41 | 41 |
} |
42 | 42 |
|
43 | 43 |
sub db_query { |
44 |
my ($self, $query, $may_fail) = @_;
|
|
44 |
my ($self, $query, %params) = @_;
|
|
45 | 45 |
|
46 |
return if $self->dbh->do($query); |
|
46 |
return if $self->dbh->do($query, undef, @{ $params{bind} || [] });
|
|
47 | 47 |
|
48 |
$self->db_error($query) unless $may_fail;
|
|
48 |
$self->db_error($query) unless $params{may_fail};
|
|
49 | 49 |
|
50 | 50 |
$self->dbh->rollback; |
51 | 51 |
$self->dbh->begin_work; |
... | ... | |
204 | 204 |
|
205 | 205 |
Outputs an error message C<$message> to the user and aborts execution. |
206 | 206 |
|
207 |
=item C<db_query $query, $may_fail>
|
|
207 |
=item C<db_query $query, %params>
|
|
208 | 208 |
|
209 |
Executes an SQL query. What the method does if the query fails depends |
|
210 |
on C<$may_fail>. If it is falsish then the method will simply die |
|
211 |
outputting the error message via L</db_error>. If C<$may_fail> is |
|
212 |
trueish then the current transaction will be rolled back, a new one |
|
213 |
will be started |
|
209 |
Executes an SQL query. The following parameters are supported: |
|
210 |
|
|
211 |
=over 2 |
|
212 |
|
|
213 |
=item C<may_fail> |
|
214 |
|
|
215 |
What the method does if the query fails depends on this parameter. If |
|
216 |
it is falsish (the default) then the method will simply die outputting |
|
217 |
the error message via L</db_error>. If C<may_fail> is trueish then the |
|
218 |
current transaction will be rolled back, a new one will be started. |
|
219 |
|
|
220 |
=item C<bind> |
|
221 |
|
|
222 |
An optional array reference containing bind parameter for the query. |
|
223 |
|
|
224 |
=back |
|
214 | 225 |
|
215 | 226 |
=item C<execute_script> |
216 | 227 |
|
sql/Pg-upgrade2/USTVA_abstraction.pl | ||
---|---|---|
47 | 47 |
}, |
48 | 48 |
); |
49 | 49 |
|
50 |
$self->db_query("DROP SCHEMA tax CASCADE;", 1); |
|
51 |
map({ $self->db_query($_, 0); } @queries);
|
|
50 |
$self->db_query("DROP SCHEMA tax CASCADE;", may_fail => 1);
|
|
51 |
$self->db_query($_) for @queries;
|
|
52 | 52 |
|
53 | 53 |
return 1; |
54 | 54 |
|
sql/Pg-upgrade2/USTVA_at.pl | ||
---|---|---|
48 | 48 |
q{ DELETE FROM tax.report_variables; }, |
49 | 49 |
); |
50 | 50 |
|
51 |
map({ $self->db_query("DELETE FROM $_ ;", 0); } @clear);
|
|
51 |
$self->db_query("DELETE FROM $_") for @clear;
|
|
52 | 52 |
|
53 | 53 |
return 1; |
54 | 54 |
|
... | ... | |
303 | 303 |
|
304 | 304 |
); |
305 | 305 |
|
306 |
for my $statement ( 0 .. $#copy_statements ) { |
|
307 |
my $query = $copy_statements[$statement]; |
|
308 |
#print $query . "<br />"; # Diagnose only! |
|
309 |
$self->db_query($query, 0); |
|
310 |
} |
|
306 |
$self->db_query($_) for @copy_statements; |
|
311 | 307 |
|
312 | 308 |
return 1; |
313 | 309 |
} |
sql/Pg-upgrade2/acc_trans_id_uniqueness.pl | ||
---|---|---|
33 | 33 |
)) |
34 | 34 |
SQL |
35 | 35 |
|
36 |
$self->db_query($query, 0);
|
|
36 |
$self->db_query($query); |
|
37 | 37 |
|
38 | 38 |
my %skipped_acc_trans_ids; |
39 | 39 |
foreach my $entry (@entries) { |
... | ... | |
50 | 50 |
AND (mtime $mtime) |
51 | 51 |
SQL |
52 | 52 |
|
53 |
$self->db_query($query, 0);
|
|
53 |
$self->db_query($query); |
|
54 | 54 |
} |
55 | 55 |
} |
56 | 56 |
|
sql/Pg-upgrade2/contacts_add_cp_position.pl | ||
---|---|---|
11 | 11 |
sub run { |
12 | 12 |
my ($self) = @_; |
13 | 13 |
|
14 |
$self->db_query('ALTER TABLE contacts ADD COLUMN cp_position VARCHAR(75)', 1); |
|
14 |
$self->db_query('ALTER TABLE contacts ADD COLUMN cp_position VARCHAR(75)', may_fail => 1);
|
|
15 | 15 |
|
16 | 16 |
return 1; |
17 | 17 |
} |
sql/Pg-upgrade2/contacts_add_street_and_zipcode_and_city.pl | ||
---|---|---|
17 | 17 |
'ALTER TABLE contacts ADD COLUMN cp_city text;', |
18 | 18 |
); |
19 | 19 |
|
20 |
$self->db_query($_, 1) for @queries; |
|
20 |
$self->db_query($_, may_fail => 1) for @queries;
|
|
21 | 21 |
|
22 | 22 |
return 1; |
23 | 23 |
} |
sql/Pg-upgrade2/defaults_datev_check.pl | ||
---|---|---|
12 | 12 |
my ($self) = @_; |
13 | 13 |
|
14 | 14 |
# this query will fail if column already exist (new database) |
15 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_sales_invoice boolean DEFAULT true|, 1); |
|
16 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_purchase_invoice boolean DEFAULT true|, 1); |
|
17 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ar_transaction boolean DEFAULT true|, 1); |
|
18 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ap_transaction boolean DEFAULT true|, 1); |
|
19 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_gl_transaction boolean DEFAULT true|, 1); |
|
15 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_sales_invoice boolean DEFAULT true|, may_fail => 1);
|
|
16 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_purchase_invoice boolean DEFAULT true|, may_fail => 1);
|
|
17 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ar_transaction boolean DEFAULT true|, may_fail => 1);
|
|
18 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ap_transaction boolean DEFAULT true|, may_fail => 1);
|
|
19 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_gl_transaction boolean DEFAULT true|, may_fail => 1);
|
|
20 | 20 |
|
21 | 21 |
# check current configuration and set default variables accordingly, so that |
22 | 22 |
# kivitendo's behaviour isn't changed by this update |
sql/Pg-upgrade2/defaults_posting_config.pl | ||
---|---|---|
12 | 12 |
my ($self) = @_; |
13 | 13 |
|
14 | 14 |
# this query will fail if column already exist (new database) |
15 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN payments_changeable integer NOT NULL DEFAULT 0|, 1); |
|
15 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN payments_changeable integer NOT NULL DEFAULT 0|, may_fail => 1);
|
|
16 | 16 |
|
17 | 17 |
# check current configuration and set default variables accordingly, so that |
18 | 18 |
# kivitendo behaviour isn't changed by this update |
sql/Pg-upgrade2/defaults_show_bestbefore.pl | ||
---|---|---|
12 | 12 |
my ($self) = @_; |
13 | 13 |
|
14 | 14 |
# this query will fail if column already exist (new database) |
15 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN show_bestbefore boolean DEFAULT false|, 1); |
|
15 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN show_bestbefore boolean DEFAULT false|, may_fail => 1);
|
|
16 | 16 |
|
17 | 17 |
# check current configuration and set default variables accordingly, so that |
18 | 18 |
# kivitendo behaviour isn't changed by this update |
sql/Pg-upgrade2/globalprojectnumber_ap_ar_oe.pl | ||
---|---|---|
19 | 19 |
"ALTER TABLE oe ADD COLUMN globalproject_id integer;", |
20 | 20 |
"ALTER TABLE oe ADD FOREIGN KEY (globalproject_id) REFERENCES project (id);"); |
21 | 21 |
|
22 |
$self->db_query("ALTER TABLE project ADD PRIMARY KEY (id);", 1);
|
|
23 |
map({ $self->db_query($_, 0); } @queries);
|
|
22 |
$self->db_query("ALTER TABLE project ADD PRIMARY KEY (id)", may_fail => 1);
|
|
23 |
$self->db_query($_) for @queries;
|
|
24 | 24 |
|
25 | 25 |
return 1; |
26 | 26 |
} |
sql/Pg-upgrade2/umstellung_eur.pl | ||
---|---|---|
20 | 20 |
|
21 | 21 |
foreach my $column (qw(accounting_method inventory_system profit_determination)) { |
22 | 22 |
# this query will fail if columns already exist (new database) |
23 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN ${column} TEXT|, 1); |
|
23 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN ${column} TEXT|, may_fail => 1);
|
|
24 | 24 |
} |
25 | 25 |
|
26 | 26 |
my $accounting_method; |
Auch abrufbar als: Unified diff
Perl-Upgrade-Scripte: db_query nun auch mit Bind-Parametern