-
Notifications
You must be signed in to change notification settings - Fork 24
/
myDataDigger.txt
368 lines (313 loc) · 14.8 KB
/
myDataDigger.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/*************************************************************************
File : myDataDigger.p
Purpose : Customized routines for DataDigger.
WARNING: This .txt file is for documentation purposes.
It will be overwritten with each new version of DataDigger.
More information on the DataDigger wiki on customization
Check https://github.com/patrickTingen/DataDigger/wiki
tl;dr: Create your own custom procedure by copying this program to
"myDataDigger.p". It will then be compiled and started when DD
starts. The file 'myDataDigger.p' (extension ".P") will never be
part of the distribution, so your version will not be overwritten.
Using QAD? Look for #QAD tags in this file.
HISTORY: DD18: customFilter added.
DD18: customDump moved here instead of having its own .p
DD20: customShowField added
DD21: customSaveFilterValue / customGetFilterValue added, customFilter removed
DD24: added support for events 'query' and 'datadigger'
*************************************************************************/
/* All functions of DataDigger, see DataDiggerLib for a full list */
{datadigger.i}
/* #QAD
/* You might like to set global_domain based on (for example) database name */
define new global shared variable global_domain as character.
*/
/* #QAD users might use this function to determine the
* domain-field in a table
*/
FUNCTION getDomainFieldName RETURNS CHARACTER
( pcDatabase AS CHARACTER
, pcTable AS CHARACTER ):
DEFINE VARIABLE cDomainFieldName AS CHARACTER NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hBufferField AS HANDLE NO-UNDO.
/*
** SDBNAME wille return a different name
** if pcDatabase is a non Progress database like MSS [dataserver]
*/
IF SDBNAME(pcDatabase) <> pcDatabase THEN RETURN "".
/* Determine the name of the domain field, based on the table */
IF (INDEX(pcTable, "_") > 0) THEN
cDomainFieldName = SUBSTRING(pcTable, 1, R-INDEX(pcTable, "_")) + "domain".
ELSE
cDomainFieldName = pcTable + "_domain".
/* Now see if the field really exists */
CREATE BUFFER hBuffer FOR TABLE SUBSTITUTE("&1.&2",pcDatabase,pcTable) NO-ERROR.
IF VALID-HANDLE(hBuffer) THEN
hBufferField = hBuffer:BUFFER-FIELD(cDomainFieldName) NO-ERROR.
IF NOT VALID-HANDLE(hBufferField) THEN cDomainFieldName = "".
DELETE OBJECT hBuffer NO-ERROR.
RETURN cDomainFieldName.
END FUNCTION. /* getDomainFieldName */
/*
PROCEDURE setWindowTitle:
/*
* Name: setWindowTitle
* Desc: Change the title of the main window
*
* This hook enables you to change the title of the DataDigger window.
*
* This is handy if you want to have other information in the title bar
* that is not provided by DataDigger (for example user name)
*
*/
DEFINE INPUT PARAMETER pcDatabase AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcTable AS CHARACTER NO-UNDO.
DEFINE INPUT-OUTPUT PARAMETER pcTitle AS CHARACTER NO-UNDO.
/* Example 1: add user name to title bar
IF NUM-DBS > 0 THEN pcTitle = pcTitle + ' ' + USERID(LDBNAME(1)).
*/
/* Example 2: replace title with simple version of db + table name
pcTitle = SUBSTITUTE('&1.&2', pcDatabase, pcTable).
*/
END PROCEDURE. /* setWindowTitle */
*/
/*
PROCEDURE customShowField:
/*
* Name: customShowField
* Desc: Change the visibility for a field
*
* This hook enables you to change the default visibility of a field.
*
* This is handy if you have some fields in your database that
* you never want to select, for example fields that have been added by
* your framework to all tables but which do not hold value for you.
*
* Note that this is just the default visibility. During run-time you
* can always change the visibility.
*/
DEFINE INPUT PARAMETER pcDatabase AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcTable AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcField AS CHARACTER NO-UNDO.
DEFINE INPUT-OUTPUT PARAMETER plShow AS LOGICAL NO-UNDO.
/* Example 1: hide the cust-num field except on the customer table
IF pcField = 'cust-num' AND pcTable <> 'customer' THEN plShow = FALSE.
*/
/* Example 2: hide the default RECID and ROWID field
IF pcField = 'RECID' OR pcField = 'ROWID' THEN plShow = FALSE.
*/
/* Example 3: By default, do not show extra #QAD fields */
/* IF pcField MATCHES '*__*' THEN plShow = FALSE. */
END PROCEDURE. /* customShowField */
*/
/*
PROCEDURE customFormat:
/*
* Name: customFormat
* Desc: Change the format for a field
*
* Depending on the input parameters you are able to adjust
* the format of a field. This routine is called after the
* custom format is fetched from the user settings.
*
* This is handy if - for example - all userid fields in your
* database have the wrong format. Or if you want to show
* all decimal fields with 4 decimals instead of 3.
*/
DEFINE INPUT PARAMETER pcDatabase AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcTable AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcField AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcDatatype AS CHARACTER NO-UNDO.
DEFINE INPUT-OUTPUT PARAMETER pcFormat AS CHARACTER NO-UNDO.
/* Example code: set minus sign at the front of an decimal field */
/* IF pcDataType = "DECIMAL" */
/* AND NOT pcFormat BEGINS "-" THEN pcFormat = "-" + pcFormat. */
/* Example code: Use at least 3 decimals for price field */
/* IF pcDataType = 'DECIMAL' */
/* AND pcField = 'Price' */
/* AND pcFormat MATCHES '*~~.99' THEN pcFormat = pcFormat + '9'. */
END PROCEDURE. /* customFormat */
*/
/*
PROCEDURE CustomDump:
/*
* Name: customDump.p
* Desc: Customized dump data from DataDigger
*
* DataDigger will call this file with the following parameters:
*
* input pcAction (character) - type of dump (Delete | Save)
* input pcDatabase (character) - name of the database
* input pcTable (character) - name of the table
* input phData (handle ) - handle to a dynamic tt with the data to dump
* input pcFilename (character) - filename as suggested by DataDigger
*
* The phData parameter is a handle to a temp-table that holds only the
* data you would like to dump. So it contains 1 record in case of a save
* action and 1 or more in case of a delete action.
*
* You can give these parameters back to DataDigger:
*
* output pcMessage (character) - a message to show the user
* output plDefaultDump (logical ) - perform regular DD dump or not
* output plContinue (logical ) - perform regular DD dump or not
*
* pcMessage:
* This can be an informative message, a warning or an error. This
* will be shown to the user by DataDigger.
*
* plDefaultDump
* This tells DD whether to perform its own dump or not.
*
* plContinue
* This tells DD whether the action should be committed. You
* can use this to prevent certain delete or save actions.
*
*
* Note that if you do your own dump, using the filename DD suggests in pcFilename
* and you set plDefaultDump to TRUE, DD will overwrite your file because it too
* uses this filename to dump its data.
*
*/
DEFINE INPUT PARAMETER pcAction AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcDatabase AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcTable AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER phData AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER pcFilename AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER pcMessage AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER plDefaultDump AS LOGICAL NO-UNDO INITIAL TRUE.
DEFINE OUTPUT PARAMETER plContinue AS LOGICAL NO-UNDO INITIAL TRUE.
/* Example code: ask if user is really sure to delete */
/* IF pcAction = 'Delete' THEN */
/* DO: */
/* MESSAGE 'Are you really really really sure you want to delete these precious records?' */
/* VIEW-AS ALERT-BOX INFORMATION BUTTONS YES-NO UPDATE plContinue. */
/* END. */
/* */
/* ELSE */
/* DO: */
/* /* This will export your data just like DataDigger does */ */
/* phData:WRITE-XML */
/* ( 'file' /* TargetType */ */
/* , pcFileName /* File */ */
/* , YES /* Formatted */ */
/* , ? /* Encoding */ */
/* , ? /* SchemaLocation */ */
/* , NO /* WriteSchema */ */
/* , NO /* MinSchema */ */
/* ). */
/* ASSIGN plContinue = TRUE. */
/* END. */
END PROCEDURE. /* CustomDump */
*/
/*
PROCEDURE customQuery:
/*
* Name: customQuery.p
* Desc: Adjust query string
*
* This routine is called when DataDigger places a query in the WHERE-editor
* and when you select a table. In that case the query is empty. In all
* cases this routine is called just prior to placing the text in the query
* editor. This gives you a chance to alter the query.
*
* INPUT pcDatabase (character) - name of the database
* INPUT pcTable (character) - name of the table
* INPUT-OUTPUT pcQuery (character) - your query string
*
*/
DEFINE INPUT PARAMETER pcDatabase AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcTable AS CHARACTER NO-UNDO.
DEFINE INPUT-OUTPUT PARAMETER pcQuery AS CHARACTER NO-UNDO.
/* Example code: get the most recently used query from query history */
/* IF pcQuery = "" THEN */
/* pcQuery = DYNAMIC-FUNCTION("getQuery", pcDatabase, pcTable, 1). */
END PROCEDURE. /* customQuery */
*/
/*
PROCEDURE DataDigger:
/*
* Name: DataDigger
* Desc: Called on open and close of a DataDigger window.
*
* When DD is started and closed, this event is published
* with piNumber = 1 for opening and -1 for closing.
*/
DEFINE INPUT PARAMETER piNumber AS INTEGER.
/* Example code: quit DD when a certain .txt file is found
*
/* Check if we are allowed to start */
IF piNumber = 1
AND SEARCH('db-maintenance.txt') <> ? THEN
DO:
MESSAGE 'Sorry, db is in maintenance, please try again later' VIEW-AS ALERT-BOX.
QUIT.
END.
*/
END PROCEDURE. /* DataDigger */
*/
/*
PROCEDURE customGetFilterValue:
/*
* Name: customGetFilterValue
* Desc: After the data browse is created, the filter fields
* are created one by one. You can use this routine to
* give them a default value.
*/
DEFINE INPUT PARAMETER pcDatabase AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcTable AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcField AS CHARACTER NO-UNDO.
DEFINE INPUT-OUTPUT PARAMETER pcFilterValue AS CHARACTER NO-UNDO.
/* Example code: set a particular field to a specific value */
/* IF pcField MATCHES "*_domain" THEN pcFilterValue = global_domain. */
END PROCEDURE. /* customGetFilterValue */
*/
/*
PROCEDURE customSaveFilterValue:
/*
* Name: customSaveFilterValue
* Desc: Perform actions based on the value of a filter
*
*/
DEFINE INPUT PARAMETER pcDatabase AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcTable AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcField AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcFilterValue AS CHARACTER NO-UNDO.
/* Example code: save value of a particular field
* #QAD users could use this to catch filtering on global_domain
* and then later adding it to the query.
*/
/* IF pcField MATCHES "*_domain" THEN global_domain = pcFilterValue. */
END PROCEDURE. /* customSaveFilterValue */
*/
/*
PROCEDURE queryOpen:
/*
* Name: queryOpen
* Desc: Receive the full query that is executed
*/
DEFINE INPUT PARAMETER pcQuery AS CHARACTER NO-UNDO.
/* DEFINE VARIABLE iWord AS INTEGER NO-UNDO. */
/* DEFINE VARIABLE cValue AS CHARACTER NO-UNDO. */
/* */
/* /* Remove double spaces */ */
/* DO WHILE REPLACE(pcQuery,' ', ' ') <> pcQuery: */
/* pcQuery = REPLACE(pcQuery,' ', ' '). */
/* END. */
/* */
/* /* Parse the query word by word and look for the domain field */
/* * If the domain field is used in an equality match, filter out */
/* * the value and save that as the new global_domain */
/* */ */
/* DO iWord = 1 TO NUM-ENTRIES(pcQuery,' ') - 2: */
/* IF ENTRY(iWord,pcQuery,' ') MATCHES '*_domain' */
/* AND ENTRY(iWord + 1,pcQuery,' ') = '=' THEN */
/* DO: */
/* cValue = ENTRY(iWord + 2,pcQuery,' '). */
/* cValue = TRIM(cValue,'()"~''). */
/* IF cValue > '' THEN global_domain = cValue. */
/* END. */
/* END. */
END PROCEDURE. /* queryOpen */
*/