forked from 4D-JP/code-audit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_foreign_key_stats.txt
65 lines (53 loc) · 1.72 KB
/
get_foreign_key_stats.txt
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
$dataTypeMap:=New collection
$dataTypeMap[1]:="boolean"
//
$dataTypeMap[3]:="16-bit integer"
$dataTypeMap[4]:="32-bit integer"
$dataTypeMap[5]:="64-bit integer"
$dataTypeMap[6]:="real"
$dataTypeMap[7]:="float"
$dataTypeMap[8]:="date"
$dataTypeMap[9]:="time"
$dataTypeMap[10]:="text inside record"
//11
$dataTypeMap[12]:="picture"
$dataTypeMap[13]:="UUID"
$dataTypeMap[14]:="text outside record"
//15
//16
//17
$dataTypeMap[18]:="BLOB"
$dataTypeMap[19]:="text inside record" //utf8
$dataTypeMap[20]:="text outside record" //utf8
$dataTypeMap[21]:="object"
ARRAY LONGINT($types;0)
//N-field
Begin SQL
SELECT DISTINCT(_USER_COLUMNS.DATA_TYPE)
FROM _USER_CONS_COLUMNS,_USER_COLUMNS,_USER_CONSTRAINTS
WHERE _USER_CONSTRAINTS.CONSTRAINT_TYPE= '4DR'
AND _USER_CONSTRAINTS.CONSTRAINT_ID = _USER_CONS_COLUMNS.CONSTRAINT_ID
AND _USER_COLUMNS.TABLE_ID = _USER_CONSTRAINTS.TABLE_ID
AND _USER_COLUMNS.COLUMN_ID = _USER_CONS_COLUMNS.COLUMN_ID
INTO :$types;
End SQL
$typesN:=New collection
ARRAY TO COLLECTION($typesN;$types)
C_LONGINT($type)
$results:=New collection
ARRAY TEXT($fields;0)
For each ($type;$typesN)
Begin SQL
SELECT DISTINCT(CONCAT(CONCAT(_USER_COLUMNS.TABLE_NAME,'.'),_USER_COLUMNS.COLUMN_NAME))
FROM _USER_CONS_COLUMNS,_USER_COLUMNS,_USER_CONSTRAINTS
WHERE _USER_CONSTRAINTS.CONSTRAINT_TYPE= '4DR'
AND _USER_CONSTRAINTS.CONSTRAINT_ID = _USER_CONS_COLUMNS.CONSTRAINT_ID
AND _USER_COLUMNS.TABLE_ID = _USER_CONSTRAINTS.TABLE_ID
AND _USER_COLUMNS.COLUMN_ID = _USER_CONS_COLUMNS.COLUMN_ID
AND _USER_COLUMNS.DATA_TYPE = :$type
INTO :$fields;
End SQL
$results.push(New collection(\
$dataTypeMap[$type];String(Size of array($fields))).join("\t"))
End for each
SET TEXT TO PASTEBOARD($results.join("\r"))