DBUtils: selectall_ids
authorSven Schöling <s.schoeling@linet-services.de>
Fri, 5 Sep 2014 11:53:31 +0000 (13:53 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Thu, 18 Dec 2014 14:42:08 +0000 (15:42 +0100)
SL/DBUtils.pm

index 2d9c472..689340a 100644 (file)
@@ -8,6 +8,7 @@ our @EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_stateme
              selectfirst_hashref_query selectfirst_array_query
              selectall_hashref_query selectall_array_query
              selectall_as_map
+             selectall_ids
              prepare_execute_query prepare_query
              create_sort_spec does_table_exist
              add_token);
@@ -236,6 +237,25 @@ sub selectall_as_map {
   return %hash;
 }
 
+sub selectall_ids {
+  $main::lxdebug->enter_sub(2);
+
+  my ($form, $dbh, $query, $key_col) = splice(@_, 0, 4);
+
+  my $sth = prepare_execute_query($form, $dbh, $query, @_);
+
+  my @ids;
+  while (my $ref = $sth->fetchrow_arrayref()) {
+    push @ids, $ref->[$key_col];
+  }
+
+  $sth->finish;
+
+  $main::lxdebug->leave_sub(2);
+
+  return @ids;
+}
+
 sub create_sort_spec {
   $main::lxdebug->enter_sub(2);