« Tapper/Schema/TestrunDB/Result/ScenarioElement.pm
↑ Summary
Tapper/Schema/TestrunDB/Result/Scenario.pm »
| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | require JSON::XS; | ||
| 7 | require Tapper::Model; | ||
| 8 | |||
| 9 | my $or_dbh = Tapper::Model::model()->storage->dbh; | ||
| 10 | my $ar_chart_lines = $or_dbh->selectall_arrayref( | ||
| 11 | ' | ||
| 12 | SELECT | ||
| 13 | chart_line_id, | ||
| 14 | chart_line_statement | ||
| 15 | FROM | ||
| 16 | testrundb.chart_lines | ||
| 17 | ', | ||
| 18 | { Slice => {} }, | ||
| 19 | ); | ||
| 20 | my $or_prep_insert_restriction = $or_dbh->prepare(' | ||
| 21 | INSERT INTO testrundb.chart_line_restrictions | ||
| 22 | ( | ||
| 23 | chart_line_id, | ||
| 24 | chart_line_restriction_operator, | ||
| 25 | chart_line_restriction_column, | ||
| 26 | is_template_restriction, | ||
| 27 | created_at | ||
| 28 | ) | ||
| 29 | VALUES | ||
| 30 | ( ?, ?, ?, ?, NOW() ) | ||
| 31 | '); | ||
| 32 | my $or_prep_insert_restriction_value = $or_dbh->prepare(' | ||
| 33 | INSERT INTO testrundb.chart_line_restriction_values | ||
| 34 | ( | ||
| 35 | chart_line_restriction_id, | ||
| 36 | chart_line_restriction_value | ||
| 37 | ) | ||
| 38 | VALUES | ||
| 39 | ( ?, ? ) | ||
| 40 | '); | ||
| 41 | |||
| 42 | for my $hr_chart_line ( @{$ar_chart_lines} ) { | ||
| 43 | |||
| 44 | my $hr_json; | ||
| 45 | eval { | ||
| 46 | $hr_json = JSON::XS::decode_json( $hr_chart_line->{chart_line_statement} ); | ||
| 47 | }; | ||
| 48 | if ( $@ ) { | ||
| 49 | warn "cannot parse json string: $@"; | ||
| 50 | } | ||
| 51 | else { | ||
| 52 | if ( $hr_json->{where} ) { | ||
| 53 | for my $ar_where_clause ( @{$hr_json->{where}} ) { | ||
| 54 | |||
| 55 | my $s_operator = shift @{$ar_where_clause}; | ||
| 56 | my $s_column = shift @{$ar_where_clause}; | ||
| 57 | |||
| 58 | eval { | ||
| 59 | |||
| 60 | $or_prep_insert_restriction->execute( | ||
| 61 | $hr_chart_line->{chart_line_id}, $s_operator, $s_column, 0, | ||
| 62 | ); | ||
| 63 | |||
| 64 | my $i_chart_line_restriction_id = $or_dbh->{mysql_insertid}; | ||
| 65 | |||
| 66 | for my $s_value ( @{$ar_where_clause} ) { | ||
| 67 | $or_prep_insert_restriction_value->execute( | ||
| 68 | $i_chart_line_restriction_id, $s_value, | ||
| 69 | ); | ||
| 70 | } | ||
| 71 | |||
| 72 | }; | ||
| 73 | if ( $@ ) { | ||
| 74 | warn "cannot add chart line restriction: $@"; | ||
| 75 | } | ||
| 76 | |||
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | } | ||
| 82 | |||
| 83 | 1; |