[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[3613] trunk



Revision: 3613
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3613&view=rev
Author:   einhverfr
Date:     2011-08-03 18:07:57 +0000 (Wed, 03 Aug 2011)

Log Message:
-----------
API Change on LedgerSMB->call_procedure to accommodate bytea's, and a test case fix

Modified Paths:
--------------
    trunk/LedgerSMB/File.pm
    trunk/LedgerSMB/GL.pm
    trunk/LedgerSMB.pm
    trunk/sql/modules/Files.sql
    trunk/t/62-api.t

Modified: trunk/LedgerSMB/File.pm
===================================================================
--- trunk/LedgerSMB/File.pm	2011-08-02 21:37:38 UTC (rev 3612)
+++ trunk/LedgerSMB/File.pm	2011-08-03 18:07:57 UTC (rev 3613)
@@ -315,8 +315,8 @@
           $self->dbobject->{dbobject}       = $self->dbobject;
           $self->dbobject->{x_info}         = $self->x_info;
     }
-    $self->dbobject->exec_method($args);
-
+    my @results = $self->dbobject->exec_method($args);
+    return @results;
 }
 
 =item merge(hashref)

Modified: trunk/LedgerSMB/GL.pm
===================================================================
--- trunk/LedgerSMB/GL.pm	2011-08-02 21:37:38 UTC (rev 3612)
+++ trunk/LedgerSMB/GL.pm	2011-08-03 18:07:57 UTC (rev 3613)
@@ -50,9 +50,9 @@
      my ($self, $form, $locale) = @_;
      my $file = LedgerSMB::File->new();
      $file->new_dbobject({base => $form, locale => $locale});
-     @{$self->{files}} = $file->list({ref_key => $self->{id}, file_class => 1});
-     @{$self->{file_links}} = $file->list_links(
-                  {ref_key => $self->{id}, file_class => 1}
+     @{$form->{files}} = $file->list({ref_key => $self->{id}, file_class => 1});
+     @{$form->{file_links}} = $file->list_links(
+                  {ref_key => $form->{id}, file_class => 1}
      );
 
 }

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2011-08-02 21:37:38 UTC (rev 3612)
+++ trunk/LedgerSMB.pm	2011-08-03 18:07:57 UTC (rev 3613)
@@ -120,8 +120,14 @@
 
 =item call_procedure( procname => $procname, args => $args )
 
-Function that allows you to call a stored procedure by name and map the appropriate argument to the function values
+Function that allows you to call a stored procedure by name and map the appropriate argument to the function values.
 
+Args is an arrayref.  The members of args can be scalars or arrayrefs in which 
+case they are just bound to the placeholders (arrayref to Pg array conversion
+occurs automatically in DBD::Pg 2.x), or they can be hashrefs of the following
+syntax: {value => $data, type=> $db_type}.  The type field is any SQL type 
+DBD::Pg supports (such as 'PG_BYTEA').
+
 =item dberror()
 
 Localizes and returns database errors and error codes within LedgerSMB
@@ -751,27 +757,31 @@
     }
     $query =~ s/\(\)/($argstr)/;
     my $sth = $self->{dbh}->prepare($query);
-    if (scalar @call_args){
-        $query_rc = $sth->execute(@call_args);
-        if (!$query_rc){
-              if ($args{continue_on_error} and  #  only for plpgsql exceptions
-                              ($self->{dbh}->state =~ /^P/)){
-                    $@ = $self->{dbh}->errstr;
-              } else {
-                    $self->dberror($self->{dbh}->errstr . ": " . $query);
-              }
+    my $place = 1;
+    # API Change here to support byteas:  
+    # If the argument is a hashref, allow it to define it's SQL type
+    # for example PG_BYTEA, and use that to bind.  The API supports the old
+    # syntax (array of scalars and arrayrefs) but extends this so that hashrefs
+    # now have special meaning. I expect this to be somewhat recursive in the
+    # future if hashrefs to complex types are added, but we will have to put 
+    # that off for another day. --CT
+    foreach my $carg (@call_args){
+        if (ref($carg) eq 'HASH'){
+            $sth->bind_param($place, $carg->{value}, $carg->{type}); 
+        } else {
+            $sth->bind_param($place, $carg);
         }
-    } else {
-        $query_rc = $sth->execute();
-        if (!$query_rc){
-              if ($args{continue_on_error} and  #  only for plpgsql exceptions
-                              ($self->{dbh}->state =~ /^P/)){
-                    $@ = $self->{dbh}->errstr;
-              } else {
-                    $self->dberror($self->{dbh}->errstr . ": " . $query);
-              }
-        }
+        ++$place;
     }
+    $query_rc = $sth->execute();
+    if (!$query_rc){
+          if ($args{continue_on_error} and  #  only for plpgsql exceptions
+                          ($self->{dbh}->state =~ /^P/)){
+                $@ = $self->{dbh}->errstr;
+          } else {
+                $self->dberror($self->{dbh}->errstr . ": " . $query);
+          }
+    }
    
     my @types = @{$sth->{TYPE}};
     my @names = @{$sth->{NAME_lc}};

Modified: trunk/sql/modules/Files.sql
===================================================================
--- trunk/sql/modules/Files.sql	2011-08-02 21:37:38 UTC (rev 3612)
+++ trunk/sql/modules/Files.sql	2011-08-03 18:07:57 UTC (rev 3613)
@@ -108,7 +108,8 @@
        uploaded_at timestamp,
        id int,
        ref_key int,
-       file_class int
+       file_class int,
+       content bytea
 );
 
 CREATE OR REPLACE FUNCTION file__list_by(in_ref_key int, in_file_class int)
@@ -116,7 +117,8 @@
 $$
 
 SELECT m.mime_type, f.file_name, f.description, f.uploaded_by, e.name, 
-       f.uploaded_at, f.id, f.ref_key, f.file_class
+       f.uploaded_at, f.id, f.ref_key, f.file_class, 
+       case when m.mime_type = 'text/x-uri' THEN f.content ELSE NULL END
   FROM mime_type m
   JOIN file_base f ON f.mime_type_id = m.id
   JOIN entity e ON f.uploaded_by = e.id
@@ -137,9 +139,9 @@
 COMMENT ON FUNCTION file__get(in_id int, in_file_class int) IS
 $$ Retrieves the file information specified including content.$$;
 
+DROP VIEW IF EXISTS file_order_links;
+DROP VIEW IF EXISTS file_tx_links;
 DROP VIEW IF EXISTS file_links;
-DROP VIEW IF EXISTS file_tx_links;
-DROP VIEW IF EXISTS file_order_links;
 DELETE FROM file_view_catalog WHERE file_class in (1, 2);
 
 CREATE OR REPLACE view file_tx_links AS

Modified: trunk/t/62-api.t
===================================================================
--- trunk/t/62-api.t	2011-08-02 21:37:38 UTC (rev 3612)
+++ trunk/t/62-api.t	2011-08-03 18:07:57 UTC (rev 3613)
@@ -33,7 +33,7 @@
 @test_request_data = do { 't/data/62-request-data' } ; # Import test case hashes
 
 for (qw(	drafts.pl     login.pl      payment.pl      
-		report.pl    employee.pl   menu.pl       vendor.pl
+		employee.pl   menu.pl       vendor.pl
 		customer.pl  inventory.pl  vouchers.pl recon.pl menu.pl)
     ){
 	ok(eval { require "scripts/$_" }, "Importing $_");


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.