use map for table columns

This commit is contained in:
Milan
2020-03-08 00:24:15 +01:00
parent ea9590f6dc
commit 7b565c6d9b
20 changed files with 38 additions and 59 deletions

View File

@@ -21,9 +21,8 @@ sub debug;
sub get_columns($) { sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_audio_recordings' ); return db::get_columns_hash( $dbh, 'calcms_audio_recordings' );
return { map { $_ => undef } @$cols };
} }
# get playout entries # get playout entries

View File

@@ -115,8 +115,7 @@ sub get_columns($$) {
my $table = shift; my $table = shift;
my $columns = db::get( $dbh, 'select column_name from information_schema.columns where table_name=?', [$table] ); my $columns = db::get( $dbh, 'select column_name from information_schema.columns where table_name=?', [$table] );
my @result = map { $_->{column_name} } (@$columns); return [ map { $_->{column_name} } @$columns ];
return \@result;
} }
# get hash with table columns as keys # get hash with table columns as keys
@@ -124,8 +123,8 @@ sub get_columns_hash($$) {
my $dbh = shift; my $dbh = shift;
my $table = shift; my $table = shift;
my $columns = db::get_columns( $dbh, $table ); my $columns = db::get( $dbh, 'select column_name from information_schema.columns where table_name=?', [$table] );
return { map { $_ => 1 } @$columns }; return { map { $_->{column_name} => 1 } @$columns };
} }
#returns last inserted id #returns last inserted id

View File

