Quercus and App Engine – Reading from the data store.

Using brian’s scripts a base and google’s jdo documentation, I’ve got a working example of reading from the app engine data store with php.

$q = $pm->newQuery("select from phptest.test");
$results = $q->execute();
//Returns a php array of resources. Foreach doesn't seem to work here. This seems to be an issue with Quercus.
$account = count($results);
for($a=0;$a < $account; $a++){
	echo $results[$a]->getId() . " - - " . $results[$a]->getFirstName() . '
'; } $pm->close(); ?>

Its just that easy.

Deletes work the same way too. The JDO persistence manager has a method called ‘deletePersistentAll()’ which will truncate the table. To delete a specific item, select it and call ‘deletePersistent(obj)’ where the obj is your record object. See the comments below.

JDO updates your data automatically. Select the item. Change the data and when you call the persistence managers close method, the changes will be saved.

Need more info: Read the google docs.

7 thoughts on “Quercus and App Engine – Reading from the data store.

  1. I want to say, that I really love your blog.
    Please go on like that and don’t stop posting. I hope this comment motivates you to do so, smile
    regards, kali

  2. Hi, I’m have difficulties to implement the UD part of CRUD for this example. Below attemp to delete gives a 500 with java.lang.UnsupportedOperationException

    import phptest.test;
    import phptest.PMF;

    $p = PMF::get();
    $pm = $p->getPersistenceManager();
    $q = $pm->newQuery("select from phptest.test where id == 14");
    $results = $q->execute();

    echo $results[0]->getId() . " - " . $results[0]->getFirstName() . '';



  3. I see what you mean.

    As a workaround, you could call:


    The query only has one record loaded and that is the only record that will be deleted.
    This worked for me.

    Google has a 1000 record limit for queries so you’ll need to build that logic into your grid if your expecting more rows than that. See this link for more info on quotas and limits..

    For update, call the set method you defined in the java table class.

  4. Hi, I moved to the Quercus from Resin 4.0 and that solved a lot of problems, including the problem here described. However, your method is off course faster when deleting more records. (IMHO a interactive web-apps should never hit that 1000 record limit)

    I’m now working on a SQL to JDO wrapper. That way you can use ‘normal’ SQL statements in your PHP apps.

Comments are closed.