From 8327a4959a98ad10eb38974aaaddaa1ff7624bda Mon Sep 17 00:00:00 2001 From: einhverfr Date: Fri, 9 Mar 2007 23:15:56 +0000 Subject: Fixing numerous issues with new orm code git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@871 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB.pm | 8 +++++--- LedgerSMB/DBObject.pm | 47 ++++++++++++++++++++++++++--------------------- LedgerSMB/Employee.pm | 19 ++++++++++--------- LedgerSMB/Location.pm | 4 ++-- employee.pl | 2 ++ location.pl | 2 ++ 6 files changed, 47 insertions(+), 35 deletions(-) create mode 100755 employee.pl create mode 100755 location.pl diff --git a/LedgerSMB.pm b/LedgerSMB.pm index 9a4910a1..eb7cca38 100755 --- a/LedgerSMB.pm +++ b/LedgerSMB.pm @@ -525,16 +525,18 @@ sub round_amount { } sub callproc { + my $self = shift @_; my $procname = shift @_; my $argstr = ""; my @results; - for (1 .. $#_){ + for (1 .. scalar @_){ $argstr .= "?, "; } $argstr =~ s/\, $//; - $query = "SELECT * FROM $procname"; - $query =~ s/\(\)/$argstr/; + $query = "SELECT * FROM $procname()"; + $query =~ s/\(\)/($argstr)/; my $sth = $self->{dbh}->prepare($query); + $sth->execute(@_); while (my $ref = $sth->fetchrow_hashref(NAME_lc)){ push @results, $ref; } diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm index 071acb68..beb95fb2 100644 --- a/LedgerSMB/DBObject.pm +++ b/LedgerSMB/DBObject.pm @@ -29,14 +29,17 @@ use strict; no strict 'refs'; use warnings; -@ISA = (LedgerSMB); +our @ISA = qw(LedgerSMB); sub new { my $lsmb = shift @_; - if (! $lsmb->isa(LedgerSMB)){ - $self->error("Constructor called without LedgerSMB object arg"); my $self = {}; - for $attr (keys $lsmb){ + if (! $lsmb->isa('LedgerSMB')){ + $self->error("Constructor called without LedgerSMB object arg"); + } + + my $attr; + for $attr (keys %{$lsmb}){ $self->{$attr} = $lsmb->{$attr}; } bless $self; @@ -49,34 +52,36 @@ sub exec_method { my $query = "SELECT proname, proargnames FROM pg_proc WHERE proname = ?"; - my $sth = $self->{__dbh}->prepare($query); + my $sth = $self->{dbh}->prepare($query); $sth->execute($funcname); my $ref; - $ref = $sth->fetchrow_hashref(NAME_lc); + $ref = $sth->fetchrow_hashref('NAME_lc'); + my $args = $ref->{proargnames}; + $args =~ s/\{(.*)\}/$1/; + my @proc_args = split /,/, $args; + print "Ref: $ref\n"; + print "Args: $ref->{proargnames}\n"; if (!$ref){ # no such function - $self->error($locale->text("No such function: ") .$funcname; + $self->error("No such function: ", $funcname); die; } my $m_name = $ref->{proname}; - my $args = $ref->{proargnames}; - my @proc_args; - - if ($m_name ~= s/$name\_//){ - push @{$self->{__methods}}, $m_name; - if ($args){ - for $arg (@$args){ - if ($arg =~ s/^in_//){ - push @proc_args, $ref->{$arg}; - } + + if ($args){ + for my $arg (@proc_args){ + if ($arg =~ s/^in_//){ + print "Arg: $arg\n"; + push @proc_args, $self->{$arg}; } } - else { - @proc_args = @_; - } } + else { + @proc_args = @_; + } + print "Arg2s: @_ \n"; $self->callproc($funcname, @proc_args); } - +1; diff --git a/LedgerSMB/Employee.pm b/LedgerSMB/Employee.pm index a299ea86..9ddbbc8f 100644 --- a/LedgerSMB/Employee.pm +++ b/LedgerSMB/Employee.pm @@ -33,33 +33,34 @@ use LedgerSMB; use LedgerSMB::DBObject; our $VERSION = '1.0.0'; -@ISA = (LedgerSMB::DBObject); +our @ISA = qw(LedgerSMB::DBObject); sub AUTOLOAD { + my $self = shift; my $procname = "employee_$LedgerSMB::Employee::Autoload"; - $self->exec_method($procname); + $self->exec_method($procname, @_); } sub save { - my $hashref = shift ($self->exec_method("employee_save")); + my $self = shift; + my $hashref = shift @{$self->exec_method("employee_save")}; $self->merge($hashref, 'id'); } sub get { - my $hashref = shift ($self->exec_method("employee_get")); - $self->merge($hashref, keys $hashref); -} - -sub delete { - $self->exec_method("employee_delete"); + my $self = shift; + my $hashref = shift @{$self->exec_method("employee_get")}; + $self->merge($hashref, keys %{$hashref}); } sub list_managers { + my $self = shift; $self->{manager_list} = $self->exec_method("employee_list_managers"); } sub search { + my $self = shift; $self->{search_results} = $self->exec_method("employee_search"); } diff --git a/LedgerSMB/Location.pm b/LedgerSMB/Location.pm index 3c7eda52..95128e51 100644 --- a/LedgerSMB/Location.pm +++ b/LedgerSMB/Location.pm @@ -34,7 +34,7 @@ use LedgerSMB; use LedgerSMB::DBObject; our $VERSION = '1.0.0'; -@ISA = (LedgerSMB::DBObject); +our @ISA = qw(LedgerSMB::DBObject); sub AUTOLOAD { my $procname = "location_$LedgerSMB::Location::Autoload"; @@ -48,7 +48,7 @@ sub save { sub get { $ref = shift @{$self->exec_method('location_get')}; - $self->merge($ref, keys $ref); + $self->merge($ref, keys %{$ref}); } sub search { diff --git a/employee.pl b/employee.pl new file mode 100755 index 00000000..7319efed --- /dev/null +++ b/employee.pl @@ -0,0 +1,2 @@ +#!/usr/bin/perl +require "menu.pl"; diff --git a/location.pl b/location.pl new file mode 100755 index 00000000..7319efed --- /dev/null +++ b/location.pl @@ -0,0 +1,2 @@ +#!/usr/bin/perl +require "menu.pl"; -- cgit v1.2.3