exists

Check if Record Exists

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I found this on php.net to check if file exists. I want to check if record exists first, then do update, otherwise do an insert. if(record exist) { update query} else { insert query} I know how to update or insert, but don't know how to check if a record exists first. How is it done? 回答1: If you know how to do a SQL SELECT , then do that: $result = mysql_query("SELECT * FROM table1 WHERE something"); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { // do something } else { // do something else } Better yet, don't do this in PHP, use

using “if” and “else” Stored Procedures MySQL

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having some difficulties when trying to create this stored procedure, any kind of help is welcome: create procedure checando(in nombrecillo varchar(30), in contrilla varchar(30), out resultado int) begin if exists (select * from compas where nombre = nombrecillo and contrasenia = contrilla) then set resultado = 0; else if exists (select * from compas where nombre = nombrecillo) then set resultado = -1; else set resultado = -2; end if; end; The table I'm working on is: +-------------+-------------+------+-----+---------+-------+ | Field |

Trying to use open( filename, 'w' ) gives IOError: [Errno 2] No such file or directory:

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to create and write to a text file from Maya using Python. The version of Python in this version of Maya is 2.7.3. I have searched and cannot find a solution/reason for this error. Here's the code that doesn't work. afile = 'D:\\temp\\test.txt' outFile = open( afile, 'w' ) outFile.write('Test.') outFile.close() # Error: 2 # Traceback (most recent call last): # File "<maya console>", line 1, in <module> # IOError: [Errno 2] No such file or directory: 'D:\\temp\\test.txt' # Most answers I found related to the slashes in the path,

mongodb: insert if not exists

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Every day, I receive a stock of documents (an update). What I want to do is insert each item that does not already exist. I also want to keep track of the first time I inserted them, and the last time I saw them in an update. I don't want to have duplicate documents. I don't want to remove a document which has previously been saved, but is not in my update. 95% (estimated) of the records are unmodified from day to day. I am using the Python driver (pymongo). What I currently do is (pseudo-code): for each document in update: existing_document

Why does SELECT results differ between mysql and sqlite?

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm re-asking this question in a simplified and expanded manner. Consider these sql statements: create table foo (id INT, score INT); insert into foo values (106, 4); insert into foo values (107, 3); insert into foo values (106, 5); insert into foo values (107, 5); select T1.id, avg(T1.score) avg1 from foo T1 group by T1.id having not exists ( select T2.id, avg(T2.score) avg2 from foo T2 group by T2.id having avg2 > avg1); Using sqlite, the select statement returns: id avg1 ---------- ---------- 106 4.5 107 4.0 and mysql returns: +------+---

How do open a file for writing only if it doesn't already exist in ruby

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to open a file for writing but only if it doesn't already exist. If the file exists I want to raise an exception. Is this the best way to do it? filename = 'foo' raise if File . exists ? filename File . open ( filename , 'w' ) do | file | file . write contents end What is the most idiomatic way to do this without the race condition? 回答1: After doing some further research, it seems you can use the File::CREAT and File::EXCL mode flags. filename = 'foo' File . open ( filename , File :: WRONLY | File :: CREAT | File :: EXCL )

Unix Bash Shell Programming if directory exists

匿名 (未验证) 提交于 2019-12-03 02:51:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I'm trying to get into an if statement in a bash shell script but I think I'm doing something wrong, anyways here's my sample code. #!/bin/bash read sd if [ -d "~/tmp/$sd" ]; then echo "That directory exists" else echo "That directory doesn't exists" fi ;; Am I pointing it to the correct directory? I want the user to input something which will be put into "sd" and if that subdirectory exists then it'll say it does, if not then it will go to the else and say it doesn't exist. 回答1: Try: if [ -d ~/tmp/"$sd" ]; then or: if [ -d "$HOME/tmp/$sd

Drop foreign key only if it exists

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm on a MySQL database. I'm doing this, but it doesn't work. ALTER TABLE `object` DROP FOREIGN KEY IF EXISTS `object_ibfk_1`; I've tried to put this IF EXISTS wherever I could. How can check if foreign key is exists before drop it? 回答1: If you want to drop foreign key if it exists and do not want to use procedures you can do it this way (for MySQL) : set @var=if((SELECT true FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND TABLE_NAME = 'table_name' AND CONSTRAINT_NAME = 'fk_name' AND CONSTRAINT_TYPE =

Composer - The requested package exists as but these are rejected by your constraint

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I run my install from composer, I have this error : λ composer install You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Error : Problem 1 - The requested package antoineb1/smoney_bundle 1.0 exists as antoineb1/smoney_bundle[dev-master] but these are rejected by your constraint. My

How to check if path or file exist in Scala

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I check if a path / file exists in Scala similar to Python ? An example below: os.path.exists("/home") Out[4]: True 回答1: Since Java 7 the better way would be scala> import java.nio.file.{Paths, Files} import java.nio.file.{Paths, Files} scala> Files.exists(Paths.get("/tmp")) res0: Boolean = true 回答2: Well, sorry I found the answer to my own question: scala> new java.io.File("/tmp").exists res0: Boolean = true 回答3: you can use scala library as well : scala.reflect.io.File(scala.reflect.io.Path("<actual file path>")).exists 文章来源: How to