laravel-oci8 icon indicating copy to clipboard operation
laravel-oci8 copied to clipboard

OracleGrammar.php line 161: Undefined index: object

Open dugajean opened this issue 7 years ago • 2 comments

Summary of problem or feature request

When using this code:

$queryInstance = DB::connection('myoracleconnection')->table($table);
$id = $queryInstance->insertGetId(['title' => 'My Title']);

I get the following exception:

ErrorException in OracleGrammar.php line 161:
Undefined index: object in OracleGrammar.php line 161

at HandleExceptions->handleError('8', 'Undefined index: object', '..../vendor/yajra/laravel-oci8/src/Oci8/Query/Grammars/OracleGrammar.php', '161', array('query' => object(OracleBuilder), 'values' => array('TITLE' => 'My Title'), 'sequence' => 'id')) in OracleGrammar.php line 161
at OracleGrammar->compileInsertGetId(object(OracleBuilder), array('TITLE' => 'My Title'), null) in Builder.php line 2103
at Builder->insertGetId(array('TITLE' => 'My Title')) in Do51.php line 50

I went to OracleGrammar.php line 161 and checked if there's an object key, and it was indeed not there. When I simply removed that block of code entirely and left the return statement only, I got this:

ErrorException in OracleProcessor.php line 56: Undefined index: object

When I go and comment out that block of code as well and let return, the exceptions disappear and my code works. So in conclusion, it's unsafe to assume that the object key will be available in debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 4)[3].

Is there a way to get around this without removing that code?

Code snippet of problem

The way that I'm trying to connect looks like this:

Config::set('database.connections.myoracleconnection', [
	'driver' => 'oracle',
	'host' => 'MY_ORACLE_SERVER_IP',
	'port' => 1521,
	'database' => 'user_inputted',
	'username' => 'myusername',
	'password' => 'mypass',
        'prefix' => '',
]);

$queryInstance = DB::connection('myoracleconnection')->table($table);
$id = $queryInstance->insertGetId(['title' => 'My Title']);

System details

System where Laravel is:

  • Ubuntu 14.10
  • Oracle Instant Client 11.2
  • PHP 5.6
  • PHP OCI8 Extension version 2.0.12
  • Laravel 5.2
  • Laravel OCI8 5.2.* (not sure which one exactly)

System where is Oracle 11.2 XE is installed:

  • SUSE Linux Enterprise Server 12 SP3

dugajean avatar Nov 14 '17 16:11 dugajean

debug_backtrace hack was added I think on v5.1 and was not updated maybe since 5.5. Maybe there is a change on the object arrangement on Laravel 5.2 that causes this issue.

In this regard, can you dump this code and examine the output? Backtrace is expected to return an Eloquent\Builder if I'm not mistaken.

debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 4)[3]

I don't have 5.2 project atm so I may not be able to dig this sooner. So please submit a PR when you found the fix. Thanks!

yajra avatar Nov 16 '17 05:11 yajra

object dump: debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 4)[3]: Array ( [file] => C:\Apache24\htdocs\CHART\chart\vendor\psy\psysh\src\Psy\ExecutionLoop\Loop.php [line] => 79 [function] => eval ) But then the same problem will happen in OracleProcessor line 56 I hit the problem running seeders from tinker. It appears to come from running a seeder directly from tinker rather than inside an outer seeder script that may wrap an object around the request. Putting the low level seeder inside an outer seeder eliminated the problem.

roberttrawick avatar Nov 17 '17 20:11 roberttrawick

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Nov 24 '22 02:11 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Dec 01 '22 03:12 github-actions[bot]