laravel-oci8
laravel-oci8 copied to clipboard
Math/arithmetic in DB::insert() causes variables with hyphens/dashes to be converted to a number
Summary of problem or feature request
When using DB::insert(...), string variables that contain a dash/hyphen are being treated as if they are numbers. This is true even if the string contains other non-numeric characters. All of these values I'm currently working with are formatted like this C#####-##, e.g., C12345-67.
This ultimately causes the INSERT query to fail, because the column in the database that stores these values (exclude_study_number) is defined as a VARCHAR(50).
Wrapping the value in strval() or DB::raw() has had no effect.
Steps to reproduce
Insert a sting value that contains numbers and a hyphen into a VARCHAR column.
DB::insert([ 'exclude_study_number' => 'C94043-01' ]);
The example above is hard coded, but when passed as a variable, the same thing happens.
Wrapping the value in strval() or DB::raw() has had no effect.
Yes, the column is named exclude_study_number, but it is defined as VARCHAR(50).
Is there a way to escape math operands in queries? Is there a reason that the letter C is being handled as a number?
System details
- Operating System: Linux and Mac OS X
- PHP Version: 5.6.23
- Laravel Version: 5.4.36
- Laravel-oci8 Version: 5.4.21
- Database Version: Oracle 11g
I just tried this on Laravel 5.8 and all works fine.
Schema::create('studies', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('exclude_study_number');
});
>>> DB::table('studies')->insert([ 'exclude_study_number' => 'C94043-01' ])
=> true
>>> DB::table('studies')->get()
=> Illuminate\Support\Collection {#4137
all: [
{#4119
+"id": "1",
+"exclude_study_number": "C94043-01",
},
],
}
>>>
Given this, it might be version specific to Laravel 5.4. I may not be able to support lower versions anymore so if you can, please do not hesitate to submit a PR for fix. Thanks!
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 7 days since being marked as stale.