@@ -14,9 +14,8 @@ sub debug;
sub get_columns ($){ sub get_columns ($){
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_event_history' ); return db::get_columns_hash( $dbh, 'calcms_event_history' );
return { map { $_ => undef } @$cols };
} }
sub get ($$){ sub get ($$){

View File

@@ -22,8 +22,7 @@ sub get_columns ($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_password_requests' ); return db::get_columns_hash( $dbh, 'calcms_password_requests' );
return { map { $_ => undef } @$cols };
} }
sub get ($$) { sub get ($$) {

View File

@@ -18,9 +18,8 @@ sub debug;
sub get_columns ($) { sub get_columns ($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_playout' ); return db::get_columns_hash( $dbh, 'calcms_playout' );
return { map { $_ => undef } @$cols };
} }

View File

@@ -28,9 +28,8 @@ sub debug;
sub get_columns ($) { sub get_columns ($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_projects' ); return db::get_columns_hash( $dbh, 'calcms_projects' );
return { map { $_ => undef } @$cols };
} }
# get projects # get projects

View File

@@ -32,9 +32,8 @@ sub debug;
sub get_columns ($) { sub get_columns ($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_series' ); return db::get_columns_hash( $dbh, 'calcms_series' );
return { map { $_ => undef } @$cols };
} }
# get series content # get series content

View File

@@ -24,9 +24,8 @@ sub debug;
sub get_columns ($) { sub get_columns ($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_series_dates' ); return db::get_columns_hash( $dbh, 'calcms_series_dates' );
return { map { $_ => undef } @$cols };
} }
# get all series_dates for studio_id and series_id within given time range # get all series_dates for studio_id and series_id within given time range

View File

@@ -27,9 +27,7 @@ sub get_columns ($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_series_schedule' ); return db::get_columns_hash( $dbh, 'calcms_series_schedule' );
return { map { $_ => undef } @$cols };
} }
#map schedule id to id #map schedule id to id

View File

@@ -20,9 +20,8 @@ sub debug;
sub get_columns ($){ sub get_columns ($){
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_studio_timeslot_dates' ); return db::get_columns_hash( $dbh, 'calcms_studio_timeslot_dates' );
return { map { $_ => undef } @$cols };
} }
# get all studio_timeslot_dates for studio_id within given time range # get all studio_timeslot_dates for studio_id within given time range

View File

@@ -18,9 +18,8 @@ sub debug;
sub get_columns($) { sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_studio_timeslot_schedule' ); return db::get_columns_hash( $dbh, 'calcms_studio_timeslot_schedule' );
return { map { $_ => undef } @$cols };
} }
#map schedule id to id #map schedule id to id

View File

@@ -15,9 +15,8 @@ sub debug;
sub get_columns($) { sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_studios' ); return db::get_columns_hash( $dbh, 'calcms_studios' );
return { map { $_ => undef } @$cols };
} }
sub get($;$) { sub get($;$) {
my $config = shift; my $config = shift;

View File

@@ -8,8 +8,6 @@ use Data::Dumper;
# table: calcms_user_default_studios # table: calcms_user_default_studios
# columns: user, project_id, studio_id # columns: user, project_id, studio_id
#use base 'Exporter';
#our @EXPORT_OK = qw(get insert update delete get_columns);
sub debug; sub debug;
@@ -17,8 +15,7 @@ sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_user_default_studios' ); return db::get_columns_hash( $dbh, 'calcms_user_default_studios' );
return { map { $_ => undef } @$cols };
} }
sub get ($$) { sub get ($$) {

View File

@@ -26,9 +26,8 @@ sub debug;
sub get_columns($) { sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_user_sessions' ); return db::get_columns_hash( $dbh, 'calcms_user_sessions' );
return { map { $_ => undef } @$cols };
} }
#map schedule id to id #map schedule id to id

View File

@@ -136,9 +136,8 @@ sub getColorCss ($$) {
sub get_columns($) { sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_user_settings' ); return db::get_columns_hash( $dbh, 'calcms_user_settings' );
return { map { $_ => undef } @$cols };
} }
sub get ($$) { sub get ($$) {

View File

@@ -13,9 +13,8 @@ sub debug;
sub get_columns($) { sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_user_stats' ); return db::get_columns_hash( $dbh, 'calcms_user_stats' );
return { map { $_ => undef } @$cols };
} }
sub get ($$) { sub get ($$) {

View File

@@ -24,9 +24,8 @@ sub debug;
sub get_columns($) { sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_work_dates' ); return db::get_columns_hash( $dbh, 'calcms_work_dates' );
return { map { $_ => undef } @$cols };
} }
# get all work_dates for studio_id and schedule_id within given time range # get all work_dates for studio_id and schedule_id within given time range

View File

@@ -25,9 +25,8 @@ sub debug;
sub get_columns($) { sub get_columns($) {
my $config = shift; my $config = shift;
my $dbh = db::connect($config); my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_work_schedule' ); return db::get_columns_hash( $dbh, 'calcms_work_schedule' );
return { map { $_ => undef } @$cols };
} }
#map schedule id to id #map schedule id to id

View File

@@ -86,7 +86,7 @@ sub delete_project {
my $entry = {}; my $entry = {};
for my $param ( keys %$params ) { for my $param ( keys %$params ) {
if ( defined $columns->{$param} ) { if ( exists $columns->{$param} ) {
$entry->{$param} = $params->{$param} || ''; $entry->{$param} = $params->{$param} || '';
} }
} }
@@ -113,7 +113,7 @@ sub save_project {
my $columns = project::get_columns($config); my $columns = project::get_columns($config);
my $entry = {}; my $entry = {};
for my $param ( keys %$params ) { for my $param ( keys %$params ) {
if ( defined $columns->{$param} ) { if ( exists $columns->{$param} ) {
$entry->{$param} = $params->{$param} || ''; $entry->{$param} = $params->{$param} || '';
} }
} }

View File

@@ -82,7 +82,7 @@ sub delete_studio {
my $entry = {}; my $entry = {};
for my $param ( keys %$params ) { for my $param ( keys %$params ) {
if ( defined $columns->{$param} ) { if ( exists $columns->{$param} ) {
$entry->{$param} = $params->{$param} || ''; $entry->{$param} = $params->{$param} || '';
} }
} }
@@ -131,7 +131,7 @@ sub save_studio {
my $columns = studios::get_columns($config); my $columns = studios::get_columns($config);
my $entry = {}; my $entry = {};
for my $param ( keys %$params ) { for my $param ( keys %$params ) {
if ( defined $columns->{$param} ) { if ( exists $columns->{$param} ) {
$entry->{$param} = $params->{$param} || ''; $entry->{$param} = $params->{$param} || '';
} }
} }