9 my $schema = DBICTest->init_schema();
11 # The map below generates stuff like:
12 # [ qw/artistid name/ ],
19 my $start_id = 'populateXaaaaaa';
23 $schema->populate('Artist', [ [ qw/artistid name/ ], map { [ ($_ + $offset) => $start_id++ ] } ( 1 .. $rows ) ] );
25 $schema->resultset ('Artist')->search ({ name => { -like => 'populateX%' } })->count,
27 'populate created correct number of rows with massive AoA bulk insert',
30 my $artist = $schema->resultset ('Artist')
31 ->search ({ 'cds.title' => { '!=', undef } }, { join => 'cds' })
33 my $ex_title = $artist->cds->first->title;
37 $schema->populate('CD', [
40 artist => $artist->id,
44 } ('Huey', 'Dewey', $ex_title, 'Louie')
46 }, qr/columns .+ are not unique for populate slice.+$ex_title/ms, 'Readable exception thrown for failed populate');
48 ## make sure populate honors fields/orders in list context
50 my @links = $schema->populate('Link', [
56 my $link2 = shift @links;
57 is($link2->id, 2, 'Link 2 id');
58 is($link2->url, 'burl', 'Link 2 url');
59 is($link2->title, 'btitle', 'Link 2 title');
62 @links = $schema->populate('Link', [
68 my $link3 = shift @links;
69 is($link3->id, 3, 'Link 3 id');
70 is($link3->url, 'curl', 'Link 3 url');
71 is($link3->title, 'ctitle', 'Link 3 title');
73 ## not all physical columns
74 @links = $schema->populate('Link', [
80 my $link4 = shift @links;
81 is($link4->id, 4, 'Link 4 id');
82 is($link4->url, undef, 'Link 4 url');
83 is($link4->title, 'dtitle', 'Link 4 title');
86 ## make sure populate -> insert_bulk honors fields/orders in void context
88 $schema->populate('Link', [
92 my $link5 = $schema->resultset('Link')->find(5);
93 is($link5->id, 5, 'Link 5 id');
94 is($link5->url, 'eurl', 'Link 5 url');
95 is($link5->title, 'etitle', 'Link 5 title');
98 $schema->populate('Link', [
100 [ qw/6 ftitle furl/ ]
102 my $link6 = $schema->resultset('Link')->find(6);
103 is($link6->id, 6, 'Link 6 id');
104 is($link6->url, 'furl', 'Link 6 url');
105 is($link6->title, 'ftitle', 'Link 6 title');
107 ## not all physical columns
108 $schema->populate('Link', [
112 my $link7 = $schema->resultset('Link')->find(7);
113 is($link7->id, 7, 'Link 7 id');
114 is($link7->url, undef, 'Link 7 url');
115 is($link7->title, 'gtitle', 'Link 7 title');
117 # test _execute_array_empty (insert_bulk with all literal sql)
118 my $rs = $schema->resultset('Artist');
124 charfield => \"'mtfnpy'",
131 $_->charfield eq 'mtfnpy'
132 } $rs->all), 5, 'populate with all literal SQL');
143 artistid => 'foo', # this dies
151 } qr/slice/, 'bad slice';
153 is($rs->count, 0, 'populate is atomic');
155 # Trying to use a column marked as a bind in the first slice with literal sql in
156 # a later slice should throw.
169 } qr/bind expected/, 'literal sql where bind expected throws';
171 # ... and vice-versa.
184 } qr/literal SQL expected/i, 'bind where literal sql expected throws';
197 } qr/inconsistent/, 'literal sql must be the same in all slices';