}
sub db_query {
- my ($self, $query, $may_fail) = @_;
+ my ($self, $query, %params) = @_;
- return if $self->dbh->do($query);
+ return if $self->dbh->do($query, undef, @{ $params{bind} || [] });
- $self->db_error($query) unless $may_fail;
+ $self->db_error($query) unless $params{may_fail};
$self->dbh->rollback;
$self->dbh->begin_work;
Outputs an error message C<$message> to the user and aborts execution.
-=item C<db_query $query, $may_fail>
+=item C<db_query $query, %params>
-Executes an SQL query. What the method does if the query fails depends
-on C<$may_fail>. If it is falsish then the method will simply die
-outputting the error message via L</db_error>. If C<$may_fail> is
-trueish then the current transaction will be rolled back, a new one
-will be started
+Executes an SQL query. The following parameters are supported:
+
+=over 2
+
+=item C<may_fail>
+
+What the method does if the query fails depends on this parameter. If
+it is falsish (the default) then the method will simply die outputting
+the error message via L</db_error>. If C<may_fail> is trueish then the
+current transaction will be rolled back, a new one will be started.
+
+=item C<bind>
+
+An optional array reference containing bind parameter for the query.
+
+=back
=item C<execute_script>
},
);
- $self->db_query("DROP SCHEMA tax CASCADE;", 1);
- map({ $self->db_query($_, 0); } @queries);
+ $self->db_query("DROP SCHEMA tax CASCADE;", may_fail => 1);
+ $self->db_query($_) for @queries;
return 1;
q{ DELETE FROM tax.report_variables; },
);
- map({ $self->db_query("DELETE FROM $_ ;", 0); } @clear);
+ $self->db_query("DELETE FROM $_") for @clear;
return 1;
);
- for my $statement ( 0 .. $#copy_statements ) {
- my $query = $copy_statements[$statement];
- #print $query . "<br />"; # Diagnose only!
- $self->db_query($query, 0);
- }
+ $self->db_query($_) for @copy_statements;
return 1;
}
))
SQL
- $self->db_query($query, 0);
+ $self->db_query($query);
my %skipped_acc_trans_ids;
foreach my $entry (@entries) {
AND (mtime $mtime)
SQL
- $self->db_query($query, 0);
+ $self->db_query($query);
}
}
sub run {
my ($self) = @_;
- $self->db_query('ALTER TABLE contacts ADD COLUMN cp_position VARCHAR(75)', 1);
+ $self->db_query('ALTER TABLE contacts ADD COLUMN cp_position VARCHAR(75)', may_fail => 1);
return 1;
}
'ALTER TABLE contacts ADD COLUMN cp_city text;',
);
- $self->db_query($_, 1) for @queries;
+ $self->db_query($_, may_fail => 1) for @queries;
return 1;
}
my ($self) = @_;
# this query will fail if column already exist (new database)
- $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_sales_invoice boolean DEFAULT true|, 1);
- $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_purchase_invoice boolean DEFAULT true|, 1);
- $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ar_transaction boolean DEFAULT true|, 1);
- $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ap_transaction boolean DEFAULT true|, 1);
- $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_gl_transaction boolean DEFAULT true|, 1);
+ $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_sales_invoice boolean DEFAULT true|, may_fail => 1);
+ $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_purchase_invoice boolean DEFAULT true|, may_fail => 1);
+ $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ar_transaction boolean DEFAULT true|, may_fail => 1);
+ $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_ap_transaction boolean DEFAULT true|, may_fail => 1);
+ $self->db_query(qq|ALTER TABLE defaults ADD COLUMN datev_check_on_gl_transaction boolean DEFAULT true|, may_fail => 1);
# check current configuration and set default variables accordingly, so that
# kivitendo's behaviour isn't changed by this update
my ($self) = @_;
# this query will fail if column already exist (new database)
- $self->db_query(qq|ALTER TABLE defaults ADD COLUMN payments_changeable integer NOT NULL DEFAULT 0|, 1);
+ $self->db_query(qq|ALTER TABLE defaults ADD COLUMN payments_changeable integer NOT NULL DEFAULT 0|, may_fail => 1);
# check current configuration and set default variables accordingly, so that
# kivitendo behaviour isn't changed by this update
my ($self) = @_;
# this query will fail if column already exist (new database)
- $self->db_query(qq|ALTER TABLE defaults ADD COLUMN show_bestbefore boolean DEFAULT false|, 1);
+ $self->db_query(qq|ALTER TABLE defaults ADD COLUMN show_bestbefore boolean DEFAULT false|, may_fail => 1);
# check current configuration and set default variables accordingly, so that
# kivitendo behaviour isn't changed by this update
"ALTER TABLE oe ADD COLUMN globalproject_id integer;",
"ALTER TABLE oe ADD FOREIGN KEY (globalproject_id) REFERENCES project (id);");
- $self->db_query("ALTER TABLE project ADD PRIMARY KEY (id);", 1);
- map({ $self->db_query($_, 0); } @queries);
+ $self->db_query("ALTER TABLE project ADD PRIMARY KEY (id)", may_fail => 1);
+ $self->db_query($_) for @queries;
return 1;
}
foreach my $column (qw(accounting_method inventory_system profit_determination)) {
# this query will fail if columns already exist (new database)
- $self->db_query(qq|ALTER TABLE defaults ADD COLUMN ${column} TEXT|, 1);
+ $self->db_query(qq|ALTER TABLE defaults ADD COLUMN ${column} TEXT|, may_fail => 1);
}
my $accounting_method;