備忘録

備忘録

SQLでMySQLとMariaDBを判別する方法

Ⅰ. はじめに

タイトルの通り「SQLでMySQLとMariaDBを判別する方法」です

Ⅱ. 手順

1. 以下SQLを実行する
SHOW VARIABLES like '%version_comment%'

実行結果

MySQL version_comment MySQL Community Server - GPL
MariaDB mariadb.org binary distribution
Google Cloud SQL for MySQL (Google)

※Google Cloudでは期待する結果を得られない

C#でMySQLのジオメトリ記憶形式を読み取る方法

Ⅰ. はじめに

タイトルの通り「C#でMySQLのジオメトリ記憶形式を読み取る方法」です。

本記事では便宜上「ジオメトリ記憶形式」という単語を利用しますが正しい単語ではありません。
英語では「Internal Geometry Storage Format」と書かれています。

Ⅱ. 手順

1. MySQLでWKTからバイナリを生成する
/* 東京駅 山手線 */
/* 緯度 35.6809591 */
/* 経度 139.7673068 */
select ST_GeomFromText('POINT(35.6809591 139.7673068)', 4326)

/* 出力 */
/* E6 10 00 00 01 01 00 00 00 F3 7F FD C6 8D 78 61 40 F1 34 F4 AA 29 D7 41 40 */
2. C#を書く
var bytes = new byte[]
{
  0xE6, 0x10, 0x00, 0x00, // SRID (4326 = WGS84)
  0x01, // Byte order (1 = Little endian)
  0x01, 0x00, 0x00, 0x00, // Type (1 = Point)
  0xF3, 0x7F, 0xFD, 0xC6, 0x8D, 0x78, 0x61, 0x40, // Longitude
  0xF1, 0x34, 0xF4, 0xAA, 0x29, 0xD7, 0x41, 0x40, // Latitude
};

var span = bytes.AsSpan();
var srid = BitConverter.ToInt32(span.Slice(0, 4));
var byteOrder = (int)span.Slice(4, 1)[0];
var type = BitConverter.ToInt32(span.Slice(5, 4));
var longitude = BitConverter.ToDouble(span.Slice(9, 8));
var latitude = BitConverter.ToDouble(span.Slice(17, 8));

Console.WriteLine($"SRID: {srid}");
Console.WriteLine($"Byte order: {byteOrder}");
Console.WriteLine($"Type: {type}");
Console.WriteLine($"Latitude(緯度): {latitude}");
Console.WriteLine($"Longitude(経度): {longitude}");

実行結果

SRID: 4326
Byte order: 1
Type: 1
Latitude(緯度): 35.6809591
Longitude(経度): 139.7673068

FAQ

Q. 手順1で生成したバイナリはWKBですか?

A. いいえ

/* MySQL系 ジオメトリ記憶形式 */
select ST_GeomFromText('POINT(35.6809591 139.7673068)', 4326)
/* E6 10 00 00 01 01 00 00 00 F3 7F FD C6 8D 78 61 40 F1 34 F4 AA 29 D7 41 40 */

/* WKB */
select ST_AsWKB(ST_GeomFromText('POINT(35.6809591 139.7673068)', 4326))
/* 01 01 00 00 00 F1 34 F4 AA 29 D7 41 40 F3 7F FD C6 8D 78 61 40 */
Q. MariaDBでSRID 4326は対応していますか?

A. 対応していません
https://stackoverflow.com/a/73285842/4771485

エクスプローラのナビゲーションウィンドウからCreative Cloud Filesを削除する方法

Ⅰ. はじめに

タイトルの通り「エクスプローラのナビゲーションウィンドウから Creative Cloud Files Personal Account user@example.com を削除する方法」です。

Ⅱ. 手順

1. 以下コマンドを実行する

reg add "HKEY_CLASSES_ROOT\CLSID\{0E270DAA-1BE6-48F2-AC49-090D8DE75392}" /v "System.IsPinnedToNameSpaceTree" /t REG_DWORD /d 0 /f

以上

実行結果

ナビゲーションウィンドウから削除された

Rust 基本文法メモ

fn say_hello(name: String) {
  println!("hello {name} !!!");
}

fn sum(a: i32, b: i32) -> i32 {
  return a + b;
}

