Example #1
0
int CustomQuery(int, char* [])
{
  const auto foo = test::TabFoo{};
  const auto bar = test::TabBar{};
  auto db = MockDb{};

  // Unconditionally
  compare(__LINE__, custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), from(foo),
                                 sqlpp::unconditionally()),
          "SELECT  DISTINCT  tab_foo.omega  FROM tab_foo ");

  // A full select statement made individual clauses
  compare(__LINE__,
          custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega),
                       from(foo.join(bar).on(foo.omega == bar.alpha)), where(bar.alpha > 17), group_by(foo.omega),
                       having(avg(bar.alpha) > 19), order_by(foo.omega.asc()), sqlpp::limit(10), sqlpp::offset(100)),
          "SELECT  DISTINCT  tab_foo.omega  FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha)  WHERE "
          "(tab_bar.alpha>17)  GROUP BY tab_foo.omega  HAVING (AVG(tab_bar.alpha)>19)  ORDER BY tab_foo.omega ASC  "
          "LIMIT 10  OFFSET 100");

  // A full select statement made individual clauses
  compare(
      __LINE__,
      custom_query(sqlpp::select(), dynamic_select_flags(db, sqlpp::distinct), dynamic_select_columns(db, foo.omega),
                   dynamic_from(db, foo.join(bar).on(foo.omega == bar.alpha)), dynamic_where(db, bar.alpha > 17),
                   dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19),
                   dynamic_order_by(db, foo.omega.asc()), sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)),
      "SELECT  DISTINCT  tab_foo.omega  FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha)  WHERE "
      "(tab_bar.alpha>17)  GROUP BY tab_foo.omega  HAVING (AVG(tab_bar.alpha)>19)  ORDER BY tab_foo.omega ASC  ");

  return 0;
}
Example #2
0
void tlistbox::order_by_column(unsigned column, twidget& widget)
{
	tselectable_& selectable = dynamic_cast<tselectable_&>(widget);
	if(column >= orders_.size()) {
		return;
	}
	for(auto& pair : orders_)
	{
		if(pair.first != nullptr && pair.first != &selectable) {
			pair.first->set_value(0);
		}
	}
	if(selectable.get_value() > orders_[column].second.size()) {
		return;
	}
	if(selectable.get_value() == 0) {
		order_by(tgenerator_::torder_func(&default_sort));
	}
	else {
		order_by(orders_[column].second[selectable.get_value() - 1]);
	}
}
Example #3
0
int CustomQuery(int, char*[])
{
  const auto foo = test::TabFoo{};
  const auto bar = test::TabBar{};
  auto db = MockDb{};

  // Unconditionally
  compare(__LINE__,
          custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), from(foo),
                       sqlpp::unconditionally()),
          "SELECT  DISTINCT  tab_foo.omega  FROM tab_foo ");

  // A full select statement made individual clauses
  compare(__LINE__,
          custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega),
                       from(foo.join(bar).on(foo.omega == bar.alpha)), where(bar.alpha > 17), group_by(foo.omega),
                       having(avg(bar.alpha) > 19), order_by(foo.omega.asc()), sqlpp::limit(10u), sqlpp::offset(100u)),
          "SELECT  DISTINCT  tab_foo.omega  FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha)  WHERE "
          "(tab_bar.alpha>17)  GROUP BY tab_foo.omega  HAVING (AVG(tab_bar.alpha)>19)  ORDER BY tab_foo.omega ASC  "
          "LIMIT 10  OFFSET 100");

  // A full select statement made individual clauses
  compare(
      __LINE__,
      custom_query(sqlpp::select(), dynamic_select_flags(db, sqlpp::distinct), dynamic_select_columns(db, foo.omega),
                   dynamic_from(db, foo.join(bar).on(foo.omega == bar.alpha)), dynamic_where(db, bar.alpha > 17),
                   dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19),
                   dynamic_order_by(db, foo.omega.asc(), foo.psi.order(sqlpp::sort_type::desc)),
                   sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)),
      "SELECT  DISTINCT  tab_foo.omega  FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha)  WHERE "
      "(tab_bar.alpha>17)  GROUP BY tab_foo.omega  HAVING (AVG(tab_bar.alpha)>19)  ORDER BY tab_foo.omega "
      "ASC,tab_foo.psi DESC  ");

  // A pragma query for sqlite
  compare(__LINE__,
          custom_query(sqlpp::verbatim("PRAGMA user_version")).with_result_type_of(select(sqlpp::value(1).as(pragma))),
          " PRAGMA user_version");

  // An insert from select for postgresql
  const auto x = 17;
  compare(__LINE__,
          custom_query(insert_into(foo).columns(foo.omega),
                       select(sqlpp::value(x).as(foo.omega))
                           .from(foo)
                           .where(not exists(select(foo.omega).from(foo).where(foo.omega == x)))),
          "INSERT INTO tab_foo (omega) "
          "SELECT 17 AS omega FROM tab_foo "
          "WHERE (NOT EXISTS(SELECT tab_foo.omega FROM tab_foo WHERE (tab_foo.omega=17)))");

  return 0;
}
Example #4
0
void listbox::order_by_column(unsigned column, widget& widget)
{
	selectable_item& selectable = dynamic_cast<selectable_item&>(widget);
	if(column >= orders_.size()) {
		return;
	}

	for(auto& pair : orders_) {
		if(pair.first != nullptr && pair.first != &selectable) {
			pair.first->set_value(SORT_NONE);
		}
	}

	if(selectable.get_value() > orders_[column].second.size()) {
		return;
	}

	if(selectable.get_value() == SORT_NONE) {
		order_by(std::less<unsigned>());
	} else {
		order_by(orders_[column].second[selectable.get_value() - 1]);
	}
}
    multicolor_gauss_seidel(
            const Matrix &A,
            const params&,
            const typename Backend::params&
            ) : order( backend::rows(A) )
    {
        const size_t n = backend::rows(A);

        std::vector<int> color(n);
        num_colors = boost::sequential_vertex_coloring(amgcl::detail::as_graph(A), &color[0]);

        ptr.resize(num_colors + 1, 0);

        for(size_t i = 0; i < n; ++i) {
            ++ptr[ color[i] + 1];
            order[i] = i;
        }

        boost::stable_sort(order, order_by(color));
        boost::partial_sum(ptr, ptr.begin());
    }