exists

Isn't Android File.exists() case sensitive?

纵然是瞬间 提交于 2020-01-03 07:22:45
问题 I've created a new folder "sdcard/ dd " by: File album = new File(albumPath); if (album.exists()) { Log.d(TAG, albumPath + " already exists."); } else { boolean bFile = album.mkdir(); } And Again, I create the second folder "sdcard/ DD " by the same code, but, this time the album.exists() returns true, which indicates the "dd" is equals "DD". Anyone know why the File.exists() can NOT check the case of the folder name? Thanks! 回答1: While Linux, and therefore also Android, normally is case

How to check whether a tuple exists in a Python list?

自闭症网瘾萝莉.ら 提交于 2020-01-02 04:45:06
问题 I am new to Python, and I am trying to check whether a pair [a,b] exists in a list l=[[a,b],[c,d],[d,e]] . I searched many questions, but couldn't find precise solution. Please can someone tell me the right and shortest way of doing it? when i run : a=[['1','2'],['1','3']] for i in range(3): for j in range(3): if [i,j] in a: print a OUTPUT IS BLANK how to achieve this then? 回答1: The code does not work because '1' != 1 and, consequently, ['1','2'] != [1,2] If you want it to work, try: a=[['1',

What's the fastest way to check that entry exists in database?

旧街凉风 提交于 2020-01-02 03:30:11
问题 I'm looking for the fastest way to check that entry exists... All my life, I did with something like this... SELECT COUNT(`id`) FROM `table_name` Some people don't use COUNT(id) , but COUNT(*) . Is that faster? What about LIMIT 1 ? P.S. With id I meant primary key, of course. Thanks in an advice! 回答1: In most situations, COUNT(*) is faster than COUNT(id) in MySQL (because of how grouping queries with COUNT() are executed, it may be optimized in future releases so both versions run the same).

Python check if exists in SQLite3

天涯浪子 提交于 2020-01-02 03:13:22
问题 I'm trying to check whether a variable exists in an SQLite3 db. Unfortunately I can not seem to get it to work. The airports table contains 3 colums, with ICAO as the first column. if c.execute("SELECT EXISTS(SELECT 1 FROM airports WHERE ICAO='EHAM')") is True: print("Found!") else: print("Not found...") The code runs without any errors, but the result is always the same (not found). What is wrong with this code? 回答1: Try this instead: c.execute("SELECT EXISTS(SELECT 1 FROM airports WHERE

oracle中的exists和not exists和in用法详解

雨燕双飞 提交于 2020-01-02 01:06:10
in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询。 not exists:做NL,对子查询先查,有个虚表,有确定值,所以就算子查询有NULL最终也有值返回 not in:做hash,对子查询表建立内存数组,用外表匹配,那子查询要是有NULL那外表没的匹配最终无值返回。 一直以来认为exists比in效率高的说法是不准确的。 如果查询的两个表大小相当,那么用in和exists差别不大。 如果两个表中一个较小,一个是大表,则子查询表大的用exists,子查询表小的用in: 例如:表A(小表),表B(大表) 1: select * from A where cc in (select cc from B) 效率低,用到了A表上cc列的索引; select * from A where exists(select cc from B where cc=A.cc) 效率高,用到了B表上cc列的索引。 相反的 2: select * from B where cc in (select cc from A) 效率高,用到了B表上cc列的索引; select * from B where exists(select cc from A where cc=B.cc) 效率低,用到了A表上cc列的索引。 not in 和not exists

常用的 19 条 MySQL 优化

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

File

泪湿孤枕 提交于 2019-12-31 09:49:25
File类下的方法: isFile() exists() isDirectory()的区别: isFile() public boolean isFile()测试此抽象路径名表示的文件是否是一个标准文.如果该文件不是一个目录,并且满足其他与系统有关的标准,那么该文件是标准文件.由Java应用程序创建的所有非目录文件一定是标准文件. 返回:当且仅当此抽象路径名表示的文件存在且是一个标准文件时,返回true;否则返回false; 抛出:SecurityException,如果存在安全管理器,且其SecurityManager.checkRead(java.lang.String)方法拒绝对文件进行读访问. exists() public boolean exists()测试此抽象路径名表示的文件或目录是否存在. 返回:当且仅当此抽象路径名表示的文件或目录存在时,返回true;否则返回false; 抛出:SecurityException如果存在安全管理器,且其SecurityManager.checkRead(java.lang.String)方法拒绝对文件或目录进行写访问. isFile():判断是否文件,也许可能是文件或者目录 exists():判断是否存在,可能不存在 两个不一样的概念 java中的isDirectory()是检查一个对象是否是文件夹。返回值是boolean类型的

mysql exists 和 in的效率比较

ぐ巨炮叔叔 提交于 2019-12-29 02:57:26
这条语句适用于a表比b表大的情况 select * from ecs_goods a where cat_id in(select cat_id from ecs_category); 这条语句适用于b表比a表大的情况 select * from ecs_goods a where EXISTS(select cat_id from ecs_category b where a.cat_id = b.cat_id); 原因:(转发) select * from A where id in(select id from B) 以上查询使用了in语句,in()只执行一次,它查出B表中的所有id字段并缓存起来.之后,检查A表的id是否与B表中的id相等,如果相等则将A表的记录加入结果集中,直到遍历完A表的所有记录. 它的查询过程类似于以下过程 List resultSet=[]; Array A=(select * from A); Array B=(select id from B); for(int i=0;i<A.length;i++) { for(int j=0;j<B.length;j++) { if(A[i].id==B[j].id) { resultSet.add(A[i]); break; } } } return resultSet; 可以看出

How To Check If A Method Exists At Runtime In Java?

拈花ヽ惹草 提交于 2019-12-28 13:46:51
问题 How would one go about checking to see if a method exists for a class in Java? Would a try {...} catch {...} statement be good practice? 回答1: I assume that you want to check the method doSomething(String, Object) . You might try this: boolean methodExists = false; try { obj.doSomething("", null); methodExists = true; } catch (NoSuchMethodError e) { // ignore } This will not work, since the method will be resolved at compile-time. You really need to use reflection for it. And if you have

Rename a file if already exists - php upload system

蹲街弑〆低调 提交于 2019-12-28 04:27:41
问题 I this PHP code: <?php // Check for errors if($_FILES['file_upload']['error'] > 0){ die('An error ocurred when uploading.'); } if(!getimagesize($_FILES['file_upload']['tmp_name'])){ die('Please ensure you are uploading an image.'); } // Check filesize if($_FILES['file_upload']['size'] > 500000){ die('File uploaded exceeds maximum upload size.'); } // Check if the file exists if(file_exists('upload/' . $_FILES['file_upload']['name'])){ die('File with that name already exists.'); } // Upload