fn main() {
  println!("Hello, world!");
  println!("aaa {}", "bbb");

  let mut a: i32 = 1;
  println!("a is :{}", a);
  a = 2;
  println!("a is :{}", a);

  let a: &str = "aaa";

  let a1: i32 = 1;
  let a2: u32 = 1;
  let a3: f64 = 1.0;
  let a4: bool = true;

  // cast
  let floatValue = 1 as f64;

  // tuple
  let tuple1 = (1,true, 2.0);
  let tuple2 = (1,true, 2.0);

  println!("{:?}", tuple1); // 全ての値
  println!("{:?}", tuple1.0); // インデックスで要素を指定する
  println!("{}", tuple1 == tuple2); // 比較

  // array
  let array1: [i32; 3] = [1,2,3]; // 1,2,3
  let array2: [i32; 100] = [0; 100]; // 0, 0, 0, .... 0

  println!("{:?}", array1);
  println!("{}", array1[0]);

  // Vector
  let vector1: Vec<i32> = vec![1,2,3];// 1,2,3
  let vector2: Vec<i32> = vec![0; 100]; // 0, 0, 0, .... 0
  let mut vector3 :Vec<i32> = Vec::new();
  vector3.push(1);
  vector3.push(2);
  vector3.push(3);
  println!("{vector3:?}");

  // LINQ
  // https://microsoft.github.io/rust-for-dotnet-devs/latest/linq/index.html
  let results = array1
      .iter()
      .filter(|x| x >= &&2)
      .collect::<Vec<&i32>>();

  println!("{results:?}");

  // char
  let c1: char = 'a';
  let c2: char = '😂';
  println!("{c1}, {c2}");

  // String
  let string1: String = String::from("abc");
  let mut string2: String = "def".to_string();
  string2 = string2 + " ghi";

  println!("{string2}");

  let string3 = format!("{string1}{string2}!!!");
  println!("{string3}");

  // Function
  say_hello("tanaka".to_string());
  println!("{}", sum(1, 2));

  // if
  if 1 > 0 && (true || false) {
      println!("aaa");
  } else if 1 > 0 {
      println!("bbb");
  } else {
      println!("ccc");
  }

  let result = if true { true } else {false};
  println!("{}", result);

  // Switch
  let x: i32 = 3;
  match x {
      0 => println!("x is 0"),
      1 | 2 => {
      println!("x is 1 or 2");
      println!("Multi line");
      },
      _ => println!("x is unknown")
  }

  let result = match x { 0 => 0, 1=>1, _=> 999};
  println!("{}", result);

  // While true
  let mut x: i32 = 0;
  loop {
      x += 1;
      if x > 10 {
      break;
      }

      if x %2 == 0 {
      continue;
      }

      println!("hello");
  }

  // while
  let mut x: i32 = 0;
  while x < 10 {
      println!("while x: {}", x);
      x += 1;
  }

  // for
  for x in [1,2,3] {
      println!("for x: {}", x);
  }
}
// 関数引数の参照渡し
fn concat (a: &String, b: &String) -> String{
  return format!("{a}{b}");
}

fn main(){
  let s1: String = "hello".to_string();
  let s2: String = "world".to_string();
  let s3: String = concat(&s1, &s2);

  println!("{s1} {s2} {s3}");
}

cpprestsdkを利用してWebサーバを構築する方法

Ⅰ. はじめに

タイトルの通り「cpprestsdkを利用してWebサーバを構築する方法」です。

Ⅱ. サンプルプログラム

#include <Windows.h>
#include <iostream>
#include <format>

#include <cpprest/http_listener.h>

int main()
{
  SetConsoleOutputCP(CP_UTF8);

  auto address = utility::conversions::to_string_t("http://127.0.0.1:80");
  web::http::experimental::listener::http_listener listener(address);

  listener.support(web::http::methods::GET, [](web::http::http_request request)
    {
      auto parameters = web::uri::split_query(request.request_uri().query());
      auto param1 = utility::conversions::utf16_to_utf8(parameters.at(L"param1"));
      auto param2 = utility::conversions::utf16_to_utf8(parameters.at(L"param2"));

      std::cout << param1 << std::endl;
      std::cout << param2 << std::endl;

      request.reply(web::http::status_codes::OK, "OK");
    });

  listener.support(web::http::methods::POST, [](web::http::http_request request)
    {
      auto json = request.extract_json().get();
      auto name = utility::conversions::utf16_to_utf8(json[L"name"].as_string());

      std::cout << name << std::endl;

      auto str = std::format("Hello {0}", name);
      request.reply(web::http::status_codes::OK, str);
    });

  listener.open().wait();

  getchar();
  listener.close();
  return 0;
}

実行結果

GET
POST