0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Filemaker ExecuteSQL用のSQL文作成を補助するカスタム関数

Posted at

FilemakerのSQL文はフィールドをダブルクォーテーションで囲んだり面倒な上に、テーブル名やフィールド名を変更しても連動しないために忘れずに変更しないといけない。

ということで、そこを少しだけ補助するカスタム関数。

テーブル名、フィールド名をクォーティション付きに変換する

カスタム関数: SQL用テーブル名

Let (
	fn = GetFieldName ( field );
	"\"" & GetValue ( Substitute ( fn; "::"; "¶" ); 1 ) & "\""
)

カスタム関数: SQLフィールド名

Let (
	fn = GetFieldName ( field );
	"\"" & Substitute ( fn; "::"; "\".\"" ) & "\""
)

使用方法

カスタム関数を使用しない通常の書き方の例

Let ( [
	%sql = "
		select
			\"field1\",
			\"field2\"
		from
			\"tableA\"
		where
			\"key\" = ?
		";
	%rows = ExecuteSQL ( %sql; ""; ""; "keyword" );
%=0];
	%rows
)

カスタム関数を使用した場合

Let ( [
	%sql = "
		select
			" & SQL用フィールド名 ( tableA::field1 ) & ",
			" & SQL用フィールド名 ( tableA::field2 ) & "
		from
			" & SQL用テーブル名 ( table::PK ) & "
		where
			" & SQL用フィールド名 ( table::key ) & " = ?
		";
	%rows = ExecuteSQL ( %sql; ""; ""; "key1" );
%=0];
	%rows
)

カスタム関数内でGetFieldNameによりテーブル名やフィールド名の置き換えが行なわれるので、テーブル定義で名称を変更しても連動して動く。
また、計算式を作成する際にFilemakerのコード支援が効くので、SQL文を作るのが少し楽です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?