insert

Insert a character at a specific location using sed

旧城冷巷雨未停 提交于 2020-08-22 04:06:14
问题 How to insert a dash into a string using sed (e.g., 201107 to 2011-07 )? 回答1: echo "201107" | sed 's/201107/2011-07/' Should work. But just kidding, here's the more general solution: echo "201107" | sed 's/^\(.\{4\}\)/\1-/' This will insert a - after the first four characters. HTH 回答2: For uncertain sed version (at least my GNU sed 4.2.2), you could just do: echo "201107" | sed 's/./&-/4' /4 -> replace for the 4th occurrence (of search pattern . ) & -> back reference to the whole match I

conditional insert statement in sqlite triggers

老子叫甜甜 提交于 2020-08-21 05:18:07
问题 Are conditional if/case/when statements supported in sqlite triggers? Let`s say I have the following setup: CREATE TABLE someTable (id INTEGER PRIMARY KEY, someValue INTEGER); CREATE TRIGGER update_another_table AFTER INSERT ON someTable BEGIN IF(new.someValue==0) DELETE FROM another_table WHERE (...some condition); ELSE IF NOT EXISTS(SELECT anotherValue FROM another_table WHERE anotherValue =new.someValue) INSERT INTO another_table VALUES(new.someValue, ...); ELSE UPDATE another_table SET

Insert Single quotes in SQLite

我是研究僧i 提交于 2020-07-09 05:50:08
问题 I'm trying to add the following text to my database: Zeeland '96 But the single quote is giving me errors. It should look like this: INSERT INTO Department (Code, Name, CountryID) VALUES ('ZE', 'Zeeland '96', 1) As you can see, at this moment is one quote missing, how can I get rid of this problem? Thanks in advance! 回答1: As you can see HERE you need to escape it by using two single quotes in a row. Try: INSERT INTO Department (Code, Name, CountryID) VALUES ('ZE', 'Zeeland ''96', 1) 回答2:

Unknown column in field list

本秂侑毒 提交于 2020-07-03 07:51:56
问题 I'm trying to insert some information to MySQL with Pascal, but when I run the program I get the error unknown column 'mohsen' in field list This is my code procedure TForm1.Button1Click(Sender: TObject); var aSQLText: string; aSQLCommand: string; namee:string; family:string; begin namee:='mohsen'; family:='dolatshah'; aSQLText:= 'INSERT INTO b_tbl(Name,Family) VALUES (%s,%s)'; aSQLCommand := Format(aSQLText, [namee, family]); SQLConnector1.ExecuteDirect(aSQLCommand); SQLTransaction1.Commit;

Insert bytearray into bytearray Python

夙愿已清 提交于 2020-06-25 05:28:08
问题 I'm trying to insert one byte array into another at the beginning. Here's a simple example of what I'm trying to accomplish. import struct a = bytearray(struct.pack(">i", 1)) b = bytearray(struct.pack(">i", 2)) a = a.insert(0, b) print(a) However this fails with the following error: a = a.insert(0, b) TypeError: an integer is required 回答1: bytearray is a sequence-type, and it supports slice-based operations. The "insert at position i " idiom with slices goes like this x[i:i] = <a compatible

Why is std::back_inserter_iterator not WeaklyIncrementable in RangeV3?

荒凉一梦 提交于 2020-06-11 07:34:12
问题 To my surprise this Concept-like assertion fails in RangeV3. #include<vector> #include<range/v3/algorithm/copy.hpp> int main(){ static_assert(ranges::WeaklyIncrementable<std::back_insert_iterator<std::vector<double> >>()); } Why is that? This, among other things means that I cannot use the ranges::copy algorithm as I use to do with std::copy . std::vector<double> w(100); std::vector<double> v; ranges::copy( begin(w), end(w), std:back_inserter(v) ); // compilation error, concept not fulfilled.

SQL Server : row_number over primary key

女生的网名这么多〃 提交于 2020-06-01 08:58:27
问题 Is there any way to create column that will be increased and reset over primary key? Example: Table A ([Code], [Type], [Line No_]) Primary key is ([Code], [Type]) And when I add a new row, I want to auto generate [Line No_] like this: Code Type Line No_ ----------------------- 'U1' 0 1000 'U1' 0 2000 'U1' 1 1000 Something like ROW_NUMBER but auto generated on insert row 回答1: No, you can't use a window function in a computed column. Computed columns must be scalar values. However, this is a

SQL Server : row_number over primary key

主宰稳场 提交于 2020-06-01 08:58:19
问题 Is there any way to create column that will be increased and reset over primary key? Example: Table A ([Code], [Type], [Line No_]) Primary key is ([Code], [Type]) And when I add a new row, I want to auto generate [Line No_] like this: Code Type Line No_ ----------------------- 'U1' 0 1000 'U1' 0 2000 'U1' 1 1000 Something like ROW_NUMBER but auto generated on insert row 回答1: No, you can't use a window function in a computed column. Computed columns must be scalar values. However, this is a

Performance comparison between mybaits Batch ExecutorType and for_each Xml

人盡茶涼 提交于 2020-06-01 07:22:46
问题 I have a list of records to be inserted into DB using my baits. Previously, my code is something like: for(Item item : items){ sqlSession.insert("insert", item); } Using this method works but I find there is dynamical incremental DiskIO at Mysql server, due to number of items. As I have little access to MySql configuration, and hope to resolve this high disk io issue, I find some possible solutions: using ExecutorType.BATCH for sqlSession insert multiple values within a single insert

Laravel insert or update multiple rows

别来无恙 提交于 2020-05-25 04:44:05
问题 Im new in laravel, and im trying to update my navigation tree. So i want to update my whole tree in one query without foreach. array( array('id'=>1, 'name'=>'some navigation point', 'parent'='0'), array('id'=>2, 'name'=>'some navigation point', 'parent'='1'), array('id'=>3, 'name'=>'some navigation point', 'parent'='1') ); I just want to ask - is there posibility in laravel to insert(if new in array) or update my current rows in database? I want to update all, because i have fields _lft,