diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-09-24 01:40:57 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-09-24 01:40:57 +0000 |
commit | 79b9272f11148755c0da2cd158738b32257fdfb3 (patch) | |
tree | 5c73048941d004f0628ece49d84e32e551136ffc /LedgerSMB | |
parent | 5cf7df87f87c8333dd6deab69af218e37970bc94 (diff) |
Fixed version for now.
Added an API to the Form object for creating SELECT, INSERT, and UPDATE queries based on custom fields
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@137 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB')
-rwxr-xr-x | LedgerSMB/Form.pm | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm index 6bca3ddd..7a578448 100755 --- a/LedgerSMB/Form.pm +++ b/LedgerSMB/Form.pm @@ -62,7 +62,7 @@ sub new { $self->{menubar} = 1 if $self->{path} =~ /lynx/i; - $self->{version} = "1.1.0"; + $self->{version} = "1.1.1"; $self->{dbversion} = "2.6.18"; bless $self, $type; @@ -1281,31 +1281,67 @@ sub db_init { } sub get_custom_queries { - my ($self, $tablename) = @_; + my ($self, $tablename, $query_type, $linenum) = @_; + if ($query_type !~ /^(select|insert|update)$/i){ + $self->error($locale->text( + "Passed incorrect query type to get_cutstom_queries." + )); + } my @rc; my %temphash; + my @templist; my @elements; my $query; + my $ins_values; + if ($linenum){ + $linenum = "_$linenum"; + } + + $query_type = uc($query_type); for (@{$self->{custom_db_fields}{$tablename}}){ @elements = split (/:/, $_); push @{$temphash{$elements[0]}}, $elements[1]; } for (keys %temphash){ - $query = "SELECT "; + my @data; + $query = "$query_type "; + if ($query_type eq 'UPDATE'){ + $query .= " $_ SET "; + } elsif ($query_type eq 'INSERT'){ + $query .= " INTO $_ ("; + } my $first = 1; for (@{$temphash{$_}}){ $query .= "$_"; + if ($query_type eq 'UPDATE'){ + $query .= '= ?'; + } + my $ins_values .= "?, "; if ($first == 0){ - $query .= ", " + $query .= ", "; } $first = 0; + if ($query_type eq 'UPDATE' or $query_type eq 'INERT'){ + push @data, $form->{$_ . $linenum}; + } + } + if ($query_type eq 'SELECT'){ + $query .= " FROM $_"; + } + if ($query_type eq 'SELECT' or $query_type eq 'UPDATE'){ + $query .= " WHERE field_id = ?"; + } + if ($query_type eq 'SELECT'){ + push @rc, [ $query ]; + } else { + unshift (@data, $query); + push @rc, [ @data ]; } - $query .= " FROM $_ WHERE field_id = ?"; - push @rc, $query; } @rc; } + sub dbconnect { my ($self, $myconfig) = @_; |