CUNIT_TEST(DBSuite, EagleDbParser_lastError) { CUNIT_VERIFY_NULL(EagleDbParser_lastError(NULL)); EagleDbParser *parser = EagleDbParser_New(); CUNIT_VERIFY_NULL(EagleDbParser_lastError(parser)); EagleDbParser_Delete(parser); }
EagleDbParser* _BenchSuite_distance(EagleDbInstance *db, int rows) { /* SLOW INSERT for(int i = 0; i < rows; ++i) { char sql[1024]; sprintf(sql, "INSERT INTO point (id, x, y) VALUES (%d, %g, %g);", i + 1, frand(1000.0), frand(1000.0)); //printf("%s\n", sql); success = EagleDbInstance_execute(db, sql, &error); if(EagleFalse == success) { CUNIT_FAIL("%s", error->message); } } */ EagleDbTableData *td = EagleDbInstance_getTable(db, "point"); EagleDbTuple *tuple = EagleDbTuple_New(td->table); for(int i = 0; i < rows; ++i) { EagleDbTuple_setInt(tuple, 0, i + 1); EagleDbTuple_setFloat(tuple, 1, frand(1000.0)); EagleDbTuple_setFloat(tuple, 2, frand(1000.0)); EagleDbTableData_insert(td, tuple); // this is a bit naughty, to save time on recreating the tuple for every row we are reusing it free(tuple->data[0]); free(tuple->data[1]); free(tuple->data[2]); tuple->data[0] = NULL; tuple->data[1] = NULL; tuple->data[2] = NULL; } EagleDbTuple_Delete(tuple); // do a distance search EagleDbParser *p = EagleDbParser_ParseWithString("SELECT id, x, y FROM point WHERE sqrt((500.0 - x) * (500.0 - x) + (500.0 - y) * (500.0 - y)) < 1.0"); if(EagleTrue == EagleDbParser_hasError(p)) { CUNIT_FAIL("%s", EagleDbParser_lastError(p)); } return p; }
CUNIT_TEST(DBSuite, EagleDbInformationSchema_tables) { int cores = 1; EagleDbInstance *db = EagleDbInstance_New(10, cores); /* parse sql */ EagleDbParser *p = EagleDbParser_ParseWithString("select table_schema, table_name from information_schema_tables;"); if (EagleTrue == EagleDbParser_hasError(p)) { CUNIT_FAIL("%s", EagleDbParser_lastError(p)); } CUNIT_ASSERT_FALSE(EagleDbParser_hasError(p)); EaglePlan *plan = EagleDbSqlSelect_parse((EagleDbSqlSelect*) p->yyparse_ast, db); if (EagleTrue == EaglePlan_isError(plan)) { CUNIT_FAIL("%s", plan->errorMessage); } CUNIT_ASSERT_FALSE(EaglePlan_isError(plan)); /* execute */ EagleInstance *eagle = EagleInstance_New(cores); EagleInstance_addPlan(eagle, plan); EagleInstance_run(eagle); /* check results */ EaglePage *page1 = EaglePageProvider_nextPage(plan->result[0]); EaglePage *page2 = EaglePageProvider_nextPage(plan->result[1]); CUNIT_ASSERT_NOT_NULL(page1); CUNIT_ASSERT_NOT_NULL(page2); EaglePage_Delete(page1); EaglePage_Delete(page2); EagleDbSqlExpression_DeleteRecursive((EagleDbSqlExpression*) p->yyparse_ast); EaglePlan_Delete(plan); EagleInstance_Delete(eagle); EagleDbParser_Delete(p); EagleDbInstance_Delete(db); }