Search in sources :

Example 16 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testSkipZeroOrdered.

@Test
public void testSkipZeroOrdered() {
    OSQLSynchQuery sql = new OSQLSynchQuery("SELECT from alphabet ORDER BY letter SKIP 0");
    List<ODocument> results = db.query(sql);
    assertEquals(26, results.size());
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 17 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testLetOrder.

@Test
public void testLetOrder() {
    OSQLSynchQuery sql = new OSQLSynchQuery("SELECT" + "      source," + "  $maxYear as maxYear" + "              FROM" + "      (" + "          SELECT expand( $union ) " + "  LET" + "      $a = (SELECT 'A' as source, 2013 as year)," + "  $b = (SELECT 'B' as source, 2012 as year)," + "  $union = unionAll($a,$b) " + "  ) " + "  LET " + "      $maxYear = max(year)" + "  GROUP BY" + "  source");
    try {
        List<ODocument> results = db.query(sql);
        fail("Invalid query, usage of LET, aggregate functions and GROUP BY together is not supported");
    } catch (OCommandSQLParsingException x) {
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 18 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testParamWithMatchesAndNot.

@Test
public void testParamWithMatchesAndNot() {
    // issue #5229
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("param1", "adm.*");
    params.put("param2", "foo.*");
    OSQLSynchQuery sql = new OSQLSynchQuery("select from OUser where (name matches :param1 and not (name matches :param2))");
    List<ODocument> results = db.query(sql, params);
    assertEquals(results.size(), 1);
    params.put("param1", Pattern.quote("adm") + ".*");
    results = db.query(sql, params);
    assertEquals(results.size(), 1);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 19 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testFilterAndOrderBy.

@Test
public void testFilterAndOrderBy() {
    // issue http://www.prjhub.com/#/issues/6199
    OSQLSynchQuery sql = new OSQLSynchQuery("SELECT FROM FilterAndOrderByTest WHERE active = true ORDER BY dc DESC");
    List<ODocument> results = db.query(sql);
    assertEquals(results.size(), 3);
    Calendar cal = new GregorianCalendar();
    Date date = results.get(0).field("dc");
    cal.setTime(date);
    assertEquals(cal.get(Calendar.YEAR), 2016);
    date = results.get(1).field("dc");
    cal.setTime(date);
    assertEquals(cal.get(Calendar.YEAR), 2010);
    date = results.get(2).field("dc");
    cal.setTime(date);
    assertEquals(cal.get(Calendar.YEAR), 2009);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 20 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testParamWithMatchesQuoteRegex.

@Test
public void testParamWithMatchesQuoteRegex() {
    // issue #5229
    Map<String, Object> params = new HashMap<String, Object>();
    // will not work
    params.put("param1", ".*admin[name].*");
    OSQLSynchQuery sql = new OSQLSynchQuery("select from matchesstuff where name matches :param1");
    List<ODocument> results = db.query(sql, params);
    assertEquals(results.size(), 0);
    // should work
    params.put("param1", Pattern.quote("admin[name]") + ".*");
    results = db.query(sql, params);
    assertEquals(results.size(), 1);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)530 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)445 Test (org.testng.annotations.Test)287 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)83 Test (org.junit.Test)73 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)59 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)53 ORID (com.orientechnologies.orient.core.id.ORID)36 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)32 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)23 HashMap (java.util.HashMap)23 List (java.util.List)22 ORecordId (com.orientechnologies.orient.core.id.ORecordId)19 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)19 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)16 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)15 Collection (java.util.Collection)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)14 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)13 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)12