Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep getting the wrong $cluster from $record->getRid() #5

Closed
nightowl77 opened this issue Mar 1, 2015 · 6 comments
Closed

Keep getting the wrong $cluster from $record->getRid() #5

nightowl77 opened this issue Mar 1, 2015 · 6 comments
Assignees
Labels

Comments

@nightowl77
Copy link

Hi Guys

I'm not sure if my OrientDB is not compatible, but I keep getting a clusterID of -2 for a record that should have a clusterID of 12.

I checked, it happens right in Operations.php. It is misreading the raw protocol data.

My OrientDB version is OrientDB Server v2.0.3

Any guidance on how I could fix that would be appreciated.

Thank you

@Ostico
Copy link
Collaborator

Ostico commented Mar 2, 2015

Can you provide a snippet of your code to reproduce the issue?
Tnx

@nightowl77
Copy link
Author

I'm working on a client's database and he's pretty paranoid about sharing his idea, so I cannot share test data but I did manage to write you a test against a database we all have. During my test writing I've found the problem. This happens when you place properties in the SQL query. For example, this won't work

select song_type, name from V 

but this will

select  from V 

Against the gratefuldead database, that actually throws an error.

If I run the code below against my client's database, I get "-2" as a clusterID for all queries against all classes.

<?php
use PhpOrient\PhpOrient;

// Use composer autoloader to load vendor classes
require_once __DIR__ . '/../vendor/autoload.php';

$client = new PhpOrient('localhost', 2424);
$client->username = 'root';
$client->password = '********';
$client->connect();

$client->dbOpen( 'GratefulDeadConcerts', 'admin', 'admin' );

$records = $client->query( 'select song_type, name from V ' );

foreach ($records as $rec)
{
    echo "Cluster: ".$rec->getRid()->cluster  . "<br>\n";   

}

The error this will produce is:

Catchable fatal error: Argument 1 passed to PhpOrient\Protocols\Binary\Data\Record::setOData() must be of the type array, null given, called in /mnt/workspace/Sites/Phalcon//vendor/ostico/phporient/src/PhpOrient/Protocols/Common/ConfigurableTrait.php on line 18 and defined in /mnt/workspace/Sites/Phalcon//vendor/ostico/phporient/src/PhpOrient/Protocols/Binary/Data/Record.php on line 110 

Furthermore, in trying to hunt down the problem I also noticed that compser installed https://github.com/Ostico/PhpOrient.git and not this repository, but when I checked the composer file of this repo, it again referenced https://github.com/Ostico/PhpOrient.git. I'm now a bit confused as to what the "official" repo should be.

For now this is not a big issue, if anyone battles with this, they can just remove the properties from the queries.

@Ostico Ostico self-assigned this Mar 6, 2015
@Ostico
Copy link
Collaborator

Ostico commented Mar 7, 2015

Thank you, i fixed now.

For your information, https://github.com/Ostico/PhpOrient.git is the main upstream repo, but orientechnologies gave to the developers the master access to the "official" cloned repository of the drivers, so we can track issues from both.

My repositories are every time in up-to-date status so you can clone from both.

@Ostico Ostico added the bug label Mar 7, 2015
@Ostico Ostico closed this as completed Mar 7, 2015
Ostico added a commit that referenced this issue Mar 7, 2015
Improvement for Keep getting the wrong $cluster from $record->getRid() #5
@nightowl77
Copy link
Author

Thank you so much Ostico!

@nightowl77
Copy link
Author

Hi Ostico

Please excuse me if I'm being an idiot, but it seems from your tests that you are indeed expecting $rid->cluster to be -2.

On line 216 of your test SQLCommandsTest.php you AssertEquals -2 on cluster. Is this an intended design feature that I somehow missed in OrientDB tutorials?

 public function testWrongClusterID(){
$client = new PhpOrient('localhost', 2424);
$client->dbOpen( 'GratefulDeadConcerts', 'admin', 'admin' );
$records = $client->query( 'select song_type, name from V ' );
/**
* @var Record[] $records
*/
foreach ($records as $k => $rec) {
  if ( $client->getTransport()->getProtocolVersion() < 26 )
    $this->assertEquals( $k +1, $rec->getRid()->position );
  else
    $this->assertEquals( $k, $rec->getRid()->position );
  $this->assertEquals( -2, $rec->getRid()->cluster );
  }
}

I have a situation where I need the correct ClusterID and the only way around that is to manually include @Rid in the select statement, like this:

select @rid, song_type, name from V

Is this they correct way?

@Ostico
Copy link
Collaborator

Ostico commented Apr 12, 2015

Yes, As far as i know this is the right way.
By the way, if you need the right rid you can make the query without explicit fields, i think you could be interested to this discussion:
orientechnologies/orientdb#3468

Let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants