@@ -94,92 +94,6 @@ public function testSelectConcat()
9494 );
9595 }
9696
97- public function testUpsert ()
98- {
99- // MySQL
100- $ builder = $ this ->getMySqlBuilder ();
101- $ builder ->getConnection ()
102- ->expects ($ this ->once ())
103- ->method ('affectingStatement ' )
104- ->with ('insert into `users` (`email`, `name`) values (?, ?), (?, ?) on duplicate key update `email` = values(`email`), `name` = values(`name`) ' , ['foo ' , 'bar ' , 'foo2 ' , 'bar2 ' ])
105- ->willReturn (2 );
106- $ result = $ builder ->from ('users ' )->upsert ([['email ' => 'foo ' , 'name ' => 'bar ' ], ['name ' => 'bar2 ' , 'email ' => 'foo2 ' ]], 'email ' );
107- $ this ->assertEquals (2 , $ result );
108-
109- // PostgreSQL
110- $ builder = $ this ->getPostgresBuilder ();
111- $ builder ->getConnection ()
112- ->expects ($ this ->once ())
113- ->method ('affectingStatement ' )
114- ->with ('insert into "users" ("email", "name") values (?, ?), (?, ?) on conflict ("email") do update set "email" = "excluded"."email", "name" = "excluded"."name" ' , ['foo ' , 'bar ' , 'foo2 ' , 'bar2 ' ])
115- ->willReturn (2 );
116- $ result = $ builder ->from ('users ' )->upsert ([['email ' => 'foo ' , 'name ' => 'bar ' ], ['name ' => 'bar2 ' , 'email ' => 'foo2 ' ]], 'email ' );
117- $ this ->assertEquals (2 , $ result );
118-
119- // SQLite
120- $ builder = $ this ->getSQLiteBuilder ();
121- $ builder ->getConnection ()
122- ->expects ($ this ->once ())
123- ->method ('affectingStatement ' )
124- ->with ('insert into "users" ("email", "name") values (?, ?), (?, ?) on conflict ("email") do update set "email" = "excluded"."email", "name" = "excluded"."name" ' , ['foo ' , 'bar ' , 'foo2 ' , 'bar2 ' ])
125- ->willReturn (2 );
126- $ result = $ builder ->from ('users ' )->upsert ([['email ' => 'foo ' , 'name ' => 'bar ' ], ['name ' => 'bar2 ' , 'email ' => 'foo2 ' ]], 'email ' );
127- $ this ->assertEquals (2 , $ result );
128-
129- // SQL Server
130- $ builder = $ this ->getSqlServerBuilder ();
131- $ builder ->getConnection ()
132- ->expects ($ this ->once ())
133- ->method ('affectingStatement ' )
134- ->with ('merge [users] using (values (?, ?), (?, ?)) [laravel_source] ([email], [name]) on [laravel_source].[email] = [users].[email] when matched then update set [email] = [laravel_source].[email], [name] = [laravel_source].[name] when not matched then insert ([email], [name]) values ([email], [name]); ' , ['foo ' , 'bar ' , 'foo2 ' , 'bar2 ' ])
135- ->willReturn (2 );
136- $ result = $ builder ->from ('users ' )->upsert ([['email ' => 'foo ' , 'name ' => 'bar ' ], ['name ' => 'bar2 ' , 'email ' => 'foo2 ' ]], 'email ' );
137- $ this ->assertEquals (2 , $ result );
138- }
139-
140- public function testUpsertWithUpdateColumns ()
141- {
142- // MySQL
143- $ builder = $ this ->getMySqlBuilder ();
144- $ builder ->getConnection ()
145- ->expects ($ this ->once ())
146- ->method ('affectingStatement ' )
147- ->with ('insert into `users` (`email`, `name`) values (?, ?), (?, ?) on duplicate key update `name` = values(`name`) ' , ['foo ' , 'bar ' , 'foo2 ' , 'bar2 ' ])
148- ->willReturn (2 );
149- $ result = $ builder ->from ('users ' )->upsert ([['email ' => 'foo ' , 'name ' => 'bar ' ], ['name ' => 'bar2 ' , 'email ' => 'foo2 ' ]], 'email ' , ['name ' ]);
150- $ this ->assertEquals (2 , $ result );
151-
152- // PostgreSQL
153- $ builder = $ this ->getPostgresBuilder ();
154- $ builder ->getConnection ()
155- ->expects ($ this ->once ())
156- ->method ('affectingStatement ' )
157- ->with ('insert into "users" ("email", "name") values (?, ?), (?, ?) on conflict ("email") do update set "name" = "excluded"."name" ' , ['foo ' , 'bar ' , 'foo2 ' , 'bar2 ' ])
158- ->willReturn (2 );
159- $ result = $ builder ->from ('users ' )->upsert ([['email ' => 'foo ' , 'name ' => 'bar ' ], ['name ' => 'bar2 ' , 'email ' => 'foo2 ' ]], 'email ' , ['name ' ]);
160- $ this ->assertEquals (2 , $ result );
161-
162- // SQLite
163- $ builder = $ this ->getSQLiteBuilder ();
164- $ builder ->getConnection ()
165- ->expects ($ this ->once ())
166- ->method ('affectingStatement ' )
167- ->with ('insert into "users" ("email", "name") values (?, ?), (?, ?) on conflict ("email") do update set "name" = "excluded"."name" ' , ['foo ' , 'bar ' , 'foo2 ' , 'bar2 ' ])
168- ->willReturn (2 );
169- $ result = $ builder ->from ('users ' )->upsert ([['email ' => 'foo ' , 'name ' => 'bar ' ], ['name ' => 'bar2 ' , 'email ' => 'foo2 ' ]], 'email ' , ['name ' ]);
170- $ this ->assertEquals (2 , $ result );
171-
172- // SQL Server
173- $ builder = $ this ->getSqlServerBuilder ();
174- $ builder ->getConnection ()
175- ->expects ($ this ->once ())
176- ->method ('affectingStatement ' )
177- ->with ('merge [users] using (values (?, ?), (?, ?)) [laravel_source] ([email], [name]) on [laravel_source].[email] = [users].[email] when matched then update set [name] = [laravel_source].[name] when not matched then insert ([email], [name]) values ([email], [name]); ' , ['foo ' , 'bar ' , 'foo2 ' , 'bar2 ' ])
178- ->willReturn (2 );
179- $ result = $ builder ->from ('users ' )->upsert ([['email ' => 'foo ' , 'name ' => 'bar ' ], ['name ' => 'bar2 ' , 'email ' => 'foo2 ' ]], 'email ' , ['name ' ]);
180- $ this ->assertEquals (2 , $ result );
181- }
182-
18397 protected function getConnection ($ connection = null )
18498 {
18599 if ($ connection ) {
0 commit comments