From aa8d314980b59fc308b59bd4f5ea11bd06f9eb3f Mon Sep 17 00:00:00 2001
From: Gerhard Gonter <ggonter@gmail.com>
Date: Fri, 6 Dec 2019 20:53:38 +0100
Subject: [PATCH] module to read data from mysql and postrgesql listings

---
 modules/util/Util/Data_Listing.pm | 57 +++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 modules/util/Util/Data_Listing.pm

diff --git a/modules/util/Util/Data_Listing.pm b/modules/util/Util/Data_Listing.pm
new file mode 100644
index 0000000..26bc640
--- /dev/null
+++ b/modules/util/Util/Data_Listing.pm
@@ -0,0 +1,57 @@
+
+package Util::Data_Listing;
+
+use strict;
+
+sub new
+{
+  my $class= shift;
+  bless [], $class;
+}
+
+sub read
+{
+  my $self= shift;
+  my $fnm= shift;
+
+  open (FI, '<:utf8', $fnm) or die "can't read [$fnm]";
+  my $rec= undef;
+  my $lnr= 0;
+  while(<FI>)
+  {
+    chop;
+    $lnr++;
+    # print __LINE__, " $lnr=[$_]\n";
+    if (m#^\*+ (\d+)\. row \*+$#              # MySQL \G
+        || m#^-+\[ RECORD (\d+) \][\-\+]+$#   # PostgreSQL \x
+       )
+    {
+      my $num= $1;
+      push(@$self, $rec) if (defined($rec));
+      $rec= { _record => $num, _file => $fnm };
+    }
+    elsif (m#^$#) {} # ignore empty lines
+    elsif (defined ($rec))
+    {
+      if (m#^\s*([^:]+): (.*)#          # MySQL \G
+          || m#^([^ ]+) *\| (.*)#       # PostgreSQL \x
+         )
+      {
+        $rec->{$1}= $2;
+      }
+      else
+      {
+        die "invalid format";
+      }
+    }
+    else
+    {
+      die "no record defined";
+    }
+  }
+  push(@$self, $rec) if (defined($rec));
+  close(FI);
+}
+
+1;
+
-- 
GitLab