MainController::MainController(): m_mw(new MainWindow), m_search(m_mw) { connect(m_mw, SIGNAL(s_save(QString)), this, SLOT(save(QString))); connect(m_mw, SIGNAL(s_load(QString)), this, SLOT(load(QString))); connect(m_mw, SIGNAL(s_newBase()), this, SLOT(newBase())); connect(m_mw, SIGNAL(s_addCategory(QString)), this, SLOT(newCategory(QString))); connect(m_mw, SIGNAL(s_removeCategory(QString)), this, SLOT(removeCategory(QString))); connect(m_mw, SIGNAL(s_seeCategory()), this, SLOT(editCategory())); connect(m_mw, SIGNAL(s_showCategory()), this, SLOT(showCategory())); connect(m_mw, SIGNAL(s_addMedia(QString)), this, SLOT(newMedia(QString))); connect(m_mw, SIGNAL(s_removeMedia(QString,QString)), this, SLOT(removeMedia(QString,QString))); connect(m_mw, SIGNAL(s_seeMedia()), this, SLOT(editMedia())); connect(m_mw, SIGNAL(s_showUser()), this, SLOT(setUser())); connect(m_mw, SIGNAL(s_search()), this, SLOT(search())); connect(&m_search, SIGNAL(s_find(QList<MediaSPointer>)), this, SLOT(showSearch(QList<MediaSPointer>))); connect(m_mw, SIGNAL(s_settings()), this, SLOT(settings())); m_mw->setShortcut(SettingsController::settings()); SettingsController artemis; artemis.newSettings(SettingsController::settings()); if(UserController::userCount() == 0) UserController().exec(); else UserController::connectUser(); }
bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { auto select_query = std::make_shared<ASTSelectQuery>(); node = select_query; ParserKeyword s_select("SELECT"); ParserKeyword s_distinct("DISTINCT"); ParserKeyword s_from("FROM"); ParserKeyword s_prewhere("PREWHERE"); ParserKeyword s_where("WHERE"); ParserKeyword s_group_by("GROUP BY"); ParserKeyword s_with("WITH"); ParserKeyword s_totals("TOTALS"); ParserKeyword s_having("HAVING"); ParserKeyword s_order_by("ORDER BY"); ParserKeyword s_limit("LIMIT"); ParserKeyword s_settings("SETTINGS"); ParserKeyword s_by("BY"); ParserNotEmptyExpressionList exp_list(false); ParserNotEmptyExpressionList exp_list_for_with_clause(false, true); /// Set prefer_alias_to_column_name for each alias. ParserNotEmptyExpressionList exp_list_for_select_clause(true); /// Allows aliases without AS keyword. ParserExpressionWithOptionalAlias exp_elem(false); ParserOrderByExpressionList order_list; /// WITH expr list { if (s_with.ignore(pos, expected)) { if (!exp_list_for_with_clause.parse(pos, select_query->with_expression_list, expected)) return false; } } /// SELECT [DISTINCT] expr list { if (!s_select.ignore(pos, expected)) return false; if (s_distinct.ignore(pos, expected)) select_query->distinct = true; if (!exp_list_for_select_clause.parse(pos, select_query->select_expression_list, expected)) return false; } /// FROM database.table or FROM table or FROM (subquery) or FROM tableFunction(...) if (s_from.ignore(pos, expected)) { if (!ParserTablesInSelectQuery().parse(pos, select_query->tables, expected)) return false; } /// PREWHERE expr if (s_prewhere.ignore(pos, expected)) { if (!exp_elem.parse(pos, select_query->prewhere_expression, expected)) return false; } /// WHERE expr if (s_where.ignore(pos, expected)) { if (!exp_elem.parse(pos, select_query->where_expression, expected)) return false; } /// GROUP BY expr list if (s_group_by.ignore(pos, expected)) { if (!exp_list.parse(pos, select_query->group_expression_list, expected)) return false; } /// WITH TOTALS if (s_with.ignore(pos, expected)) { if (!s_totals.ignore(pos, expected)) return false; select_query->group_by_with_totals = true; } /// HAVING expr if (s_having.ignore(pos, expected)) { if (!exp_elem.parse(pos, select_query->having_expression, expected)) return false; } /// ORDER BY expr ASC|DESC COLLATE 'locale' list if (s_order_by.ignore(pos, expected)) { if (!order_list.parse(pos, select_query->order_expression_list, expected)) return false; } /// LIMIT length | LIMIT offset, length | LIMIT count BY expr-list if (s_limit.ignore(pos, expected)) { ParserToken s_comma(TokenType::Comma); ParserNumber num; if (!num.parse(pos, select_query->limit_length, expected)) return false; if (s_comma.ignore(pos, expected)) { select_query->limit_offset = select_query->limit_length; if (!num.parse(pos, select_query->limit_length, expected)) return false; } else if (s_by.ignore(pos, expected)) { select_query->limit_by_value = select_query->limit_length; select_query->limit_length = nullptr; if (!exp_list.parse(pos, select_query->limit_by_expression_list, expected)) return false; } } /// LIMIT length | LIMIT offset, length if (s_limit.ignore(pos, expected)) { if (!select_query->limit_by_value || select_query->limit_length) return false; ParserToken s_comma(TokenType::Comma); ParserNumber num; if (!num.parse(pos, select_query->limit_length, expected)) return false; if (s_comma.ignore(pos, expected)) { select_query->limit_offset = select_query->limit_length; if (!num.parse(pos, select_query->limit_length, expected)) return false; } } /// SETTINGS key1 = value1, key2 = value2, ... if (s_settings.ignore(pos, expected)) { ParserSetQuery parser_settings(true); if (!parser_settings.parse(pos, select_query->settings, expected)) return false; } if (select_query->with_expression_list) select_query->children.push_back(select_query->with_expression_list); select_query->children.push_back(select_query->select_expression_list); if (select_query->tables) select_query->children.push_back(select_query->tables); if (select_query->prewhere_expression) select_query->children.push_back(select_query->prewhere_expression); if (select_query->where_expression) select_query->children.push_back(select_query->where_expression); if (select_query->group_expression_list) select_query->children.push_back(select_query->group_expression_list); if (select_query->having_expression) select_query->children.push_back(select_query->having_expression); if (select_query->order_expression_list) select_query->children.push_back(select_query->order_expression_list); if (select_query->limit_by_value) select_query->children.push_back(select_query->limit_by_value); if (select_query->limit_by_expression_list) select_query->children.push_back(select_query->limit_by_expression_list); if (select_query->limit_offset) select_query->children.push_back(select_query->limit_offset); if (select_query->limit_length) select_query->children.push_back(select_query->limit_length); if (select_query->settings) select_query->children.push_back(select_query->settings); return true; }
bool ParserStorage::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { ParserKeyword s_engine("ENGINE"); ParserToken s_eq(TokenType::Equals); ParserKeyword s_partition_by("PARTITION BY"); ParserKeyword s_primary_key("PRIMARY KEY"); ParserKeyword s_order_by("ORDER BY"); ParserKeyword s_sample_by("SAMPLE BY"); ParserKeyword s_settings("SETTINGS"); ParserIdentifierWithOptionalParameters ident_with_optional_params_p; ParserExpression expression_p; ParserSetQuery settings_p(/* parse_only_internals_ = */ true); ASTPtr engine; ASTPtr partition_by; ASTPtr primary_key; ASTPtr order_by; ASTPtr sample_by; ASTPtr settings; if (!s_engine.ignore(pos, expected)) return false; s_eq.ignore(pos, expected); if (!ident_with_optional_params_p.parse(pos, engine, expected)) return false; while (true) { if (!partition_by && s_partition_by.ignore(pos, expected)) { if (expression_p.parse(pos, partition_by, expected)) continue; else return false; } if (!primary_key && s_primary_key.ignore(pos, expected)) { if (expression_p.parse(pos, primary_key, expected)) continue; else return false; } if (!order_by && s_order_by.ignore(pos, expected)) { if (expression_p.parse(pos, order_by, expected)) continue; else return false; } if (!sample_by && s_sample_by.ignore(pos, expected)) { if (expression_p.parse(pos, sample_by, expected)) continue; else return false; } if (s_settings.ignore(pos, expected)) { if (!settings_p.parse(pos, settings, expected)) return false; } break; } auto storage = std::make_shared<ASTStorage>(); storage->set(storage->engine, engine); storage->set(storage->partition_by, partition_by); storage->set(storage->primary_key, primary_key); storage->set(storage->order_by, order_by); storage->set(storage->sample_by, sample_by); storage->set(storage->settings, settings); node = storage; return true; }