insert-update

Insert character into SQL string

瘦欲@ 提交于 2019-12-19 19:55:33
问题 I have an nvarchar column I need to insert a hyphen at fixed points within the string. The hyphen need to go between the rightmost character and the next, and again in the 3rd position from the right, such as: column value is 0000050704 and I need it to be 0000050-70-4 or value is 0555256321 and it should be 0555256-32-1 Can't see how this is done. Can anyone give me a little help? 回答1: Assuming the strings can be a variable length, you'll need to use REVERSE() or lots of nasty looking LEN()

Using insertWithOnConflict for update or insert

我是研究僧i 提交于 2019-12-19 16:54:45
问题 I need to insert or update and I found the method insertWithOnConflict of the SQLiteDatabase, but I do not know how it checks if the entry already exists. Theoretically I need a "Where" argument to check if a certain ID exists, and if so, it should replace all other columns. This is what I have now, but I don´t think that the second argument is the unique id ContentValues args = new ContentValues(); args.put(AppDatabase.COLUMN_ID, entry.getId()); args.put(AppDatabase.COLUMN_NAME, entry

Update or replace an embedded document in MongoDB collection

半世苍凉 提交于 2019-12-18 09:51:32
问题 I have following data structure: db.objects { "_id" : 1, "name" : "object name", "type" : "rectangle", "area" : { "position_x1" : 0, "position_y1" : 0, "position_x2" : 0, "position_y2" : 0 }, "dimension" : { "width" : 0, "height" : 0 } } I want to replace/update "area" and "dimension" separately for a document in objects collection with "_id" = 1. [?] Please let me know how can i achieve using MongoDB C# driver. 回答1: This is a very simple use of the $set operator. So essentially the update

I get “Syntax error in UPDATE statement” with OleDB

偶尔善良 提交于 2019-12-18 09:46:56
问题 I am developing an information system that works with a connected data source / MS Access database. The question is kinda cliche but I can't seem to find a proper solution from the similar ones I have come across. Here is my code for the button. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'myConnection.ConnectionString = connString 'myConnection.Open() If Me.txtConfirmPasscode.Text = Me.txtNewPasscode.Text Then Dim updateCmd As

Why are 2 rows affected in my `INSERT … ON DUPLICATE KEY UPDATE`?

不打扰是莪最后的温柔 提交于 2019-12-17 17:33:53
问题 I'm doing an INSERT ... ON DUPLICATE KEY UPDATE for a PRIMARY KEY in the following table: DESCRIBE users_interests; +------------+---------------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------------------------+------+-----+---------+-------+ | uid | int(11) | NO | PRI | NULL | | | iid | int(11) | NO | PRI | NULL | | | preference | enum('like','dislike','ignore') | YES | | NULL | | +------------+-----------------

Rails - User Input for Multiple models on a single form - How

三世轮回 提交于 2019-12-17 15:36:50
问题 This is basically a nested form question, albeit with only one field that belongs to a parent model. My data entry form collects data for a model - however I also need to collect one other a data element/value (UserID) that actually goes into a parent record that will be created with the detail record. AFAIK Rails expects each form field to map to a model and I need to create an unbound data input field that I will use separately. How can I override this default behaviour and create a'free

MySQL trigger On Insert/Update events

≯℡__Kan透↙ 提交于 2019-12-17 04:31:20
问题 So I have two tables like this... ext_words ------------- | id | word | ------------- | 1 | this | ------------- | 2 | that | ------------- | 3 | this | ------------- ext_words_count --------------------- | id | word | count | --------------------- | 1 | this | 2 | --------------------- | 2 | that | 1 | --------------------- I am trying to create a trigger that will: update ext_words_count.count when ext_words.word is updated. To further complicate matters, if ext_words.word does not exist in

MySQL trigger On Insert/Update events

白昼怎懂夜的黑 提交于 2019-12-17 04:31:17
问题 So I have two tables like this... ext_words ------------- | id | word | ------------- | 1 | this | ------------- | 2 | that | ------------- | 3 | this | ------------- ext_words_count --------------------- | id | word | count | --------------------- | 1 | this | 2 | --------------------- | 2 | that | 1 | --------------------- I am trying to create a trigger that will: update ext_words_count.count when ext_words.word is updated. To further complicate matters, if ext_words.word does not exist in

How do I update if exists, insert if not (AKA “upsert” or “merge”) in MySQL?

风流意气都作罢 提交于 2019-12-16 19:17:12
问题 Is there an easy way to INSERT a row when it does not exist, or to UPDATE if it exists, using one MySQL query? 回答1: Yes, INSERT ... ON DUPLICATE KEY UPDATE. For example: INSERT INTO `usage` (`thing_id`, `times_used`, `first_time_used`) VALUES (4815162342, 1, NOW()) ON DUPLICATE KEY UPDATE `times_used` = `times_used` + 1 回答2: I know this is an old question, but the Google lead me here recently so I imagine others come here, too. @chaos is correct: there is the INSERT ... ON DUPLICATE KEY

Insert values in to SQLite database ? java.lang.NullPointerException [duplicate]

你离开我真会死。 提交于 2019-12-13 08:59:19
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 5 years ago . I want to insert some values in to my database. but my code give "java.lang.NullPointerException" error. I am new to android and i not able to fix this error. can any one help? below is my Add_new calss public class Add_new extends Activity { EditText nameText, phoneText, emailText, addressText; ImageView contactImageImgView; List<Contact> Contacts = new ArrayList