diff --git a/src/Illuminate/Database/MySqlConnection.php b/src/Illuminate/Database/MySqlConnection.php index 24a2cfbd9eb0..94b5b57d87e0 100755 --- a/src/Illuminate/Database/MySqlConnection.php +++ b/src/Illuminate/Database/MySqlConnection.php @@ -7,7 +7,6 @@ use Illuminate\Database\Query\Processors\MySqlProcessor; use Illuminate\Database\Schema\Grammars\MySqlGrammar as SchemaGrammar; use Illuminate\Database\Schema\MySqlBuilder; -use PDO; class MySqlConnection extends Connection { @@ -64,21 +63,4 @@ protected function getDoctrineDriver() { return new DoctrineDriver; } - - /** - * Bind values to their parameters in the given statement. - * - * @param \PDOStatement $statement - * @param array $bindings - * @return void - */ - public function bindValues($statement, $bindings) - { - foreach ($bindings as $key => $value) { - $statement->bindValue( - is_string($key) ? $key : $key + 1, $value, - is_int($value) || is_float($value) ? PDO::PARAM_INT : PDO::PARAM_STR - ); - } - } } diff --git a/tests/Integration/Database/EloquentMySqlConnectionTest.php b/tests/Integration/Database/EloquentMySqlConnectionTest.php new file mode 100755 index 000000000000..60f2c7d6ed5b --- /dev/null +++ b/tests/Integration/Database/EloquentMySqlConnectionTest.php @@ -0,0 +1,91 @@ +set('app.debug', 'true'); + + // Database configuration + $app['config']->set('database.default', 'testbench'); + + $app['config']->set('database.connections.testbench', [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'username' => 'root', + 'password' => '', + 'database' => 'forge', + 'prefix' => '', + ]); + } + + protected function setUp(): void + { + parent::setUp(); + + if (! Schema::hasTable(self::TABLE)) { + Schema::create(self::TABLE, function (Blueprint $table) { + $table->json(self::JSON_COL)->nullable(); + $table->float(self::FLOAT_COL)->nullable(); + }); + } + } + + protected function tearDown(): void + { + DB::table(self::TABLE)->truncate(); + + parent::tearDown(); + } + + /** + * @dataProvider floatComparisonsDataProvider + * + * @param float $value the value to compare against the JSON value + * @param string $operator the comparison operator to use. e.g. '<', '>', '=' + * @param bool $shouldMatch true if the comparison should match, false if not + */ + public function testJsonFloatComparison(float $value, string $operator, bool $shouldMatch): void + { + DB::table(self::TABLE)->insert([self::JSON_COL => '{"rank":'.self::FLOAT_VAL.'}']); + $this->assertSame( + $shouldMatch, + DB::table(self::TABLE)->where(self::JSON_COL.'->rank', $operator, $value)->exists(), + self::JSON_COL.'->rank should '.($shouldMatch ? '' : 'not ')."be $operator $value" + ); + } + + public function floatComparisonsDataProvider(): array + { + return [ + [0.2, '=', true], + [0.2, '>', false], + [0.2, '<', false], + [0.1, '=', false], + [0.1, '<', false], + [0.1, '>', true], + [0.3, '=', false], + [0.3, '<', true], + [0.3, '>', false], + ]; + } + + public function testFloatValueStoredCorrectly(): void + { + DB::table(self::TABLE)->insert([self::FLOAT_COL => self::FLOAT_VAL]); + $this->assertEquals(self::FLOAT_VAL, DB::table(self::TABLE)->value(self::FLOAT_COL)); + } +}