Use a cursor to pull MARC data from the DB user/miker/marc_export_by_cursor
authorMike Rylander <mrylander@gmail.com>
Wed, 19 Apr 2017 14:34:25 +0000 (10:34 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 19 Apr 2017 14:34:25 +0000 (10:34 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/support-scripts/marc_export.in

index 5c0115c..b46b03e 100755 (executable)
@@ -403,8 +403,7 @@ ACN_JOIN
 sub execute_query {
     my $self = shift;
     $self->build_query() unless ($self->{query});
-    $self->{sth} = $self->{handle}->prepare($self->{query});
-    return $self->{sth}->execute;
+    return $self->{handle}->do("declare csr cursor with hold for $$self{query}");
 }
 
 sub next {
@@ -435,7 +434,7 @@ sub next {
             return $self->next();
         }
     } else {
-        my $data = $self->{sth}->fetchrow_hashref;
+        my $data = $self->{handle}->prepare('fetch 1 from csr')->execute->fetchrow_hashref;
         if ($data) {
             $r = $self->{breClass}->from_bare_hash($data);
             if ($Marque::config->option_value('format') eq 'BRE') {
@@ -506,6 +505,8 @@ sub next {
                     $self->{mfhds} = [$self->sres_for_bre($r)];
                 }
             }
+        } else {
+            $self->{handle}->do('close csr');
         }
     }
     # Common stuff that doesn't depend on record type.
@@ -742,14 +743,13 @@ sub build_query {
 sub execute_query {
     my $self = shift;
     $self->build_query() unless ($self->{query});
-    $self->{sth} = $self->{handle}->prepare($self->{query});
-    return $self->{sth}->execute;
+    return $self->{handle}->do("declare csr cursor with hold for $$self{query}");
 }
 
 sub next {
     my $self = shift;
     my $output;
-    my $data = $self->{sth}->fetchrow_hashref;
+    my $data = $self->{handle}->prepare('fetch 1 from csr')->execute->fetchrow_hashref;
 
     if ($data) {
         my $format = $Marque::config->option_value('format');
@@ -830,6 +830,8 @@ sub next {
                 }
             }
         }
+    } else {
+        $self->{handle}->do('close csr');
     }
 
     return $output;