-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSQLGetTableFields.fmfn
96 lines (87 loc) · 3.63 KB
/
SQLGetTableFields.fmfn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* =====================================================
* @function SQLGetTableFields ( TableName; IgnoreName; IgnorePrefix )
*
* @parameter TableName (string)
* @parameter IgnoreName (List)
* @parameter IgnorePrefix (List)
*
* @return list List of fields in TableName.
*
* @category logical
* @copyright 2014, Jason P. Scharf
*
* @version 0.0.2
*
* @dependencies text.explode, list.implode
*
* @purpose Get a list of fields from TableName that do not include fields
* in IgnoreName or that start with anything in IgnorePrefix.
*
* @todo NONE
*
* @changes
* 2014-08-21, JPS, Created (0.0.1).
* 2014-08-24, JPS, Added @DEBUG command to IgnoreName (0.0.2).
* @/changes
* =====================================================
*/
Let (
[
/************************/
/* Start Configuration **/
/************************/
/*
* Test to see if the provided TableName is a Table Name string or
* fields contents.
*/
~isFQFN = EvaluationError ( GetFieldName ( TableName ));
~FQFN = If ( ~isFQFN = 0; GetFieldName ( TableName ); "?" );
~tableName = If ( ~FQFN = "?"; TableName; ~FQFN );
/* If TableName os not provided, get the current layouts table name. */
~tableName = If ( IsEmpty ( ~tableName ); Get ( LayoutTableName ); ~tableName);
/* Remove @DEBUG */
~ignoreName = Substitute ( IgnoreName ; "@DEBUG" ; "" );
/* Unquote IgnoreName */
~ignoreFieldName = Substitute ( ~ignoreName ; "\"" ; "" );
/* Encode Special Characters in IgnorePrefix for LIKE. */
~ignoreFieldPrefix = Substitute (
IgnorePrefix ;
[ "_" ; "\_" ];
[ "%" ; "\%" ]
);
/* CONSTANTS ************/
VERSION = "0.0.2";
DEBUG = ( PatternCount ( IgnoreName ; "@" ) = 1 );
/************************/
/* End Configuration ****/
/************************/
/* Check to see if the provided TableName is a FQFN */
~isFullyQualifiedFieldName = PatternCount ( ~tableName ; "::" ) = 1;
/* Resolve the table name */
~resolvedTableName = If ( ~isFullyQualifiedFieldName; GetValue ( text.explode ( "::"; ~tableName ); 1 ); ~tableName );
/* Use ExecuteSQL and VirtualScheme to get a list of fields. */
~fieldQueryBase = "SELECT FieldName FROM FileMaker_Fields WHERE TableName = ?";
~fieldQueryOmitFieldByName = If ( not IsEmpty ( ~ignoreFieldName ); " AND FieldName NOT IN ('" & list.implode ( "', '"; ~ignoreFieldName ) & "')");
~fieldQueryOmitFieldByPrefix = If ( not IsEmpty ( ~ignoreFieldPrefix ); " AND UPPER ( FieldName ) NOT LIKE UPPER ('" & list.implode ( "%') AND UPPER ( FieldName ) NOT LIKE UPPER('"; ~ignoreFieldPrefix ) & "%')");
~fieldQueryCombined = ~fieldQueryBase & ~fieldQueryOmitFieldByName & ~fieldQueryOmitFieldByPrefix;
~fieldQueryResults = ExecuteSQL ( ~fieldQueryCombined; ""; ""; ~resolvedTableName )
];
Case (
DEBUG;
List (
"Version: " & VERSION;
"Table Name: " & ~tableName;
"Table Name - Resolved: " & ~resolvedTableName;
" -- Ignore Fields -- ";
text.tab & "Name: " & ~ignoreFieldName;
text.tab & "Prefix: " & ~ignoreFieldPrefix;
"Query: " & ~fieldQueryCombined;
"Query Error: " & EvaluationError ( ExecuteSQL ( ~fieldQueryCombined; ""; ""; ~resolvedTableName ));
" -- Results -- ";
~fieldQueryResults;
);
/* DEFAULT */
~fieldQueryResults
)
)