Created
July 28, 2015 15:06
-
-
Save oliverlundquist/bb22204f16f66bf2c253 to your computer and use it in GitHub Desktop.
sql transactions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function handle() | |
{ | |
for($i=1; $i<=100; $i++) { | |
if ($i===1) { | |
\DB::table('transactions')->insert(['colorme_id' => $i]); | |
} else { | |
\DB::statement('insert into transactions(colorme_id) SELECT MAX(colorme_id)+1 from transactions'); | |
} | |
usleep(200000); | |
} | |
} | |
public function handle() | |
{ | |
\DB::beginTransaction(); | |
// \DB::transaction(function() | |
// { | |
sleep(2); | |
$max_colorme_id = \DB::table('transactions')->max('colorme_id'); | |
$this->info('max colorme id: ' . $max_colorme_id); | |
sleep(2); | |
\DB::table('transactions')->insert(['colorme_id' => $max_colorme_id]); | |
sleep(2); | |
// }); | |
\DB::commit(); | |
} | |
public function handle() | |
{ | |
// \DB::beginTransaction(); | |
// \DB::transaction(function() | |
// { | |
sleep(2); | |
$this->info('insert'); | |
\DB::statement('insert into transactions(colorme_id) SELECT MAX(colorme_id)+1 from transactions'); | |
sleep(2); | |
$this->info('insert & update'); | |
$id = \DB::table('transactions')->insertGetId(['colorme_id' => 0]); | |
sleep(2); | |
\DB::statement('update transactions a, (select max(colorme_id)+1 as max_id from transactions) b set a.colorme_id=b.max_id where id=' . $id); | |
sleep(2); | |
// }); | |
// \DB::commit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment