| 1 | package DBIO::Test::Conformance::Cases::Bind; | ||
| 2 | # ABSTRACT: The shared Bind cases every DBIO driver answers | ||
| 3 | |||
| 4 | 4 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 4 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 4 | our $VERSION = '0.900007'; | |
| 8 | |||
| 9 | 4 | ▶ | use DBIO::Util (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | |||
| 12 | 36 | ▶ | my $id = sub { +{ data_type => 'integer', is_nullable => 0 } }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | # the table most cases bind into: a key and one nullable column of a base type, | ||
| 15 | # or varchar(n) for a short string a case searches by value | ||
| 16 | 20 | ▶ | my $val = sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 17 | 20 | my ($type, %extra) = @_; | |
| 18 | return { | ||
| 19 | 20 | name => 'Val', table => 'val', | |
| 20 | columns => [ | ||
| 21 | id => $id->(), | ||
| 22 | v => { data_type => $type, is_nullable => 1, %extra }, | ||
| 23 | ], | ||
| 24 | primary_key => [ 'id' ], | ||
| 25 | }; | ||
| 26 | 4 | }; | |
| 27 | |||
| 28 | 4 | my $ALL = [qw(create find search update)]; | |
| 29 | |||
| 30 | # $n characters A..Z, a different run for a different seed | ||
| 31 | 20 | ▶ | my $text = sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 32 | 20 | my ($n, $seed) = @_; | |
| 33 | 20 | return join '', map { chr(65 + (($_ * 7 + $seed) % 26)) } 0 .. $n - 1; | |
| 34 | 4 | }; | |
| 35 | |||
| 36 | # $n bytes, every value of 0..255 in a fixed order | ||
| 37 | 12 | ▶ | my $bytes = sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 38 | 12 | my ($n) = @_; | |
| 39 | 12 | return join '', map { chr(($_ * 31 + 7) % 256) } 0 .. $n - 1; | |
| 40 | 4 | }; | |
| 41 | |||
| 42 | my @CASES = ( | ||
| 43 | |||
| 44 | { | ||
| 45 | name => 'bind-empty-string', | ||
| 46 | since => 1, | ||
| 47 | subject => { source => 'Val', column => 's' }, | ||
| 48 | input => { sources => [ { | ||
| 49 | name => 'Val', table => 'val', | ||
| 50 | columns => [ | ||
| 51 | id => $id->(), | ||
| 52 | s => { data_type => 'varchar', size => 20, is_nullable => 1 }, | ||
| 53 | n => { data_type => 'integer', is_nullable => 1 }, | ||
| 54 | ], | ||
| 55 | primary_key => [ 'id' ], | ||
| 56 | } ] }, | ||
| 57 | expect => [ | ||
| 58 | { bind_roundtrip => { source => 'Val', column => 's', values => [ '' ], ops => $ALL } }, | ||
| 59 | { rejects => { source => 'Val', create => { id => 9000, n => '' } } }, | ||
| 60 | ], | ||
| 61 | }, | ||
| 62 | |||
| 63 | { | ||
| 64 | name => 'bind-digit-string-leading-zero', | ||
| 65 | since => 1, | ||
| 66 | subject => { source => 'Val', column => 'v' }, | ||
| 67 | input => { sources => [ $val->('varchar', size => 20) ] }, | ||
| 68 | expect => [ | ||
| 69 | { bind_roundtrip => { source => 'Val', column => 'v', | ||
| 70 | values => [ '01234', '007' ], ops => $ALL } }, | ||
| 71 | # the same values once more, each after a statement that bound an integer | ||
| 72 | { bind_roundtrip => { source => 'Val', column => 'v', | ||
| 73 | values => [ '01234', '007' ], ops => [ 'int_first', @$ALL ] } }, | ||
| 74 | ], | ||
| 75 | }, | ||
| 76 | |||
| 77 | { | ||
| 78 | name => 'bind-integer-string-in-expression', | ||
| 79 | since => 1, | ||
| 80 | subject => { source => 'Val', column => 'v' }, | ||
| 81 | input => { sources => [ $val->('varchar', size => 20) ] }, | ||
| 82 | expect => [ | ||
| 83 | # numerically equal, textually different: found only as the application wrote it | ||
| 84 | { bind_roundtrip => { source => 'Val', column => 'v', | ||
| 85 | values => [ '5', '5.0', '05', '1e2', '100', '-0', '0' ], | ||
| 86 | ops => $ALL } }, | ||
| 87 | ], | ||
| 88 | }, | ||
| 89 | |||
| 90 | { | ||
| 91 | name => 'bind-long-string', | ||
| 92 | since => 1, | ||
| 93 | subject => { source => 'Val', column => 'v' }, | ||
| 94 | input => { sources => [ $val->('text') ] }, | ||
| 95 | expect => [ | ||
| 96 | { bind_roundtrip => { source => 'Val', column => 'v', | ||
| 97 | 16 | values => [ map { $text->($_, $_) } 4001, 8001, 32769, 70000 ], | |
| 98 | ops => $ALL } }, | ||
| 99 | ], | ||
| 100 | }, | ||
| 101 | |||
| 102 | { | ||
| 103 | name => 'bind-non-ascii', | ||
| 104 | since => 1, | ||
| 105 | subject => { source => 'Val', column => 'v' }, | ||
| 106 | input => { sources => [ $val->('text') ] }, | ||
| 107 | expect => [ | ||
| 108 | { bind_roundtrip => { source => 'Val', column => 'v', | ||
| 109 | values => [ | ||
| 110 | "\x{fc}", "\x{20ac}", "\x{65e5}", | ||
| 111 | "Gr\x{fc}\x{df}e \x{20ac}", | ||
| 112 | "\x{65e5}\x{672c}\x{8a9e}", | ||
| 113 | ( "Gr\x{fc}\x{df}e \x{20ac}" x 715 ), | ||
| 114 | ( "\x{65e5}\x{672c}\x{8a9e}" x 1667 ), | ||
| 115 | ], | ||
| 116 | ops => $ALL } }, | ||
| 117 | ], | ||
| 118 | }, | ||
| 119 | |||
| 120 | { | ||
| 121 | name => 'bind-binary', | ||
| 122 | since => 1, | ||
| 123 | subject => { source => 'Val', column => 'v' }, | ||
| 124 | input => { sources => [ $val->('blob') ] }, | ||
| 125 | expect => [ | ||
| 126 | { bind_roundtrip => { source => 'Val', column => 'v', | ||
| 127 | 4 | values => [ join('', map { chr } 0 .. 255), $bytes->(9000) ], | |
| 128 | ops => $ALL } }, | ||
| 129 | ], | ||
| 130 | }, | ||
| 131 | |||
| 132 | { | ||
| 133 | name => 'bind-lob-empty-and-large', | ||
| 134 | since => 1, | ||
| 135 | subject => { source => 'Lob', column => 't' }, | ||
| 136 | input => { sources => [ { | ||
| 137 | name => 'Lob', table => 'lob', | ||
| 138 | columns => [ | ||
| 139 | id => $id->(), | ||
| 140 | t => { data_type => 'text', is_nullable => 1 }, | ||
| 141 | b => { data_type => 'blob', is_nullable => 1 }, | ||
| 142 | ], | ||
| 143 | primary_key => [ 'id' ], | ||
| 144 | } ] }, | ||
| 145 | expect => [ | ||
| 146 | # a LOB is not searched by value on most engines: create, read back, update | ||
| 147 | { bind_roundtrip => { source => 'Lob', column => 't', | ||
| 148 | values => [ '', $text->(100000, 3) ], ops => [qw(create update)] } }, | ||
| 149 | { bind_roundtrip => { source => 'Lob', column => 'b', | ||
| 150 | values => [ '', $bytes->(100000) ], ops => [qw(create update)] } }, | ||
| 151 | ], | ||
| 152 | }, | ||
| 153 | |||
| 154 | { | ||
| 155 | name => 'bind-lob-row-operations', | ||
| 156 | since => 1, | ||
| 157 | subject => { source => 'Doc', column => 'body' }, | ||
| 158 | input => { sources => [ { | ||
| 159 | name => 'Doc', table => 'doc', | ||
| 160 | columns => [ | ||
| 161 | id => { data_type => 'integer', is_auto_increment => 1, is_nullable => 0 }, | ||
| 162 | label => { data_type => 'text', is_nullable => 1 }, | ||
| 163 | body => { data_type => 'blob', is_nullable => 1 }, | ||
| 164 | ], | ||
| 165 | primary_key => [ 'id' ], | ||
| 166 | } ] }, | ||
| 167 | expect => [ | ||
| 168 | { bind_lob_ops => { source => 'Doc', column => 'body', label_column => 'label', | ||
| 169 | value => $bytes->(20000) } }, | ||
| 170 | ], | ||
| 171 | }, | ||
| 172 | |||
| 173 | { | ||
| 174 | name => 'bind-question-mark-in-literal', | ||
| 175 | since => 1, | ||
| 176 | subject => { source => 'Note', column => 'txt' }, | ||
| 177 | input => { sources => [ { | ||
| 178 | name => 'Note', table => 'note', | ||
| 179 | columns => [ | ||
| 180 | id => $id->(), | ||
| 181 | txt => { data_type => 'varchar', size => 20, is_nullable => 1 }, | ||
| 182 | ], | ||
| 183 | primary_key => [ 'id' ], | ||
| 184 | } ] }, | ||
| 185 | expect => [ | ||
| 186 | # a ? in a string literal and in a comment stays; the one real bind lands | ||
| 187 | { bind_literal => { source => 'Note', column => 'txt', | ||
| 188 | create => { id => 1, txt => 'x' }, value => 'x', other => 'y', | ||
| 189 | literal => q{{{txt}} = ? AND 'a?b' = 'a?b' /* is this a ? */} } }, | ||
| 190 | ], | ||
| 191 | }, | ||
| 192 | |||
| 193 | { | ||
| 194 | name => 'bind-numeric-exact', | ||
| 195 | since => 1, | ||
| 196 | subject => { source => 'Num', column => 'v' }, | ||
| 197 | input => { sources => [ { | ||
| 198 | name => 'Num', table => 'num', | ||
| 199 | columns => [ | ||
| 200 | id => $id->(), | ||
| 201 | v => { data_type => 'numeric', size => [ 20, 4 ], is_nullable => 1 }, | ||
| 202 | ], | ||
| 203 | primary_key => [ 'id' ], | ||
| 204 | } ] }, | ||
| 205 | expect => [ | ||
| 206 | { bind_roundtrip => { source => 'Num', column => 'v', | ||
| 207 | values => [ '1234567890123456.7890', '-1234567890123456.7890', | ||
| 208 | '0.0001' ], | ||
| 209 | ops => $ALL } }, | ||
| 210 | ], | ||
| 211 | }, | ||
| 212 | |||
| 213 | ); | ||
| 214 | |||
| 215 | 42 | ▶ | sub cases { |
|
Subroutine
cases: called CC=1 SCAR=0.0
Pod
documented
| |||
| 216 | 42 | return DBIO::Util::deep_copy([ @CASES ]); | |
| 217 | } | ||
| 218 | |||
| 219 | 4 | 1; | |
| 220 | |||
| 221 | __END__ | ||