« blib/lib/SQL/Translator/Producer/XML/SQLFairy.pm
↑ Summary
blib/lib/SQL/Translator/Generator/Role/Quote.pm »
| 1 | package SQL::Translator::Producer::DB2; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | SQL::Translator::Producer::DB2 - DB2 SQL producer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | use SQL::Translator; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | my $t = SQL::Translator->new( parser => '...', producer => 'DB2' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | print $translator->translate( $file ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | Creates an SQL DDL suitable for DB2. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | our ($DEBUG, $WARN); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | our $VERSION = '1.66'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | $DEBUG = 0 unless defined $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | use SQL::Translator::Schema::Constants; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | use SQL::Translator::Utils qw(header_comment); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # http://publib.boulder.ibm.com/infocenter/db2help/topic/com.ibm.db2.udb.doc/ad/r0006844.htm | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # This is a terrible WTDI, each Parser should parse down to some standard set | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # of SQL data types, with field->extra entries being used to convert back to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # weird types like "polygon" if needed (IMO anyway) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | my %dt_translate; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | %dt_translate = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # MySQL types | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | int => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | mediumint => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | tinyint => 'smallint', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | char => 'char', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | tinyblob => 'blob', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | mediumblob => 'blob', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | longblob => 'long varchar for bit data', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | tinytext => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | text => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | longtext => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | mediumtext => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | enum => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | set => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | date => 'date', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | datetime => 'timestamp', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | time => 'time', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | year => 'date', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # PostgreSQL types | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 'double precision' => 'double', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | serial => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | bigserial => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | money => 'double', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | character => 'char', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 'character varying' => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | bytea => 'BLOB', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | interval => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | boolean => 'smallint', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | point => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | line => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | lseg => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | box => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | path => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | polygon => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | circle => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | cidr => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | inet => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | macaddr => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | bit => 'number', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 'bit varying' => 'number', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # DB types | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | number => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | varchar2 => 'varchar', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | long => 'clob', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | my %db2_reserved = map { $_ => 1 } qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ADD DETERMINISTIC LEAVE RESTART | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | AFTER DISALLOW LEFT RESTRICT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ALIAS DISCONNECT LIKE RESULT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ALL DISTINCT LINKTYPE RESULT_SET_LOCATOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ALLOCATE DO LOCAL RETURN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | ALLOW DOUBLE LOCALE RETURNS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ALTER DROP LOCATOR REVOKE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | AND DSNHATTR LOCATORS RIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ANY DSSIZE LOCK ROLLBACK | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | APPLICATION DYNAMIC LOCKMAX ROUTINE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | AS EACH LOCKSIZE ROW | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ASSOCIATE EDITPROC LONG ROWS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ASUTIME ELSE LOOP RRN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | AUDIT ELSEIF MAXVALUE RUN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | AUTHORIZATION ENCODING MICROSECOND SAVEPOINT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | AUX END MICROSECONDS SCHEMA | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | AUXILIARY END-EXEC MINUTE SCRATCHPAD | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | BEFORE END-EXEC1 MINUTES SECOND | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | BEGIN ERASE MINVALUE SECONDS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | BETWEEN ESCAPE MODE SECQTY | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | BINARY EXCEPT MODIFIES SECURITY | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | BUFFERPOOL EXCEPTION MONTH SELECT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | BY EXCLUDING MONTHS SENSITIVE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | CACHE EXECUTE NEW SET | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | CALL EXISTS NEW_TABLE SIGNAL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | CALLED EXIT NO SIMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | CAPTURE EXTERNAL NOCACHE SOME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | CARDINALITY FENCED NOCYCLE SOURCE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | CASCADED FETCH NODENAME SPECIFIC | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | CASE FIELDPROC NODENUMBER SQL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | CAST FILE NOMAXVALUE SQLID | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | CCSID FINAL NOMINVALUE STANDARD | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | CHAR FOR NOORDER START | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | CHARACTER FOREIGN NOT STATIC | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | CHECK FREE NULL STAY | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | CLOSE FROM NULLS STOGROUP | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | CLUSTER FULL NUMPARTS STORES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | COLLECTION FUNCTION OBID STYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | COLLID GENERAL OF SUBPAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | COLUMN GENERATED OLD SUBSTRING | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | COMMENT GET OLD_TABLE SYNONYM | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | COMMIT GLOBAL ON SYSFUN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | CONCAT GO OPEN SYSIBM | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | CONDITION GOTO OPTIMIZATION SYSPROC | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | CONNECT GRANT OPTIMIZE SYSTEM | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | CONNECTION GRAPHIC OPTION TABLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | CONSTRAINT GROUP OR TABLESPACE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | CONTAINS HANDLER ORDER THEN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | CONTINUE HAVING OUT TO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | COUNT HOLD OUTER TRANSACTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | COUNT_BIG HOUR OVERRIDING TRIGGER | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | CREATE HOURS PACKAGE TRIM | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | CROSS IDENTITY PARAMETER TYPE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | CURRENT IF PART UNDO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | CURRENT_DATE IMMEDIATE PARTITION UNION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | CURRENT_LC_CTYPE IN PATH UNIQUE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | CURRENT_PATH INCLUDING PIECESIZE UNTIL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | CURRENT_SERVER INCREMENT PLAN UPDATE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | CURRENT_TIME INDEX POSITION USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | CURRENT_TIMESTAMP INDICATOR PRECISION USER | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | CURRENT_TIMEZONE INHERIT PREPARE USING | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | CURRENT_USER INNER PRIMARY VALIDPROC | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | CURSOR INOUT PRIQTY VALUES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | CYCLE INSENSITIVE PRIVILEGES VARIABLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | DATA INSERT PROCEDURE VARIANT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | DATABASE INTEGRITY PROGRAM VCAT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | DAY INTO PSID VIEW | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | DAYS IS QUERYNO VOLUMES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | DB2GENERAL ISOBID READ WHEN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | DB2GENRL ISOLATION READS WHERE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | DB2SQL ITERATE RECOVERY WHILE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | DBINFO JAR REFERENCES WITH | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | DECLARE JAVA REFERENCING WLM | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | DEFAULT JOIN RELEASE WRITE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | DEFAULTS KEY RENAME YEAR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | DEFINITION LABEL REPEAT YEARS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | DELETE LANGUAGE RESET | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | DESCRIPTOR LC_CTYPE RESIGNAL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | /; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | ▶ | sub produce { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
produce: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | my ($translator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | $DEBUG = $translator->debug; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | $WARN = $translator->show_warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | my $no_comments = $translator->no_comments; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | my $add_drop_table = $translator->add_drop_table; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | my $schema = $translator->schema; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 3 | my $output = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | my $indent = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | ▶ | $output .= header_comment unless ($no_comments); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 3 | my (@table_defs, @fks, @index_defs); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | foreach my $table ($schema->get_tables) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | ▶ | push @table_defs, 'DROP TABLE ' . $table->name . ";" if $add_drop_table; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 8 | my ($table_def, $fks) = create_table( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | $table, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | no_comments => $no_comments | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | push @table_defs, $table_def; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | push @fks, @$fks; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 8 | foreach my $index ($table->get_indices) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 3 | push @index_defs, create_index($index); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | my (@view_defs); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | foreach my $view ($schema->get_views) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 3 | push @view_defs, create_view($view); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | my (@trigger_defs); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 3 | foreach my $trigger ($schema->get_triggers) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 7 | push @trigger_defs, create_trigger($trigger); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | ▶ | ? (@table_defs, @fks, @index_defs, @view_defs, @trigger_defs) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | : $output . join("\n\n", @table_defs, @fks, @index_defs, @view_defs, @trigger_defs) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | my %objnames; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 46 | ▶ | sub check_name { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_name: called CC=5 SCAR=21.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 46 | my ($name, $type, $length) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 46 | my $newname = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 46 | ▶ | if (length($name) > $length) ## Maximum table name length is 18 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | warn "Table name $name is longer than $length characters, truncated" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | if $WARN; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # if(grep {$_ eq substr($name, 0, $length) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # values(%{$objnames{$type}})) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # die "Got multiple matching table names when truncated"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # $objnames{$type}{$name} = substr($name, 0,$length); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # $newname = $objnames{$type}{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 46 | ▶ | if ($db2_reserved{ uc($newname) }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | warn "$newname is a reserved word in DB2!" if $WARN; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # return sprintf("%-*s", $length-5, $newname); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 46 | return $newname; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | ▶ | sub create_table { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_table: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 8 | my ($table, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 8 | my $table_name = check_name($table->name, 'tables', 128); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # this limit is 18 in older DB2s ! (<= 8) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 8 | my (@field_defs, @comments); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | push @comments, "--\n-- Table: $table_name\n--" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 8 | ▶ | unless $options->{no_comments}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 8 | foreach my $field ($table->get_fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 36 | push @field_defs, create_field($field); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 8 | my (@con_defs, @fks); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 8 | foreach my $con ($table->get_constraints) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 15 | my ($cdefs, $fks) = create_constraint($con); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 15 | push @con_defs, @$cdefs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 15 | push @fks, @$fks; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 8 | ▶ | my $tablespace = $table->extra()->{'TABLESPACE'} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$table->extra->{'TABLESPACE'} || ''
MC/DC0%0/1
$table->extra->{'TABLESPACE'} || ''
$table->extra->{'TABLESPACE'}
Truth table50%1/2
A
A= $table->extra->{'TABLESPACE'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 8 | my $table_def = "CREATE TABLE $table_name (\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 8 | $table_def .= join(",\n", map {" $_"} @field_defs, @con_defs); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 8 | $table_def .= "\n)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 8 | ▶ | $table_def .= $tablespace ? "IN $tablespace;" : ';'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 8 | return $table_def, \@fks; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 38 | ▶ | sub create_field { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_field: called CC=10 SCAR=23.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 38 | my ($field) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 38 | my $field_name = check_name($field->name, 'fields', 30); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # print Dumper(\%dt_translate); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # print $field->data_type, " ", $dt_translate{lc($field->data_type)}, "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 38 | ▶ | my $data_type = uc($dt_translate{ lc($field->data_type) } || $field->data_type); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$dt_translate{lc $field->data_type} || $field->data_type
MC/DC0%0/2
$dt_translate{lc $field->data_type} || $field->data_type
$dt_translate{lc $field->data_type}
$field->data_type
Truth table66%2/3
A || B
A= $dt_translate{lc $field->data_type}B= $field->data_type
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 38 | my $size = $field->size(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 38 | my $field_def = "$field_name $data_type"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 38 | ▶ | $field_def | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | .= $field->is_auto_increment | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | ? ' GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1)' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 38 | ▶ | $field_def .= $data_type =~ /(CHAR|CLOB|NUMERIC|DECIMAL)/i ? "(${size})" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 38 | ▶ | $field_def .= !$field->is_nullable ? ' NOT NULL' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # $field_def .= $field->is_primary_key ? ' PRIMARY KEY':''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 38 | ▶ | $field_def | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%1/3
$field->default_value =~ /current( |_)timestamp/i or $field->default_value =~ /now\(\)/i
MC/DC0%0/2
$field->default_value =~ /current( |_)timestamp/i or $field->default_value =~ /now\(\)/i
$field->default_value =~ /current( |_)timestamp/i
$field->default_value =~ /now\(\)/i
Truth table33%1/3
A or B
A= $field->default_value =~ /current( |_)timestamp/iB= $field->default_value =~ /now\(\)/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | .= !defined $field->default_value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | ? '' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | : $field->default_value =~ /current( |_)timestamp/i | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | || $field->default_value =~ /\Qnow()\E/i ? ' DEFAULT CURRENT TIMESTAMP' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | : defined $field->default_value ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | " DEFAULT " | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | . ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | $data_type =~ /(INT|DOUBLE)/i | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | ? $field->default_value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | : "'" . $field->default_value . "'" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 38 | return $field_def; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 5 | ▶ | sub create_index { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_index: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 5 | my ($index) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 5 | ▶ | my $out = sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 'CREATE %sINDEX %s ON %s ( %s );', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | $index->type() =~ /^UNIQUE$/i ? 'UNIQUE' : '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | $index->name, $index->table->name, join(', ', $index->fields) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 15 | ▶ | sub create_constraint { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_constraint: called CC=12 SCAR=25.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 15 | my ($constraint) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 15 | my (@con_defs, @fks); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 15 | ▶ | my $ctype | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | = $constraint->type =~ /^PRIMARY(_|\s)KEY$/i ? 'PRIMARY KEY' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | : $constraint->type =~ /^UNIQUE$/i ? 'UNIQUE' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | : $constraint->type =~ /^CHECK_C$/i ? 'CHECK' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | : $constraint->type =~ /^FOREIGN(_|\s)KEY$/i ? 'FOREIGN KEY' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 15 | ▶ | my $expr | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | = $constraint->type =~ /^CHECK_C$/i | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | ? $constraint->expression | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 15 | ▶ | my $ref | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | = $constraint->type =~ /^FOREIGN(_|\s)KEY$/i | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | ? ('REFERENCES ' . $constraint->reference_table . '(' . join(', ', $constraint->reference_fields) . ')') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 15 | ▶ | my $update = $constraint->on_update ? $constraint->on_update : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 15 | ▶ | my $delete = $constraint->on_delete ? $constraint->on_delete : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | my $out = join(' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 15 | ▶ | grep {$_} $constraint->name ? ('CONSTRAINT ' . $constraint->name) : '', | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | $ctype, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | '(' . join(', ', $constraint->fields) . ')', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | $expr ? $expr : $ref, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | $update, $delete); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 15 | ▶ | if ($constraint->type eq FOREIGN_KEY) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 3 | my $table_name = $constraint->table->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 3 | $out = "ALTER TABLE $table_name ADD $out;"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 3 | push @fks, $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 12 | push @con_defs, $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 15 | return \@con_defs, \@fks; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 3 | ▶ | sub create_view { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_view: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 3 | my ($view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | my $out = sprintf("CREATE VIEW %s AS\n%s;", $view->name, $view->sql); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 3 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 7 | ▶ | sub create_trigger { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_trigger: called CC=6 SCAR=20.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 7 | my ($trigger) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # create: CREATE TRIGGER trigger_name before type /ON/i table_name reference_b(?) /FOR EACH ROW/i 'MODE DB2SQL' triggered_action | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 7 | my $db_events = join ', ', $trigger->database_events; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | my $out = sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 'CREATE TRIGGER %s %s %s ON %s %s %s MODE DB2SQL %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | $trigger->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | $trigger->perform_action_when || 'AFTER', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | $db_events =~ /update_on/i | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | ? ('UPDATE OF ' . join(', ', $trigger->fields)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | : $db_events || 'UPDATE', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | $trigger->table->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | $trigger->extra->{reference} || 'REFERENCING OLD AS oldrow NEW AS newrow', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 7 | ▶ | $trigger->extra->{granularity} || 'FOR EACH ROW', | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%4/8
$trigger->perform_action_when || 'AFTER'
$db_events or "UPDATE"
$trigger->extra->{'reference'} || 'REFERENCING OLD AS oldrow NEW AS newrow'
$trigger->extra->{'granularity'} || 'FOR EACH ROW'
MC/DC0%0/1
$trigger->perform_action_when || 'AFTER'
$trigger->perform_action_when
MC/DC0%0/1
$db_events or "UPDATE"
$db_events
MC/DC0%0/1
$trigger->extra->{'reference'} || 'REFERENCING OLD AS oldrow NEW AS newrow'
$trigger->extra->{'reference'}
MC/DC0%0/1
$trigger->extra->{'granularity'} || 'FOR EACH ROW'
$trigger->extra->{'granularity'}
Truth table50%1/2
A
A= $trigger->perform_action_when
Truth table50%1/2
A
A= $db_events
Truth table50%1/2
A
A= $trigger->extra->{'reference'}
Truth table50%1/2
A
A= $trigger->extra->{'granularity'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | $trigger->action | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 7 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | sub alter_field { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alter_field: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | my ($from_field, $to_field) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | ▶ | my $data_type = uc($dt_translate{ lc($to_field->data_type) } || $to_field->data_type); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$dt_translate{lc $to_field->data_type} || $to_field->data_type
MC/DC0%0/2
$dt_translate{lc $to_field->data_type} || $to_field->data_type
$dt_translate{lc $to_field->data_type}
$to_field->data_type
Truth table33%1/3
A || B
A= $dt_translate{lc $to_field->data_type}B= $to_field->data_type
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | my $size = $to_field->size(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | ▶ | $data_type .= $data_type =~ /CHAR/i ? "(${size})" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # DB2 will only allow changing of varchar/vargraphic datatypes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # to extend their lengths. Or changing of text types to other | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # texttypes, and numeric types to larger numeric types. (v8) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # We can also drop/add keys, checks and constraints, but not | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # columns !? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | my $out = sprintf('ALTER TABLE %s ALTER %s SET DATATYPE %s', $to_field->table->name, $to_field->name, $data_type); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | sub add_field { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | my ($new_field) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | my $out = sprintf('ALTER TABLE %s ADD COLUMN %s', $new_field->table->name, create_field($new_field)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | ▶ | sub drop_field { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | my ($field) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||