clause

How to correctly use guard clause in Ruby

限于喜欢 提交于 2019-12-08 15:53:16
问题 What is the correct way to use the guard clause in this sample? def require_admin unless current_user && current_user.role == 'admin' flash[:error] = "You are not an admin" redirect_to root_path end end I don't know where to put flash message when trying to rewrite using these https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals conventions 回答1: You can use the return statement here. Essentially, there is no need for the method to continue if those conditions are met, so you can

Is multiple .Where() statements in LINQ a performance issue?

≡放荡痞女 提交于 2019-12-08 14:35:43
问题 I am wondering if there are performance implications of multiple .Where() statements. For example I could write: var contracts = Context.Contract .Where( c1 => c1.EmployeeId == employeeId ) .Where( c1 => !Context.Contract.Any( c2 => c2.EmployeeId == employeeId && c1.StoreId == c2.StoreId && SqlFunctions.DateDiff("day", c2.TerminationDate.Value, c1.DateOfHire.Value) == 1 ) ) .Where( c1 => !Context.EmployeeTask.Any( t => t.ContractId == c1.Id ) ); Or alternatively I could combine them all into

MySQL group_concat with where clause

China☆狼群 提交于 2019-12-06 02:31:39
问题 I got this problem with Group_Concat and a where filter. In my table i got module names which are linked to a client. I want to search clients by module name, but in the group concat i still want to see all modules that are owned by the client. currently it will display all clients with those modules, but it will only display that specific module. I can't figure out how to make them both work together. Any suggestions on how to get my expected result?? These are some basic tables and the

【2019年8月版】OCP 071认证考试原题-第35题

一世执手 提交于 2019-12-05 13:41:58
choose two Which two statenents are tue about the COUNT function? A) It can only be used for NUMBER data types. B) COUNT (DISTINCT inv_amt) returns the number of rows excluding rows containing dupicates and NULLs in the INV_AMT column C) COUNT(*) returns the number of rows in a table including duplicate rows and rows containing NULLs in any column. D) A SELECT statement using the COUNT function with a DISTINCT keyword cannot have a WHERE clause. E) COUNT(inv_amt) returns the number of rows in a table including rows with NULL in the INV_AMT column. Answer::BC (解析:count 对于 null 值是忽略的;可以与 where

Condition left join in CriteriaQuery

无人久伴 提交于 2019-12-05 09:30:51
Hi everybody I am trying to do this in CriteriaQuery, I was searching so long but I can't found anything to do it, someone can help me? SELECT b.name FROM Empl a LEFT OUTER JOIN Deplo b ON (a.id_depl = b.id_depl) AND b.id_place = 2; I'm just trying to do a condition in left join clause, I saw ".on" function but I don't know if it will work and how it work because I tried to do something like this: Join Table1, Table2j1 = root.join(Table1_.table2, JoinType.LEFT).on(cb.and(cb.equal(table2_.someid, someId))); But it need a boolean expresion. The on clause has been introduced in JPA 2.1. An

关于MySQL的ONLY_FULL_GROUP_BY

橙三吉。 提交于 2019-12-05 05:08:53
今天同事问了一个奇怪的MySQL group by问题。研究了一会发现饶有趣味,记录之~ 表结构简化如下: create table user ( id int not null primary key, remark varchar(20) null, constraint user_with_icp_remark_uindex unique (remark) ); 对上表执行如下 SELECT 操作: SELECT * FROM user GROUP BY remark; 会报错: SELECT list is not in GROUP BY clause and contains nonaggregated column 'user.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 众所周知 MySQL 5.7 以后默认设置了 ONLY_FULL_GROUP_BY ,即默认设置下只允许 SELECT 的列:1)在GROUP BY中出现过;或 2)是聚合值。id 不满足上面的条件,出现异常很合理。但是对上表执行如下 SELECT 操作: SELECT * FROM user

开源模式面临的生存危机

纵饮孤独 提交于 2019-12-04 13:25:51
对于知名容器厂商 Docker 公司来说昨天是一个值得铭记的日子。先是 Mirantis 宣布收购 Docker 企业级服务部门获得融资3500万美元。值得注意的是,这次收购并不包括 Docker Desktop 。据称, Mirantis 和 Docker 将共同开发核心的上游技术,为开源开发做出贡献。此外, Mirantis 和 Docker 将继续确保双方产品之间的集成, Docker 将专注于 Docker Desktop 和 Docker Hub ,而 Mirantis 专注于 Docker Enterprise 容器平台。几乎同时 Docker 还宣布公司已任命长期担任首席产品官的 Scott Johnston 为首席执行官(CEO)。 Johnston 是今年 Docker 的第三任 CEO ,接替 Rob Bearden ,而 Bearden 接替5月份卸任的 Steve Singh 。 在发布这则消息前,Docker公司已经融资2.7亿美元,是行业内的独角兽。 如今急匆匆贱卖其企业级业务令人吃惊。其实也不算贱卖。主要是 Docker 是开源的,从一开始面向的就是开发者,你要知道想从开发者手中赚钱是非常难的;而在赚钱的企业生产实践中缺乏行之有效的解决方案。互联网巨头 Google 开源(CNCF基金会) Kubernetes (k8s) 对其更是致命的打击

SQL

一曲冷凌霜 提交于 2019-12-04 09:12:00
1. MySQL插入数据 语法: INSERT INTO table_name(field1,field2,field3,...fieldN) VALUES (value1,value2,value3,...valueN,) 如果数据是字符型,必须使用单引号或者是双引号,如"value"。 如: insert into student(username, age, sex, height) values("mengli", 26, 2, 165); 2. MySQL查询数据 2.1 语法:SELECT column_name,column_name FROM table_name [WHERE Clause] [LIMIT N][OFFSET M] 以下语句将取出学生表的全部记录: 如:select * from student; 有时取出所有信息数据量太大,浪费内存。比如只想查询所有同学的名字,则可以指定要查询的字段: SELECT username FROM student; 2.2. DISTINCT 关键字 使用DISTINCT关键字 可以指定某一列或者多列不重复 ,语法为:SELECT DISTINCT fields FROM table_name, 这样一来紧跟在DISTINCT后面的列将 排重后 显示出来,优先保留排在前面的行。 如:SELECT DISTINCT

MySQL group_concat with where clause

若如初见. 提交于 2019-12-04 07:48:43
I got this problem with Group_Concat and a where filter. In my table i got module names which are linked to a client. I want to search clients by module name, but in the group concat i still want to see all modules that are owned by the client. currently it will display all clients with those modules, but it will only display that specific module. I can't figure out how to make them both work together. Any suggestions on how to get my expected result?? These are some basic tables and the query i tried along with results i get and the result i really wanted Client +--------------------+ | id |

【2019年8月】OCP 071认证考试最新版本的考试原题-第26题

巧了我就是萌 提交于 2019-12-04 05:41:33
Choose three Which three actions can you perfom only with system privileges? A) Truncate a table in another schema. B) Access flat files via a database, which are stored in an operating system directory. C) Log in to a database. D) Query any table in a database. E) Use the WITH GRANT OPTION clause. F) Execute a procedure in another schema. Answer:CDF (解析:这道题考的就是可以授权哪些系统权限去做哪些活儿。 C:create session D:select any table F:EXECUTE ANY PROCEDURE 原来以为 AAnswer:正确,结构查询发现没有 truncate any table 的权限。 ) 来源: https://my.oschina.net/u/3902946/blog/3128196