Query data using the C++ binding and OQL

Previous | Top | Next

We show in this section how to query objects as defined in the ODL schema using the C++ language binding and OQL.

static void query_students(eyedb::Database *db)
{
  eyedb::OQL oql(db, "select Student");
  eyedb::ObjectArray obj_arr;
  oql.execute(obj_arr);
  unsigned int count = obj_arr.getCount();
  for (int n = 0; n < count; n++) {
    Student *s = Student_c(obj_arr[n]);
    if (s) {
      std::cout << s->getFirstname() << ” ” << s->getLastname() << std::endl;
    }
  }
}

static void query_courses(eyedb::Database *db,
			  const char *firstname, const char *lastname)
{
  eyedb::OQL oql(db, “select c from Course c where ”
		 “c.teacher.lastname = \”%s\” && ”
		 “c.teacher.firstname = \”%s\”", lastname, firstname);
  eyedb::ObjectArray obj_arr;
  oql.execute(obj_arr);
  unsigned int count = obj_arr.getCount();
  for (int n = 0; n < count; n++) {
    Course *c = Course_c(obj_arr[n]);
    if (c) {
      std::cout << firstname << ” ” << lastname << “: ” <<
	c->getTitle() << ” ” << c->getDescription() << std::endl;
    }
  }
}

View the whole C++ file

Previous | Top | Next