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

Fetching entities by an integer value does not seem to work #119

Open
marian-duda opened this issue May 25, 2016 · 4 comments
Open

Fetching entities by an integer value does not seem to work #119

marian-duda opened this issue May 25, 2016 · 4 comments

Comments

@marian-duda
Copy link

Hi,

Using fetchAll..
This works:
SELECT * FROM Book WHERE isbn = '1853260304';

This does not work:
SELECT * FROM Book WHERE book_id= 300;
I get an empty array as result.

Both properties are indexes.

Query works directly on Google Cloud Datastore GQL.

Am I missing something?

@tomwalder
Copy link
Owner

I expect it is something to do with the individual property data types.

Are you binding the parameters, or just passing that GQL string directly in? Could you share the code?

@marian-duda
Copy link
Author

Yeah it seems it works with binding, but string seem to work regardless:

$obj_book_schema = (new Schema('Book'))
->addString('title')
->addString('author')
->addString('isbn', TRUE)
->addDatetime('published', FALSE)
->addString('text', FALSE)
->addInteger('book_id', true);

    $gateway = new \GDS\Gateway\ProtoBuf(null, \Settings::get('datastoreNamespace'));
    $obj_book_store = new Store($obj_book_schema, $gateway);
    // So now create a simple Model object
   $obj_book = new Entity();
    $obj_book->title = 'Romeo and Juliet';
    $obj_book->author = 'William Shakespeare';
    $obj_book->isbn = '1840224339';
    $obj_book->book_id = 123;
    $obj_book_store->upsert($obj_book);

    $result = $obj_book_store->fetchAll("SELECT * FROM Book WHERE book_id = @id", ['id' => 123]); //Ok
    $result = $obj_book_store->fetchAll("SELECT * FROM Book WHERE isbn = @isbn", ['id' => '1840224339']); //Ok
    $result = $obj_book_store->fetchAll("SELECT * FROM Book WHERE book_id = 123"); //empty
    $result = $obj_book_store->fetchAll("SELECT * FROM Book WHERE isbn = '1840224339'"); // Ok.

Thanks.

@tomwalder
Copy link
Owner

If you want to use your own unique ID, then you are better using the KeyName, rather than an indexed property.

Let me know if you need more help on this.

@marian-duda
Copy link
Author

It's used to log various ids from MySQL so I don't think it's appropriate.
Would be nice is if index tagging(true/false) would be a Entity thing, and not through schema.

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

No branches or pull requests

2 participants