exists

Linq To Entities - Any VS First VS Exists

不打扰是莪最后的温柔 提交于 2019-12-01 03:08:42
I am using Entity Framework and I need to check if a product with name = "xyz" exists ... I think I can use Any(), Exists() or First(). Which one is the best option for this kind of situation? Which one has the best performance? Thank You, Miguel Any translates into "Exists" at the database level. First translates into Select Top 1 ... Between these, Exists will out perform First because the actual object doesn't need to be fetched, only a Boolean result value. At least you didn't ask about .Where(x => x.Count() > 0) which requires the entire match set to be evaluated and iterated over before

Oracle sql return true if exists question

孤街醉人 提交于 2019-12-01 02:52:41
How do I check if a particular element exists in a table - how can I return true or false? I have a table that has user_id user_password user_secretQ Verbally, I want to do this: If a particular user_id exists in the user_id column, then return true -- otherwise return false. There is no Boolean type in Oracle SQL. You will need to return a 1 or 0, or some such and act accordingly: SELECT CASE WHEN MAX(user_id) IS NULL THEN 'NO' ELSE 'YES' END User_exists FROM user_id_table WHERE user_id = 'some_user'; In PL/SQL you can do this: function user_exists (p_user_id users.user_id%type) return

oracle中sql语句的优化

血红的双手。 提交于 2019-12-01 02:42:05
一、执行顺序及优化细则 1.表名顺序优化 (1) 基础表放下面,当两表进行关联时数据量少的表的表名放右边 表或视图: Student_info (30000条数据) Description_info (30条数据) select * from description_info di ,student_info si --学生信息表 where si.student_id = di.lookup_code(+) and di.lookup_type(+) = 'STUDENT_ID' 与 select * from student_info si--学生信息表 ,description_info di where si.student_id = di.lookup_code(+) and di.lookup_type(+) = 'STUDENT_ID' 以student_info作为基础表,你会发现运行的速度会有很大的差距。 (2) 当出现多个表时,关联表被称之为交叉表,交叉表作为基础表 select * from description_info di ,description_info di2 ,student_info si --学生信息表 where si.student_id = di.lookup_code(+) and di.lookup_type(+) =

ATX uiautomator2 README 学习

旧巷老猫 提交于 2019-12-01 02:35:39
连接设备 有多种方式可以连接 wifi 首先要保证你的手机(10.0.0.1)和电脑在同一个局域网内 import uiautomator2 as u2d = u2.connect('10.0.0.1') # alias for u2.connect_wifi('10.0.0.1')print(d.info) usb usb通过设备号连接,可以通过 adb devices 查看 import uiautomator2 as u2d = u2.connect('123456f') # alias for u2.connect_usb('123456f')print(d.info) adb wifi import uiautomator2 as u2d = u2.connect_adb_wifi("10.0.0.1:5555")# Equals to # + Shell: adb connect 10.0.0.1:5555# + Python: u2.connect_usb("10.0.0.1:5555") 全局设置 里面包含一些 u2 全局设置的属性 Http debug >>> d.debug = True>>> d.info12:32:47.182 $ curl -X POST -d '{"jsonrpc": "2.0", "id":

Mysql中的语句优化

白昼怎懂夜的黑 提交于 2019-12-01 02:09:59
1、EXPLAIN 做MySQL优化,我们要善用EXPLAIN查看SQL执行计划。 下面来个简单的示例,标注(1、2、3、4、5)我们要重点关注的数据: type列,连接类型。一个好的SQL语句至少要达到range级别。杜绝出现all级别。 key列,使用到的索引名。如果没有选择索引,值是NULL。可以采取强制索引方式。 key_len列,索引长度。 rows列,扫描行数。该值是个预估值。 extra列,详细说明。注意,常见的不太友好的值,如下:Using filesort,Using temporary。 2、SQL语句中IN包含的值不应过多 MySQL对于IN做了相应的优化,即将IN中的常量全部存储在一个数组里面,而且这个数组是排好序的。但是如果数值较多,产生的消耗也是比较大的。再例如:select id from t where num in(1,2,3) 对于连续的数值,能用between就不要用in了;再或者使用连接来替换。 3、SELECT语句务必指明字段名称 SELECT*增加很多不必要的消耗(CPU、IO、内存、网络带宽);增加了使用覆盖索引的可能性;当表结构发生改变时,前断也需要更新。所以要求直接在select后面接上字段名。 4、当只需要一条数据的时候,使用limit 1 这是为了使EXPLAIN中type列达到const类型 5、如果排序字段没有用到索引

