[Swift]UITableView insertRows

insertRows

self.mainTableView.beginUpdates()
self.data.insert("jack", at: 0)
self.mainTableView.insertRows(at: [IndexPath(row:0, section:0)], with:UITableViewRowAnimation.top)
self.mainTableView.endUpdates()

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
   return self.data.count
}

[MySQL]SUBSTRING

開始位置は1からなので注意

all_test

id name tel zip
1 あいう 09011112222 1112222
2 なにぬ 09033334444 3334444
3 かきく 09055556666 7775555
4 さしす 09077778888 9002144

SQL

SELECT id,name,tel,zip,SUBSTRING(zip,1,3) AS zip1,SUBSTRING(zip,4,4) AS zip2
FROM all_test
ORDER BY id ASC;

結果

id name tel zip zip1 zip2
1 あいう 09011112222 1112222 111 2222
2 なにぬ 09033334444 3334444 333 4444
3 かきく 09055556666 7775555 777 5555
4 さしす 09077778888 9002144 900 2144

[MySQL]FIND_IN_SET

下記2つのテーブルをtelカラムでjoinしたい

all_test

id name tel
1 あいう 09011112222
2 なにぬ 09033334444
3 かきく 09055556666
4 さしす 09077778888

sub_infos

id tel address
1 090-3333-4444 東京都港区赤坂1-2-2
2 090-7777-8888 神奈川県横浜市中区4-32-4

SQL

SELECT a.id,a.name,a.tel,s.id AS sub_id,s.tel AS sub_tel
FROM all_test AS a
LEFT JOIN sub_infos AS s
ON FIND_IN_SET(a.tel,REPLACE(s.tel,'-',''))
ORDER BY id ASC;

結果

id name tel sub_id sub_tel
1 あいう 09011112222
2 なにぬ 09033334444 1 090-3333-4444
3 かきく 09055556666
4 さしす 09077778888 2 090-7777-8888

[Swift]Array Extension #2

Array Extension #2

mutating func switchValue(_ index1:Int,index2:Int){
    let _index1:Int = (index1 < 0) ? self.count + index1 : index1
    let _index2:Int = (index2 < 0) ? self.count + index2 : index2
    let elm = self[_index1]
    self[_index1] = self[_index2]
    self[_index2] = elm
}

[MySQL]検索結果ファイル出力

検索結果ファイル出力

SELECT id,ken_id,ken_name FROM ad_address GROUP BY ken_name ORDER BY ken_id ASC LIMIT 55 INTO OUTFILE "tmp/test.csv" FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n';

[MySQL]XAMPP+コマンドプロンプト

XAMPP+コマンドプロンプト
MySQLのダンプファイルをリストアする時、文字コードを揃えないと文字化けする。
ダンプファイルがUTF-8の時

chcp 65001
mysql -u user -p < C:\xampp\htdocs\abc.dump

その後確認する時

chcp 932
mysql -u user -p ※MySQLログイン
set names sijis
select * from tablename;