exists

ALTER TABLE ADD COLUMN IF NOT EXISTS in SQLite

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: We've recently had the need to add columns to a few of our existing SQLite database tables. This can be done with ALTER TABLE ADD COLUMN . Of course, if the table has already been altered, we want to leave it alone. Unfortunately, SQLite doesn't support an IF NOT EXISTS clause on ALTER TABLE . Our current workaround is to execute the ALTER TABLE statement and ignore any "duplicate column name" errors, just like this Python example (but in C++). However, our usual approach to setting up database schemas is to have a .sql script containing

ALTER TABLE ADD COLUMN IF NOT EXISTS in SQLite

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: We've recently had the need to add columns to a few of our existing SQLite database tables. This can be done with ALTER TABLE ADD COLUMN . Of course, if the table has already been altered, we want to leave it alone. Unfortunately, SQLite doesn't support an IF NOT EXISTS clause on ALTER TABLE . Our current workaround is to execute the ALTER TABLE statement and ignore any "duplicate column name" errors, just like this Python example (but in C++). However, our usual approach to setting up database schemas is to have a .sql script containing

Grails 2.4 and hibernate4 errors with run-app

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I've upgraded an app to Grails 2.4.0, and I'm using the hibernate4 plugin. When executing run-app the error examples below are generated for each domain class using the in-memory database. I've read several posts on the hibernate forums that the errors aren't serious. It's simply logging an error because the table it's trying to drop doesn't yet exist. 2014-Mai-24 13:25:26,788 ERROR [localhost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport - SchemaExport.java 425 - HHH000389: Unsuccessful: alter table user_role drop

How to insert pandas dataframe via mysqldb into database?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I can connect to my local mysql database from python, and I can create, select from, and insert individual rows. My question is: can I directly instruct mysqldb to take an entire dataframe and insert it into an existing table, or do I need to iterate over the rows? In either case, what would the python script look like for a very simple table with ID and two data columns, and a matching dataframe? 回答1: Update: There is now a to_sql method, which is the preferred way to do this, rather than write_frame : df . to_sql ( con = con ,

SQL Server: IF EXISTS ; ELSE

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a tableA: ID value 1 100 2 101 2 444 3 501 Also TableB ID Code 1 2 Now I want to populate col = code of table B if there exists ID = 2 in tableA. for multiple values , get max value. else populate it with '123'. Now here is what I used: if exists (select MAX(value) from #A where id = 2) BEGIN update #B set code = (select MAX(value) from #A where id = 2) from #A END ELSE update #B set code = 123 from #B I am sure there is some problem in BEGIN;END or in IF EXIST;ELSE. Basically I want to by-pass the else part if select statement in IF

Faster way to find out if a user exists on a system?

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an application that checks to see if a user exists (if not create it) every time it starts. This is done as follows: bool bUserExists = false; DirectoryEntry dirEntryLocalMachine = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer"); DirectoryEntries dirEntries = dirEntryLocalMachine.Children; foreach (DirectoryEntry dirEntryUser in dirEntries) { bUserExists = dirEntryUser.Name.Equals("UserName", StringComparison.CurrentCultureIgnoreCase); if (bUserExists) break; } The problem is on the majority of the systems where

NoSuchFieldException when field exists

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm getting a java.lang.NoSuchFieldException when trying to run the following method: public void getTimes(String specialty, String day) { ArrayList withSpec = new ArrayList (); for (Tutor t : tutorList){ try { Time startTime = (Time)t.getClass().getField(day + "Start").get(t); } catch (NoSuchFieldException | SecurityException | IllegalAccessException ex) Logger.getLogger(DBHandler.class.getName()).log(Level.SEVERE, null, ex); } The error is on the line Time startTime = (Time)t.getClass().getField(day + "Start").get(t); I don't understand

Excel VBA If WorkSheet(“wsName”) Exists [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Test or check if sheet exists 17 answers I'm wondering if there is clean cut functionality that returns True or False if a worksheet inside a workbook exists? It would be good, but not essential, if it's possible to do it without skipping error handling. The only thing I've found doesn't really work: On Error Resume Next If (Worksheets("wsName").Name "") Then Debug.Print "Worksheet exists!" Else Debug.Print "Worksheet doesn't exist!" End If On Error GoTo ErrHandler 回答1: A version without error

Laravel 4: Where Not Exists

匿名 (未验证) 提交于 2019-12-03 02:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need my model to return only those records from one table where a matching record does not exist in another table. I was thinking that the solution might be with Query Scopes but the documentation only scratches the surface. So my SQL would look something like this: SELECT * FROM A WHERE NOT EXISTS (SELECT A_id FROM B WHERE B.A_id = A.id) Here are my tables: A ------------- | id | name | ------------- B -------------------- | id | A_id | name | -------------------- Probably unnecessary but here are my models. Model for A: class A extends

Check if Database Exists Before Creating

匿名 (未验证) 提交于 2019-12-03 01:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This seems pretty trivial, but it is now frustrating me. I am using C# with SQL Server 2005 Express. I am using the following code. I want to check if a database exists before creating it. However, the integer returned is -1 and this is how MSDN defines what ExecuteNonQuery() will return as well. Right now, the database does exist but it still returns -1. Having said that, how can I make this work to get the desired result? private static void checkInventoryDatabaseExists(ref SqlConnection tmpConn, ref bool databaseExists) { string