How to find with javascript if element exists in DOM or it's virtual (has been just created by createElement)

谁说胖子不能爱 提交于 2019-12-01 00:47:55
问题 I'm looking for a way to find if element referenced in javascript has been inserted in the document. Lets illustrate a case with following code: var elem = document.createElement('div'); // Element has not been inserted in the document, i.e. not present document.getElementByTagName('body')[0].appendChild(elem); // Element can now be found in the DOM tree Jquery has :visible selector, but it won't give accurate result when I need to find that invisible element has been placed somewhere in the

Django学习之model进阶

廉价感情. 提交于 2019-11-30 23:07:17
Django学习之model进阶 本节目录 一 QuerySet 二 中介模型 三 查询优化 四 extra 五 整体插入 六 xxx 七 xxx 八 xxx 一 QuerySet 可切片 使用Python 的切片语法来限制 查询集 记录的数目 。 它等同于SQL 的 LIMIT 和 OFFSET 子句。 1 >>> Entry.objects. all ()[:5] # (LIMIT 5) >>> Entry.objects.all()[5:10] # (OFFSET 5 LIMIT 5) 不支持负的索引(例如 Entry.objects.all()[-1] )。通常, 查询集 的切片返回一个新的 查询集 —— 它不会执行查询。 可迭代 articleList=models.Article.objects.all() for article in articleList: print(article.title) 惰性查询 查询集 是惰性执行的 —— 创建 查询集 不会带来任何数据库的访问。 你可以将过滤器保持一整天,直到 查询集 需要求值时,Django 才会真正运行这个查询。(关于惰性是不是在迭代器的地方听过呀) 1 2 3 4 5 6 7 8 queryResult=models.Article.objects. all () # not hits database

Shorthand function for checking whether a property exists [duplicate]

时光怂恿深爱的人放手 提交于 2019-11-30 22:59:45
This question already has an answer here: Test for existence of nested JavaScript object key 55 answers Can you guys help me make a shorthand function determining whether an object property exists? In 99% of the cases I want to use it to check whether the returned json object contains the specified property or not. Note that there is no guarantee that any of the parent properties or even the json object itself must be defined. I was thinking of something in this manner: function propertyExists(<property>) { // property is something like data.property.property return typeof(data) !== "undefined

Django学习之model进阶

ぐ巨炮叔叔 提交于 2019-11-30 22:38:24
Django学习之model进阶 本节目录 一 QuerySet 二 中介模型 三 查询优化 四 extra 五 整体插入 六 xxx 七 xxx 八 xxx 一 QuerySet 可切片 使用Python 的切片语法来限制 查询集 记录的数目 。 它等同于SQL 的 LIMIT 和 OFFSET 子句。 1 >>> Entry.objects. all ()[:5] # (LIMIT 5) >>> Entry.objects.all()[5:10] # (OFFSET 5 LIMIT 5) 不支持负的索引(例如 Entry.objects.all()[-1] )。通常, 查询集 的切片返回一个新的 查询集 —— 它不会执行查询。 可迭代 articleList=models.Article.objects.all() for article in articleList: print(article.title) 惰性查询 查询集 是惰性执行的 —— 创建 查询集 不会带来任何数据库的访问。 你可以将过滤器保持一整天,直到 查询集 需要求值时,Django 才会真正运行这个查询。(关于惰性是不是在迭代器的地方听过呀) 1 2 3 4 5 6 7 8 queryResult=models.Article.objects. all () # not hits database

Android: How to detect a directory in the assets folder?

谁说胖子不能爱 提交于 2019-11-30 22:23:04
I'm retrieving files like this String[] files = assetFiles.list("EngagiaDroid"); How can we know whether it is a file or is a directory? I want to loop through the directories in the assets folder then copy all of its contents. You can check if a File represents a directory using http://developer.android.com/reference/java/io/File.html#isDirectory (). Is that what you mean? I think a more general solution (in case you have subfolders etc.) would be something like this (based on the solution you linked to, I've added it there too): ... copyFileOrDir("myrootdir"); ... private void copyFileOrDir