QMF DB2 BBDD
QMF DB2 BBDD
QMF DB2 BBDD
www.redbooks.ibm.com
SG24-5746-00
SG24-5746-00
December 1999
Take Note!
Before using this information and the product it supports, be sure to read the general information in
Appendix E, “Special notices” on page 393.
This edition applies to Version 6, Release 1 Refresh of QMF for Windows, Program Number 5655-DB2
for use with the Windows NT Operating System.
When you send information to IBM, you grant IBM a non-exclusive right to use or distribute the
information in any way it believes appropriate without incurring any obligation to you.
Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xi
Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
The team that wrote this redbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Comments welcome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
v
6.5.1 Create new tables . . . . . . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 198
6.5.2 Create new queries . . . . . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 199
6.5.3 Create new form and report . . . . . . . . . . . .. . . . .. . . . . .. . . . 211
6.5.4 Create new procedures . . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 227
6.6 Using Data Snap-Ins for QMF for Windows . . . .. . . . .. . . . . .. . . . 231
6.6.1 Lotus 123 . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 232
6.6.2 Microsoft Excel . . . . . . . . . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 235
6.6.3 Microsoft Access . . . . . . . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 238
6.7 Converting dynamic SQL to static SQL. . . . . . . .. . . . .. . . . . .. . . . 242
6.7.1 Dynamic versus static SQL . . . . . . . . . . . . .. . . . .. . . . . .. . . . 243
6.8 Checking your resource limits . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 243
6.9 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 246
6.9.1 Change password capability . . . . . . . . . . . .. . . . .. . . . . .. . . . 246
6.9.2 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 247
6.10 Customizing the interface . . . . . . . . . . . . . . . . .. . . . .. . . . . .. . . . 249
6.11 Migrating from OS/2 Query Manager . . . . . . . .. . . . .. . . . . .. . . . 251
vii
B.48 GetQMFObjectInfo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
B.49 GetQMFObjectInfoEx() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
B.50 GetQMFObjectList() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
B.51 GetQMFObjectListEx() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
B.52 GetQMFProcText() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
B.53 GetQMFQueryText() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
B.54 GetQueryText() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
B.55 GetQueryVerb() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
B.56 GetResourceLimit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
B.57 GetResourceLimitEx(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
B.58 GetRowCount() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
B.59 GetServerList() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
B.60 GetServerListEx() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
B.61 GetStoredProcedureResultSets() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
B.62 GetVariables() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
B.63 GetVariablesEx(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
B.64 InitializeProc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
B.65 InitializeQuery() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
B.66 InitializeServer() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
B.67 InitializeStaticQuery() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
B.68 IsStatic() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
B.69 Open() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
B.70 Prepare(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
B.71 PrintReport() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
B.72 ReinitializeServer() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
B.73 Rollback() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
B.74 RunProc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
B.75 SaveData() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
B.76 SaveQMFProc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
B.77 SaveQMFQuery() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
B.78 SetBindOption() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
B.79 SetBindOwner() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
B.80 SetBusyWindowButton() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
B.81 SetBusyWindowMessage() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
B.82 SetBusyWindowMode() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
B.83 SetBusyWindowTitle(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
B.84 SetGlobalVariable(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
B.85 SetHostVariable() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
B.86 SetOption() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
B.87 SetParent() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
B.88 SetProcVariable() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
B.89 SetVariable() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
B.90 ShowBusyWindow() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
viii A DB2 Enterprise Query Environment — Build It with QMF for Windows !
B.91 StartBind() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
ix
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
xii A DB2 Enterprise Query Environment — Build It with QMF for Windows !
84. Save data into new table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
85. New SQL query menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
86. New query window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
87. Save new SQL query at server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
88. Substitution variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
89. New prompted query window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
90. Select tables to a new prompted query,. . . . . . . . . . . . . . . . . . . . . . . . . . 205
91. Adding join condition to a new prompted query . . . . . . . . . . . . . . . . . . . . 206
92. Adding columns to a new prompted query. . . . . . . . . . . . . . . . . . . . . . . . 207
93. Add sort condition to a new prompted query . . . . . . . . . . . . . . . . . . . . . . 208
94. Add row condition to a new prompted query . . . . . . . . . . . . . . . . . . . . . . 209
95. Displaying result of the new prompted query. . . . . . . . . . . . . . . . . . . . . . 210
96. Saving new prompted query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
97. New blank form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
98. New blank form main window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
99. Adding columns to a new blank form . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
100.Saving new blank form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
101.Ways of creating new form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
102.Using the sum function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
103.Result of group and sum functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
104.Modify column order in a form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
105.Final result of the modified form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
106.New procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
107.Saving new procedure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
108.Lotus 123 Snap-In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
109.Formatting data using Lotus 123 Snap-In . . . . . . . . . . . . . . . . . . . . . . . . 234
110.Result of Lotus 123 Snap-In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
111.Excel Snap-In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
112.Formatting data using Excel Snap-In . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
113.Result of Excel Snap-In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
114.Access Snap-In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
115.Selecting a table to place the data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
116.Select and report list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
117.Result of access Snap-In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
118.Retrieve the most current resource limits . . . . . . . . . . . . . . . . . . . . . . . . 245
119.Resource limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
120.Change password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
121.Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
122.Customize toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
123.Move the toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
124.Web environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
125.Convert form to HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
126.Form main . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
xiii
127.Form main window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
128.Form detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
129.HTML form preview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
130.Publishing procedure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
131.Dynamic reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
132.CGI example -— first screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
133.CGI example -— second screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
134.An Enterprise Query Environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
135.Rocket personal portal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
136.Properties screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
137.Copy to favorites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
138.Windows registry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
139.Variable structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
140.Substitution variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
141.Global variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
142.Adding global variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
143.New global variable created . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
144.Object activity detail table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
145.Object activity summarization table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
146.Object data table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
147.Object directory table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
148.Object remarks table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
149.RAA subtype table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
150.AuthID table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
151.Profile table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
152.Reserved table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
153.Resource table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
154.RAA object view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
155.Admin view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
156.AuthID View. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
157.Profile view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
158.Resource view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
159.Table view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
160.User admin view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
161.User AuthID view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
162.Q.RAA_OBJECT_VIEW relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
163.RDBI.TABLE_VIEW relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
xiv A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Tables
xvi A DB2 Enterprise Query Environment — Build It with QMF for Windows !
84. GetServerListEx parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
85. GetStoredProceduresResultSets parameters . . . . . . . . . . . . . . . . . . . . . 351
86. GetVariables parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
87. GetVariablesEx parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
88. InitializeProc parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
89. Valid values for the parameter SourceType. . . . . . . . . . . . . . . . . . . . . . . 354
90. InitializeQuery parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
91. Valid values for the parameter sourcetype . . . . . . . . . . . . . . . . . . . . . . . 355
92. InitializeServer parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
93. InitializeStaticQuery parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
94. IsStatic parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
95. Open parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
96. Prepare parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
97. RunProc parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
98. SaveData parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
99. SaveQMFProc parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
100.SaveQMFQuery parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
101.SetBindOption parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
102.Meanings and Values for the options . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
103.SetBindOwner parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
104.SetBusyWindowButton parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
105.SetBusyWindowMessage parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 369
106.SetBusyWindowMode parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
107.Valid values for the parameter mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
108.SetBusyWindowTitle parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
109.SetGlobalVariable parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
110.SetHostVariable parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
111.SetOption parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
112.Valid values for the parameter Option . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
113.SetParent parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
114.SetProcVariable parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
115.SetVariable parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
116.ShowBusyWindow parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
117.StartBind parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
xvii
xviii A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Preface
Administering and accessing these diverse data sources can easily become
a nightmare for people who need to work with them. Each database
management system may provide a different user interface, and this fact
alone makes end users and companies unhappy, because they must either
learn different user interfaces or must invest extensively in education.
This redbook will help you design and implement a solution to build an
Enterprise Query Environment using QMF for Windows. We discuss specifics
for three typical users of this product: database administrators, application
developers, and end-users. We describe the WWW functionality and other
specifics of the product, such as its capabilities for Business-to-Business and
Customer-to-Business applications. The information provided particularly
applies to Version 6, Release 1 Refresh of QMF for Windows, Program
Number 5655-DB2, for use with the Windows NT Operating System.
Michael Biere
IBM Cincinnati
Mark Flores
IBM Santa Teresa Lab
Tom Iglehart
Rocket Software
Vasilis Karras
IBM ITSO, Poughkeepsie Center
Matthew G. Kelley
Rocket Software
Andrea Reid
IBM Santa Teresa Lab
Mark Romano
IBM Santa Teresa Lab
Jon A. Scheer
Life Cycle Consulting Inc., Torrance, CA
Shawn Sullivan
Rocket Software
Dave Ward
Washington Mutual, Seattle, WA
Shirley Worthington
Multnomah County, Portland, OR
Andy Youniss
Rocket Software
xxi
Comments welcome
Your comments are important to us!
xxii A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Chapter 1. Introduction to query management
This redbook is about implementing a DB2 query and reporting tool, the
Query Management Facility (QMF), specifically using QMF for Windows, into
an existing enterprise environment. The audience of the redbook is intended
to be database administrators, application developers, end-users, and other
IT professionals with a need for an enterprise query and reporting
environment.
Data Mining
Knowledge
Predict (Discovery)
Information
Queries Single-Dimensional
Result Set
Data
Observe
Now, with the emergence of World Wide Web technologies and the
acceptance of the Internet as a primary vehicle for distributing information,
there is an opportunity to maximize the return on investment in corporate
information. It is now possible to cost-effectively deliver reporting capabilities
to every user, from senior executives and production line workers, to sales
forces and branch offices across an entire organization and beyond, to
customers, suppliers, and other business partners. Query and reporting tools
should have some typical characteristics, such as being able to:
• Provide a common user interface.
• Centralize the administration.
• Give control over the resources used by the users.
• Prevent users from unwanted data access.
Data Mining
Operational Customer Segmentation
Business Business
Data Basket Analysis
Data Information Segment 1
Fraud Detection
Warehouse Warehouse Target Marketing
CUST.NR
AGE ?
NAT.
CITY Segment n
INCOME
BEHAVIOUR
HISTORY
Query / OLAP
Business Queries
Multi Dimensional
Extraction / Replication Analysis
Data Cleaning
Meta Data Management
Application Suport
Product integration
V2.4 Governor
V2.3 Data interchange (IXF)
Prompted query, SAA query
V2.2 interface
V2.1 Report enhancements
Table editor
Query enhancements
SAA callable interface
Remote DB support
Repository manager suport
Interface to Relational
Database Products.
V1.2 SQL/QBE language
V1.1 suport.
Report and command
enhancements
DBCS support
1984 - 1985 1986 - 1989 1990 - 1997 1998 - 1999
The QMF family is an integrated toolset for querying, reporting, and updating
data stored in the entire DB2 family as well as, when combined with DB2
DataJoiner, in nonrelational IBM data sources and other vendor relational
data sources. QMF is available in 15 national languages.
The QMF Family has moved from being an independent product for use with
DB2 for OS/390 and DB2 for VM and VSE to become a priced feature of the
DB2 product. QMF for Windows can also be ordered as a separate product to
access workstation DB2s only (AIX, OS/2, Windows NT, and so on).
The development and support of QMF HPO Manager and Compiler and QMF
for Windows is the responsibility of Rocket Software, an IBM business
partner since 1991.
2.2.1 IT issues
As mentioned previously, most of the typical business environments today
deal with a wide variety of databases, tools, and even operating systems.
One of the main challenges will be to get all these different products and
environments to work together in a way that is transparent to the user, who is
doing a day’s work.
Today, much of this is easy to implement; for example, TCP/IP has evolved to
become the standard for connectivity to different computer systems. In terms
of database access, there are some standards available that allow access to
different data sources, for example, Distributed Relational Database
Architecture (DRDA) or Open Database Connectivity (ODBC).
Dial-Up TCP/IP
Connection
This picture illustrates some concerns with this situation. For example:
• Not all of the data sources allow access using the same networking
protocol.
• Administering and tracking the application installation will get very
complex.
• The “Power User” needs access to all of the data sources available.
Therefore, he needs to know how to handle all of the proprietary front
ends. Once new queries or reports have been created, they should be
made available to a broad number of employees, requiring them to use the
same front end the query has been created with.
• The “End User” may only need access to predefined queries and reports,
but most of the tools are too complex to handle, as they also allow the
creation of new queries. Very often this kind of user even wants to use
their standard spreadsheet application or personal database to access all
the company data sources.
The majority of users may run the same query again and again. Once a query
has been redefined due to new requirements, the user needs to find a way (or
is told a way) to transfer this new query to his own system. Normally, the end
user would be happier if someone else who is better skilled in these matters
could perform this task. Providing a central shared query repository would
allow the queries to be edited at a single source and be available to the users
without any further action required.
Figure 7 shows a way to solve most, if not all, of the concerns raised
previously. It shows the addition of another product, DB2 DataJoiner, to the
existing environment to access non-DB2 data sources.
DB2 for OS/390 DB2 for VM DB2 for VSE DB2 for AIX DB2 for Windows DB2 for OS/2
QMF QMF QMF QMF for Windows QMF for Windows QMF for Windows
Dial-Up
Connection
Multi-Dimensional
Multi-Dimensional
OLAP
OLAP Tools
Tools
Data
Data Interpretation
Interpretation
Spreadsheets,
Spreadsheets, Statistics
Statistics
Operational
Data
Data Inquiry
Inquiry
QMF:
QMF: Query
Query and
and Reporting
Reporting
DBAs will appreciate QMF for Windows as a single product with the
capabilities to open all of the DB2 host and DB2 workstation database
platforms to Windows users (3.x, 9x, NT, and WIN-OS/2), without having
database gateways, middleware, or ODBC drivers to manage. QMF for
Windows provides resource management functions to block waste or abuse
through detailed permissions organized on each server by group, by
schedule, or by combinations of group and schedule.
QMF for Windows V6 can be ordered as a feature of DB2 for OS/390 V6, DB2 for
VSE and VM V6, as a feature of QMF V6 on each of the aforementioned S/390
platforms, or as a stand-alone product licensed to access DB2 workstation
databases only, as shown in Figure 9.
Note:
QMF for Windows has a “server based licensing”, which means that no
matter how many users use the product, the licensing is based on the DB2
servers (or subsystems) accessed. So, for each DB2 accessed, no matter
by how many users, only one QMF for Windows license is needed.
QM F for W indows
Standalone Product
W orkstation DB2 Access
2.5.1.1 Platforms
QMF for Windows is used to access two DB2 subsystems: a production
system and a test system, which both run MVS on an IBM ES9000-982.
2.5.1.2 Background
The bank is a large financial institution and has the task of providing accurate
and timely information to different areas of the company. After the decision
had been made to eliminate VM, a solution was needed to provide the users
with the same level of support they were receiving before. All of the
databases and associated tables and queries on VM were migrated to a
decision support DB2 subsystem.
One of the few weaknesses has been that the error messages, which appear
with communication problems using SNA as the protocol between the end
users workstation and the host, have been hard to interpret.
2.5.1.7 Deliverables
The new environment allows the end users to create new queries, and to
download data for report processing or for import into Windows applications.
2.5.2.1 Platforms
DB2 V 4.1 for MVS runs on an IBM 9672-R32 under OS/390. QMF runs on
this 9672 under both TSO and CICS, and is available to any user who has
security on the CICS region under which QMF runs. QMF for Windows is
installed on a Windows NT Server and is connected via LU 6.2 through an
SNA server.
2.5.2.2 Background
This institution supports local government’s information processing,
networking, software, and telecommunications needs.
2.5.2.7 Deliverables
The new environment allows the end users to create new queries easily by
using the prompted query feature of QMF for Windows, and to download and
utilize the data from the host easily.
This chapter explains the basic architecture behind the operation of QMF for
Windows and describes the prerequisite software and configuration that it
requires. It provides a step-by-step guide to install QMF for Windows and the
QMF for Windows Administrator. The intended audience is the person
(system programmer, or database administrator) responsible for installing
QMF for Windows.
From the application point of view, the base for all communication and data
transfer consists of communication protocols. Several protocols are available
for inter-system communication. Especially in the workstation area, you have
several options:
• The connectivity between the workstation environment and the host
systems is based, for example, on Ethernet or on Token Ring.
• The communication protocols mostly used in the workstation environment
are NetBIOS and TCP/IP. The protocol TCP/IP is used for communication
to host systems as well.
• The most common protocol in the host environment is still APPC
(Advanced Program to Program Communication) based on Shared
Network Architecture (SNA). The use of Advanced Peer-to-Peer
Networking (APPN) simplifies the configuration.
The next layer is the protocol or architecture supplying the base for the
data exchange between the data sources and targets.
QMF for Windows and DB2 are both distributed relational database
applications that operate together in a client/server relationship. Both QMF
for Windows and DB2 implement and adhere to DRDA. Each component
plays a separate and distinct role in this relationship:
• QMF for Windows is the DRDA application requester.
• DB2 acts as the DRDA application server.
One layer of DRDA describes the communication protocol that must be used
by the participants in the architecture. Specifically, it defines that requesters
and servers must communicate via the TCP/IP or the SNA LU 6.2 protocol.
Before installing, configuring, or using QMF for Windows you must verify that
the required network infrastructure is properly configured.
An interesting article about the history of the Internet can be found at:
http://www.isoc.org/internet-history/
So why has the use of TCP/IP grown at such a rate? The reasons include the
availability of common application functions across differing platforms and the
ability to access the Internet, but the primary reason is that of interoperability.
The open standards of TCP/IP allow corporations to interconnect or merge
different platforms. An example is the simple case of allowing file transfer
capability between an MVS/ESA host and, perhaps, a Hewlett Packard
workstation.
TCP/IP also provides for the routing of multiple protocols to and from diverse
networks. For example, a requirement to connect isolated networks using
IPX, AppleTalk, and TCP/IP protocols using a single physical connection can
be accomplished with routers using TCP/IP protocols.
One further reason for the growth of TCP/IP is the popularity of the socket
programming interface between the TCP/IP transport protocol layer and
TCP/IP applications. A large number of applications today have been written
for the TCP/IP socket interface.
3.2.2 IP addressing
IP uses IP addresses to specify source and target hosts on the Internet.
(For example, we can contrast an IP address in TCP/IP with a fully qualified
NETID.LUNAME in SNA). An IP address consists of 32 bits and is usually
represented in the form of four decimal numbers, one decimal number for
each byte (or octet). For example:
00001001 01000011 00100110 00000001 a 32-bit address
9 67 38 1 decimal notation
Some values for these host IDs and network IDs are preassigned and cannot
be used for actual network or host addressing:
• All bits 0
Stands for this: this host (IP address with <host address>=0) or this
network (IP address with <network address>=0). When a host wants to
communicate over a network, but does not know the network IP address, it
may send packets with <network address>=0. Other hosts on the network
interpret the address as meaning this network. Their reply contains the
fully qualified network address, which the sender records for future use.
3.2.3 Subnets
Because of the explosive growth of the Internet, the principle of assigned IP
addresses became too inflexible to facilitate changes to local network
configurations. Such changes might occur when:
• A new type of physical network is installed at a location.
• Growth of the number of hosts requires splitting the local network into two
or more separate networks.
• Growing distances require splitting a network into smaller networks, with
gateways between them.
Figure 12. Class A address with subnet mask and subnet address
We usually use a bit mask, known as the subnet mask, to identify which bits
of the original host address field to indicate the subnet number. In the above
example, the subnet mask is 255.255.255.192 in decimal notation (or
11111111 11111111 11111111 11000000 in bit notation). Note that, by
convention, the <network address> is masked as well.
For each of these subnet values, only (2**18)-2 addresses (from 1 to 262143)
are valid because of the all bits 0 and all bits 1 number restrictions. This split
will therefore give 262142 subnets, each with a maximum of (2**6)-2 or 62
hosts.
The value applied to the subnet number takes the value of the full byte, with
nonsignificant bits set to zero. For example, the hexadecimal value 01 in this
subnet mask assumes an 8-bit value, 01000000, and gives a subnet value of
64 (and not 1, as it might seem).
IP recognizes all host addresses as being on the local network for which the
logical_AND operation described above produces the same result. This is
important for routing IP datagrams in subnet environments (see “IP routing”
on page 33).
The subnet number shown above is a relative number, that is, it is the
68760th subnet of network 9 with the given subnet mask. This number bears
no resemblance to the actual IP address that this host has been assigned
(9.67.38.1) and has no meaning in terms of IP routing.
The division of the original <host address> part into <subnet> and <host>
parts can be chosen freely by the local administrator; except that the values
of all zeros and all ones in the <subnet> field are reserved for special
addresses.
3.2.4 IP datagram
The unit of transfer of a data packet in TCP/IP is called an IP datagram.
It is made up of a header containing information for IP and data that is only
relevant to the higher-level protocols. IP can handle fragmentation and
reassembly of IP datagrams. The maximum length of an IP datagram is
65,535 bytes (or octets). There is also a requirement for all TCP/IP hosts to
support IP datagrams of up to 576 bytes without fragmentation.
3.2.5 IP routing
There are two types of IP routing: direct and indirect. For example, Figure 14
shows that the host C has a direct route to hosts B and D, and an indirect
route to host A through gateway B.
The mappings are stored in the IP routing table (see Figure 15). Three types
of mappings can be found in this table:
• Direct routes, for locally attached networks
• Indirect routes, for networks reachable through one or more gateways
• Default route, which contains the (direct or indirect) route to be used if the
destination IP network is not found in the mappings of type 1 and 2 above
The routing table of host F might contain the symbolic entries shown in Figure
16.
Note:
• IP routing is an iterative process. It is applied by every host handling a
datagram, except for the host to which the datagram is finally delivered.
• Routing tables and the routing algorithm are local to any host in an IP
network. To forward IP datagrams on behalf of other hosts, routers must
exchange their routing table information with other routers in the
network, using special routing protocols.
QMF for Windows requires a WinSock 1.1 interface to the installed TCP
protocol stack.
If TCP/IP V3R1 for MVS is already installed on your system, it will in many
cases be useful to set up a separate TCP/IP started task for OpenEdition
MVS services.
Note
You can run one or more TCP/IP address space copies on a single MVS
system. To concurrently connect more than one TCP/IP instance to
OpenEdition MVS, you need to configure the OpenEdition MVS to use
Common I-Net (C-INET) AF_INET PFS, instead of integrated sockets
AF_INET PFS, which does not support multiple TCP/IP instances
connected to OpenEdition MVS.
When you have DB2 using TCP/IP, however, you can have only one
TCP/IP instance connect to OpenEdition MVS on the same MVS system,
because DB2 uses asynchronous I/O services, and C-INET AF_INET
PFS does not support asynchronous I/O. Therefore, the integrated
sockets AF_INET PFS must be used. In other words, you must configure
OpenEdition MVS to use the integrated sockets AF_INET PFS when
using DB2 with TCP/IP. Refer to the TCP/IP V3R1 for MVS:
Customization and Administration Guide, SC31-7134, for further
consideration of multiple copies of TCP/IP.
5647-A01 (C) Copyright IBM Corp. 1981, 1997. All rights reserved.
US Government Users Restricted Rights - Use, duplication or
F1=HELP F2=SPLIT F3=END F4=RETURN F5=IFIND F6=BOOK
F7=UP F8=DOWN F9=SWAP F10=LEFT F11=RIGHT F12=RETRIEVE
The following screen lists all the currently active jobs on the system.
You can see the multiple transport driver support TCPIP environment
(TCPIPOE, TCPIPMVS) on the sample screen above.
After completing the steps above, you should verify your system’s host name
and address configuration for TCP/IP OpenEdition (TCPIPOE) as follows:
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
The following screen shows the result of NETSTAT HOME TCP TCPIPOE command.
Alternatively you can check for the host name and IP address on the
OpenMVS ISPF Shell panel.
- Press Enter.
- Select an action bar choice.
- Specify an action code or command on the command line.
________________________________________________________________
________________________________________________________________
________________________________________________________________
Bottom
F3=Exit F4=Prompt F5=Refresh F10=Additional parameters F12=Cancel
F13=How to use this display F24=More keys
In addition to the TCP/IP protocol itself, you should check your system
configuration with DSPNETA to see if the database has been configured
properly. The entries listed as current system name, local control point name,
and default local location must be the same. In the example below, this
name is AS400.
More...
Press Enter to continue.
F3=Exit F12=Cancel
Position to . . . . . .
Relational Remote
Option Database Location Text
AS400 *LOCAL
Bottom
F3=Exit F5=Refresh F6=Print list F12=Cancel
(C) COPYRIGHT IBM CORP. 1980, 1998.
3.3.3 AIX
Before you can access a DB2 UDB database at the AIX system, TCP/IP must
be configured to allow the QMF client to connect to the AIX system. To check
the configuration:
Enter smit on the AIX command line. Following the selections shown below
leads to a screen like the one shown in Figure 18.
Select the defined network interface (Figure 19). If you don’t know the
network interface to be used, you need to ask your network administrator.
Check for the host name, domain name, and so on, as shown in Figure 20.
You will need to know the hostname or IP address in order to configure the
connectivity on the IM client.
Once this is done, you may want to check the TCP/IP status on the IM server
system.
Add the dotted decimal address and host name into the /etc/hosts file of the
IM client system (see Figure 21).
You can check the connection from the client to the server by typing PING
HOSTNAME on the command line.
3.3.4 Windows
We describe all actions in this section using Windows NT as a sample
system. Using Windows 95 as the operating system for the IM client might
have different screen names, but is basically the same procedure as shown
here for Windows NT.
Try to find out if you can reach the server machine through the TCP/IP
protocol from the machine you intend to use as the client. To test this, open
an NT Command Prompt window and type ping hostname for the desired
hostname.
If this fails, try to find out the IP address of the host. Unless your system is
configured using DHCP, you may find an entry in your local hosts file. Try to
ping the address instead of the hostname. If this also fails, your network
setup is incorrect and you should contact your network administrator.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows NT.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
9.9.9.9 examplehost
Never change the entry or address for localhost. Test your new setup by
saving your hosts file and then ping examplehost. This should now work.
You can use DHCP on your clients without any problems. If you need to use
DHCP on your IM server, the server’s hostname must be registered with a
DNS server, because you cannot specify a fixed IP address in the client’s
hosts file.
SNA provides function subsetting at a logical unit (LU) level. Thus, the
architecture provides standard option sets, in the form of profiles, which are
defined in the transmission control, data flow control, and presentation
services levels. A specific LU supports a subset of architected profiles that
reduces the number of options specific network products have to implement.
End users (for example, terminal users, applications) access the network
through the LU component of a network product. The LU manages the
exchange of data and acts as the intermediary between the end user and the
network.
The actual functions that can be used may vary from one APPC
implementation to another. Programs communicate using options that are
supported and agreed to by the APPC support on either side.
3.4.2.4 Sessions
The logical connection between LUs is called a session. Sessions are
established when one LU sends another LU the request to BIND. During this
BIND process, both partners exchange information about the characteristics
of the connection to be established. The LU that starts the session, the
initiator, is known as the primary LU, and the recipient of the session is known
as the secondary LU.
LUs have either single-session capability, that is, they allow only one active
LU-to-LU session with a partner LU at a time; or they have parallel-session
capability. With parallel-session support it is possible to have more than one
session with the same partner LU at the same time. Most LUs have
parallel-session capability.
3.4.2.5 Conversations
To avoid the overhead of session setup every time two LUs want to
communicate, another concept, that of a conversation, has been defined. A
conversation is the logical connection between TPs and is carried out over a
session. Conversations serially reuse a session to exchange end user
information. When a conversation ends, another conversation can be
allocated and use the same session. Sessions are typically long-lived links,
whereas conversations exist for the duration of the exchange of information,
for example, the time it takes to process a transaction.
When TPs communicate over an LU 6.2 conversation, there are a few areas
that they both agree on for compatibility.
Synchronization level provides a means by which two TPs (if they choose to
do so) reach a consistent state of processing with respect to the data
exchanged. The programs on either end synchronize their actions by
requesting and granting confirmations. Confirmation could be used, for
example, when one program wants to ensure that its partner received the
To alleviate this problem, a standard and consistent API has been defined for
applications that need to communicate in the APPC arena. The Common
Programming Interface for Communications (CPI-C) is common across
multiple environments and differs from the product-specific APIs in that it
provides an exact common syntax to specify the function calls and
parameters. CPI-C is designed to eliminate the mismatch of the verb
specifications in the different environments. This capability allows an
application programmer to learn the syntax on one platform and port the
knowledge or even part of the program to another supporting platform.
Application programs can use CPIC calls in the major languages such as
COBOL, C, FORTRAN, and PL/I. Pseudonym files are provided in the
different operating environments (in MVS, check SYS1.SAMPLIB). The files
can be "included" or "copied" into programs that call CPI-C.
For the time being, TCP/IP is not supported by DB2 for VSE V5, one of the
host data servers for this project, which just has support for APPC protocol.
On VSE, CICS handles the DRDA connectivity and also supports the
two-phase commit processing. VSE itself uses Cross Partition
Communication (XPCC) to talk to CICS.
The first step is to identify the appropriate values for the following definitions
in Table 1.
Table 1. SNA configuration parameters
Network ID USIBMSC
Local LU SC02242I
3.5.1 Windows NT
The following section guides you through the configuration of the CPI-C for a
Windows client using IBM Personal Communications Version 4.3.
1. To start the configuration, select the Windows NT Start Menu. Click on
Programs, then on IBM Personal Communication, and finally on SNA
Node Configuration.
2. Pull down the File menu and select New.
If you already have a valid Personal Communication configuration file and
you want to modify this, simply select your configuration file from the File
menu instead.
The window as shown in Figure 23 will open, showing the possible APPC
definitions required to define the CPI-C communication. In order to
configure Personal Communications for CPI-C, the following parameters
need to be configured:
- Configure Node
- Configure Devices
- Configure Connections
- Configure Partner LU 6.2
After all the entries are made, select the Advanced tab and make sure the
following parameters are set to on (checked):
• Activate Link at Start
• Solicit SSCP Sessions
The entry for the PU name can be left with its default value, DIRPU000. Make
sure that your local node’s Physical Unit ID is entered correctly.
Go on to the Adjacent Node tab and enter the values as shown in Figure 26,
then click OK to return to the main configuration window.
Clicking OK will confirm the parameters and the configuration file needs to be
saved by selecting Save As from the File menu.
The SQLDS private protocol is used for communication between DB2 Server
for VM and DB2 Server for VSE through Guest Sharing only. It provides no
DRDA functionality. With the setting of the DB2 for VSE or VM start-up
parameter PROTOCOL to either AUTO or SQLDS, you may decided whether
the database server accepts a DRDA request or private protocol only.
OS/390
A feature of DB2 DataJoiner called Classic Connect provides access to IMS
and VSAM data on OS/390 in a relational view. A server application running
on the host, maps the nonrelational data to the specified table image using
meta data. This meta data is generated from the COBOL copybooks or the
database descriptor block (DBD for IMS), which describe the format of the
data records.
VSE/ESA
A similar function is provided for access to VSAM, DL/I, and sequential files
on VSE by CrossAccess from CROSS ACCESS Corporation. The Server is
running permanently on the host to be accessed either through TCP/IP or
APPC. For every request, a Database Management System Interface (DMSI)
is started in another (dynamic) partition. The DMSI accesses the
nonrelational data, while the server maps it to the relational table image by
using the meta data, as described for Classic Connect.
To access a DB2 UDB server using CLI, the 32-bit version of QMF for
Windows must be able to establish a CLI connection from the local host (the
system on which QMF for Windows is running) to the remote host (the system
on which DB2 UDB is running) via the DB2 UDB client.
QMF for Windows requires the DB2 UDB client Version 5.2 or later to access
the database via CLI and supports CLI connections only to the DB2 UDB
database servers on the workstation environment, including DB2 DataJoiner.
When you insert the product CD-ROM you have the option of installing QMF
for Windows only, or also install the QMF for Windows Administrator. The
main installation process is very straight forward as long as the database
administrator installs the product using the distribution media. But this
requires the installation CD-ROM to be passed among the potential users and
each user has to perform the installation by himself and in addition will install
the full version, rather than the thin client. The following section describes this
installation process and its options in more detail.
Using a simple text editor, edit the setup.ini file. This file, on Disk1 of the
installation diskettes, controls the installation process and determines the
settings used for the installation. The variables you can set are shown in
Table 2.
Table 2. Installation parameters
For each of those components, 1 means it will be installed, 0 means it will not
be installed.
Example 1: Setup.ini
[Options]
AutoInstall=1
FileServerInstall=0
SetupType=2
InstallPath=C:\Programs\QMFWin
ProgramGroup=QMFWin
Base=1
Admin=0
Excel=0
1-2-3=1
Example 2: Setup.ini
[Options]
AutoInstall=1
FileServerInstall=1
SetupType=0
InstallPath=H:\QMFWin
ProgramGroup=QMFWin
When you are using QMF for Windows Administrator, you are always editing
a particular server definition file (SDF). The SDF contains all of the
technical information needed by QMF for Windows to access any number of
database servers. There are two ways (shown in Figure 29) to use server
definition files:
1. You can allow each user to have his or her own SDF.
2. You can create a single SDF that is shared by multiple users over a
file-sharing network. This approach has the advantage that it centralizes
administration of the SDF; you only need to create and maintain a single
file, and your users need only point to that file when they run QMF for
Windows.
SD F
Server 1
Server 2
Serv er X
SDF
Server 1
Server 2
Ser ver X
You can create a new SDF for a user or group of users by selecting the
New... command or the Save As... command from the File menu. To open
and work with a different SDF, select the Open... command from the File
menu.
Example of SDF:
[Server Parameters]
Server1=QMF Demo
Server2=DB2NT
Server3=DB2AIX
[QMF Demo]
RDBName=SAMPLE
HostName=qmfdemo.rocketsoftware.com
Port=40000
SymDestName=*TCP/IP*
DecimalDelimiter=Period
StringDelimiter=Apostrophe
RDBI-CollectionID-0000000000000012=QMFW611
QMFWin-CollectionID-0000000000000011=QMFW611
DefaultSchedule1=Y00000078000003840009601710000012C00000000000000000
00A0000000007FDFFFE00002710XX
[DB2NT]
Timestamp=19990830205032
RDBName=SAMPLE
HostName=78-axfxb
Note:
The server definition file is created and edited using the QMF for Windows
Administrator application. Editing this file using any other method is not
recommended, as it may corrupt the file.
You use QMF for Windows Administrator to define each server, giving it a
name and also specifying the technical information that QMF for Windows
needs to access it. This process is analogous to defining a data source in
ODBC. In order to define a new database server to QMF for Windows, from
the Administrator main window you must click New... and enter all of the
following required values on the Server Parameters dialog box:
Hint:
For DB2 OS/390 DBAs: If you are not sure of the value to enter here,
there is an easy way to determine the correct value; with a tool other
than QMF for Windows, run the following query at the server:
SELECT DISTINCT CURRENT SERVER FROM SYSIBM.SYSTABLES
After selecting the radio button for the required connection, you need to enter
the following values, depending on the selection made:
Host name: If you enter a TCP domain name for the host name, QMF for
Windows Administrator resolves that name to an address using the
GetHostByName socket call. Alternatively, you can directly specify the host
address in dotted decimal notation (for example, "1.2.3.4")
Port number: This is the TCP/IP port the database server is configured for
with its listener port in the services file.
CPI-C
Before configuring this connection, you must specify the SNA software that
you are using to implement CPI-C in your Windows environment. This
software has to be configured, and the CPI-C symbolic destination name
for the database server has to be defined before the QMF for Windows
installation. The CPI-C symbolic destination name is defined in your SNA
software as described in detail in 3.5, “Configuring your SNA (LU 6.2, APPC,
and CPI-C)” on page 55.
From the main window in QMF for Windows Administrator, select the
Options... command from the Edit menu. In the Options dialog box in the
CPI-C Options group, specify the name of the DLL that your SNA software
provides for CPI-C applications as shown in Figure 31 on page 75. The name
of the provider DLL typically is wcpic32.dll.
Once the SNA software is configured, you can proceed with the QMF for
Windows Administrator.
CLI
In order for QMF for Windows to connect to DB2 via CLI, you first use the
DB2 UDB facilities to define your database servers and how to connect to
them; this configuration is outside the control of QMF for Windows. One this
configuration is completed at the DB2 UDB client, in order to create the
connection inside QMF for Windows Administrator you need only to specify
the alias defined for a particular database.
To access a DB2 UDB server using CLI, the 32-bit version of QMF for
Windows must be able to establish a CLI connection from the local host (the
system on which QMF for Windows is running) to the remote host (the system
on which DB2 UDB is running) via the DB2 UDB client.
To connect to DB2 for MVS, DB2 for OS/390 and DB2 UDB for OS/390 using
CLI, you must have DB2 Connect installed locally or as a gateway. Although
this connectivity is possible, for performance reasons we recommend to
connect to those platforms using a DRDA connection to avoid a possible
performance bottleneck at the DB2 Connect gateway. However, if DB2
Connect is already installed in the existing environment and its performance
is sufficient for the amount of users using this gateway, this will allow for a
very easy setup for QMF for Windows.
If there are any problems with your network configuration, QMF for Windows
Administrator displays an error message as shown in Figure 35.
The Copy button allows you to copy the error message on the clipboard to be
then saved for further investigation.
Note:
Turn tracing off when the problem is resolved; tracing can have a
significant adverse impact on the performance of QMF for Windows.
There are very few errors that can occur in QMF for Windows Administrator
when trying to establish a connection to the server. The problem at this point
almost certainly indicates a problem with the network configuration rather
than with the QMF for Windows Administrator. These few errors are:
• Failure to activate the SNA software or to start the SNA node.
• Failure to activate the SNA link.
• Failure to properly configure an LU 6.2 session between the QMF for
Windows LU and the DB2 LU.
Note
When you define multiple server entries within the SDF, accessing the
same database but using different network connection options, be sure
to use different Collection Names for each network option. If you do
NOT do so, only those users accessing the server using the last bound
packages will be able to access the server.
2. Owner ID
To bind those packages, you must have authority at the database server to
run the SQL that they contain. If your primary authorization ID has the
required privileges, you can leave this field blank. If you have a secondary
authorization ID that you usually use for administrative tasks, enter it in
this field.
Figure 37 shows the screen to create the QMF for Windows objects.
When you click Create objects..., QMF for Windows Administrator opens a
connection to the database server to bind the installation package
RAARDBI1. Your authorization ID must have the BINDADD privilege at the
database server in order to bind package RAARDBI1. After the installation
package is bound, QMF for Windows Administrator asks you whether you
want to automatically check which objects need to be created (and which
ones already exist). Click YES at this prompt.
In order to check for the existence of the required objects, the SELECT
authority is required on the following tables, depending on the type of
database server.
DB2 UDB for OS/390, DB2 for OS/390, DB2 for MVS:
SYSIBM.SYSDATABASE
SYSIBM.SYSTABLESPACE
SYSIBM.SYSTABLES
DB2 UDB, DB2 Common Server, DB2 Parallel Edition, DB2 DataJoiner
SYSCAT.TABLESPACES (except DB2 Parallel Edition and DB2 DataJoiner
Version 1)
SYSCAT.TABLES
SYSCAT.INDEXES
SYSCAT.COLUMNS
For the complete list of the QMF tables and views that are created in this
step, see Appendix C, “QMF for Windows tables and views” on page 379.
If all of the objects already exist, a message to this effect will be displayed
and you do not need to do anything further.
If one or more objects need to be created, the Create Objects dialog box
opens, displaying a series of SQL statements (separated by semicolons).
These are the SQL statements that QMF for Windows Administrator needs to
execute to create the required tables. Review this statements carefully for
correct syntax and naming conventions. If you are satisfied with the
statements, click OK to run them at the selected database server.
Hint:
Save the SQL statements by copying the text to the clipboard and save it
to a file for future references.
A return SQL code of -551 or -552 indicates that the authorization ID on the
bind (either your primary user ID or the specified owner ID) does not have all
the privileges required to create database objects at the selected database
server.
Version 6.1 and later of QMF for Windows stores user profile, resource limits,
and authorization ID information in different tables, and uses different views
than previous versions and host QMF.
The new tables and views used to access these tables are created when you
click the Create Objects button on the Packages dialog in QMF for Windows
Administrator. If you look at the SQL that is generated to create these tables
and views you'll notice that:
1. If any of the previous host QMF tables are detected to exist, INSERT
statements will be created to copy all of the data stored in the old tables to
the new tables.
INSERT INTO RDBI.PROFILE_TABLE
SELECT * FROM Q.PROFILES;
So, if you want to use your existing QMF objects, only the above-mentioned
modification during installation has to be done. Once this is set up correctly,
no changes need to be made to the existing objects to make them available
through QMF for Windows.
User profiles
By default, QMF for Windows V6.1 stores and accesses user profile
information in the table named RDBI.PROFILE_TABLE. QMF for Windows
V6.1 always accesses this table through the view named
RDBI.PROFILE_VIEW. If you want to continue using your existing
Q.PROFILES table (host QMF), modify the DDL used to create
RDBI.PROFILE_VIEW and point it to Q.PROFILES as follows:
CREATE VIEW RDBI.PROFILE_VIEW
(
CREATOR,
"CASE",
DECOPT,
CONFIRM,
WIDTH,
LENGTH,
LANGUAGE,
SPACE,
TRACE,
PRINTER,
TRANSLATION,
PFKEYS,
SYNONYMS,
RESOURCE_GROUP,
MODEL,
ENVIRONMENT
) AS SELECT CREATOR, "CASE", DECOPT, CONFIRM,
WIDTH, LENGTH, LANGUAGE, SPACE,
TRACE, PRINTER, TRANSLATION,
Resource groups
By default, QMF for Windows V6.1 stores and accesses resource group
(governing) information in the table named RDBI.RESOURCE_TABLE.
QMF for Windows V6.1 always accesses this table through the view named
RDBI.RESOURCE_VIEW. If you want to continue using your existing
Q.RESOURCE_TABLE table (host QMF), modify the DDL used to create
RDBI.RESOURCE_VIEW and point it to Q.RESOURCE_VIEW (the view
already created on Q.RESOURCE_TABLE) as follows:
CREATE VIEW RDBI.RESOURCE_VIEW
(
RESOURCE_GROUP,
RESOURCE_OPTION,
INTVAL,
FLOATVAL,
CHARVAL
) AS SELECT RESOURCE_GROUP, RESOURCE_OPTION,
INTVAL, FLOATVAL, CHARVAL
FROM Q.RESOURCE_VIEW;
-- FROM RDBI.RESOURCE_TABLE;
Primary/secondary IDs
By default, QMF for Windows V6.1 stores and accesses primary/secondary
authid relationship information in the table named RDBI.AUTHID_TABLE.
QMF for Windows V6.1 always accesses this table through the view named
RDBI.AUTHID_VIEW. If you want to continue using your existing table
Q.RAA_AUTHID_TABLE (older version of the QMF for Windows product),
modify the DDL used to create RDBI.AUTHID_VIEW and point it to
Q.RAA_AUTHID_TABLE as follows:
CREATE VIEW RDBI.AUTHID_VIEW
(
PRIMARY_ID,
SECONDARY_ID
)
AS
SELECT PRIMARY_ID, SECONDARY_ID
FROM Q.RAA_AUTHID_TABLE;
-- FROM RDBI.AUTHID_TABLE;
You use QMF for Windows Administrator to choose the collection name and
bind options (owner id, etc.....) for the packages that it requires and to
automatically bind the packages at the server. In this collection, the following
five packages will be bound: RAARDBI1, RAARDBI2, RAARDBIA,
RAASHUT2, RAASHUT3.
- RAARDBI1 is used only in the server configuration phase to create the
database objects required by QMF for Windows in each connected
database server.
- RAARDBIA is used only by the Administrator module and contains the
SQL required for administrative functions.
- The other three packages: RAARDBI2, RAASHUT2, and RAASHUT3,
are used by the QMF for Windows module.
RDBI.RESERVED SELECT
RDBI.TABLE_VIEW SELECT
RDBI.USER_AUTHID_VIEW SELECT
RDBI.USER_ADMIN_VIEW SELECT
Q.RAA_OBJECT_VIEW SELECT
Note:
Special considerations for existing QMF installations:
The sample tables supplied with each of the QMF family of products are
identical. If they exist already at the specified server, QMF for Windows will
delete and recreate them.
The QMF for Windows installation objects created at that database server are
not deleted by this action; if you want to clean-up the QMF for Windows
objects, you have to explicitly delete them at the server. For a list of the QMF
for Windows installation objects, use Appendix C, “QMF for Windows tables
and views” on page 379.
The governing function of QMF for Windows is always active. If you do not
explicitly set up resource limits, governing based on default limits still happens.
We strongly recommend you define your own sets of limits before you
enable the users to access QMF for Windows.
Using the Administrator module, the DBA can define sets of limits and
restrictions, which are called resource limits groups. The DBA can then
assign users to resource limits groups, according to the governing level that
you want performed for those users.
To prevent users from circumventing limits that you establish, resource limits
groups are securely stored in a database table at the database server.
Specifically, resource limits groups are stored in the table named
RDBI.RESOURCE_TABLE. A view named RDBI.RESOURCE_VIEW is
Users who are not explicitly assigned to a resource limits group are governed
by the limits defined in the default resource limits group. The DBA is
responsible for creating and maintaining the default resource limits group,
which is named <Default>.
Note:
If you want to prevent the access to users not explicitly registered in any
resource limit group, we strongly suggest that you update the <Default>
resource limit group and uncheck all the boxes in the SQL Verbs,
Options, Save Data, Binding, and Object Tracking folders in the Edit
Resource Limits Group Schedule window.
In order to create a new resource limits group, use the following procedure:
1. Select the server you are currently working with in the QMF for Windows
Administrator window and click the Edit... button. The Server Parameters
dialog box opens.
2. Click the Resource Limits... button. The Resource limits groups list
dialog box opens, showing a list of all the resource groups defined at the
server.
3. Select the resource limits group from which you want to model the new
group and click the New... button. The New Resource Limits Group
dialog box opens.
4. Type a name for the group in the Group name field. There are no
restrictions on the name you enter.
5. Type any comments, up to 80 characters in length, that describe the new
resource limits group. Optionally, you can leave this field blank.
6. If the Create this group using schedules from... check box is enabled
(see Figure 40), the group you selected as a model has schedules that
you can copy into the new group. Check this box if you want to create the
new group with copies of all of the schedules contained in the model
group. Otherwise, the new group contains no schedules.
In order to create a new schedule in the resource limits group, use the
following procedure:
1. Select the resource limits group for which you want to create schedules in
the Resource Limits Group List dialog box and click the Edit... button. The
Edit Resource Limits Group dialog box opens.
2. Select a schedule in the Schedule List if you want it to be used as a model
for the new schedule.
3. Click the New... button. The New Resource Limits Group Schedule
dialog box (Main Tab) opens so you can create a new schedule. If you
have selected a schedule in the Schedule List, the selected schedule is
used as a model for the new schedule.
Hint:
If more than one schedule is defined to be in effect at the same time,
the QMF for Windows governor will use the one with the lowest
schedule number.
• Timeouts tab: This is used to specify the limits for this schedule in order
to gain control over the resource consumption for this group. Entries with a
value of “0” mean that no limit will be defined. Figure 42 shows the
Timeout tab of the schedule definition.
- Idle Query Timeouts — Limits the amount of time a query can remain
idle You may set two different timeouts:
• Warning Limit — When this timeout expires, QMF for Windows
reminds the user that the query is idle and prompts the user whether
or not to cancel the query.
• Cancel Limit — When this timeout expires, QMF for Windows
automatically cancels the query.
A query might be idle when the first buffer of data has been returned to
the user, and QMF for Windows is waiting for that user to go to the
bottom of the data before it fetches the next set of data.
Hint:
A lower timeout limit prevents long-running (runaway) queries. A
higher limit allows database requests to complete when the database
server is slow due to resource contention or other reasons.
Hint:
A lower timeout limit helps minimize the resources consumed at
servers by idle connections. A higher timeout limit helps minimize the
overhead of establishing connections.
When this timeout expires, QMF for Windows automatically closes the
idle connection to the database server.
• Limits tab: In this window (shown in Figure 43), you specify other
resource limits, like maximum rows allowed to fetch by this resource limit
group.
It is important to keep in mind the way that QMF for Windows retrieves the
data. For example, if a resource limit group has a defined fetch limit of
10,000 rows, QMF for Windows fetches the first buffer full of data, let’s say
8,000. It then checks and sees that the maximum of 10,000 has not yet
been reached and fetches the next buffer of data. As this second buffer full
of data might again return 8,000 rows, the user will see 16,000 rows, even
if the limit has been defined to be 10,000.
- Maximum Rows To Fetch — Limits the number of rows of data QMF for
Windows retrieves from a database server when running a query.
1. Warning Limit — When this limit is reached, QMF for Windows
prompts the user whether or not it should continue to fetch more
data.
2. Cancel Limit — When this limit is reached, QMF for Windows
automatically cancels the query.
Note:
Turning off the permissions for update, delete, and insert does not affect
the ability to perform these actions using the table editor.
100 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 44. SQL Verbs: parameters
You can allow/disallow the use of the following verbs from QMF for
Windows: ACQUIRE, ALTER, CALL, COMMENT, CREATE, DELETE,
DROP, EXPLAIN, GRANT, INSERT, LABEL, LOCK, REVOKE, SET,
SELECT, SIGNAL, UPDATE.
• Options tab: Using the Options tab allows to control the access to the
database objects for the resource limit group (see Figure 45).
102 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
the 21st row visible, QMF for Windows requests more data. However, if
the user runs the query and then waits a long time before scrolling
down, the query remains active for that entire period of time. This is
undesirable because it consumes resources at the database server the
entire time the query is active.
Hint:
If you enable this parameter, QMF for Windows repeatedly requests
data until it receives all of the data, independent of the user's
scrolling requests.
Note:
If you select this option but do not specify a default table space, the
user cannot specify a table space, and the database server uses a
default.
104 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 46. Save data: parameters
• Bindings tab: In this screen parameters for the bind process are defined.
(See Figure 47 on page 106).
- Allow binding of packages — Enables users to bind static packages for
their queries.
- Allow dropping of packages — Enables users to drop static packages
from the database server.
- Default collection name — Specifies the default collection ID for static
packages bound by users.
106 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
• All (RS) — Specifies that the execution of SQL statements in the
package is isolated (protected) from the actions of concurrent users
for rows the requester reads and changes.
• Cursor Stability (CS) — Specifies that the execution of SQL
statements in the package and the current row to which the
database cursor is positioned are isolated (protected) from the
actions of concurrent users for changes the requester makes.
• Change — Specifies that the execution of SQL statements in the
package is isolated (protected) from the actions of concurrent users
for changes the requester makes.
• No Commit (UR) — Specifies that the execution of SQL statements
in the package is not isolated (protected) from the actions of
concurrent users for changes the requester makes.
- Default isolation level can be overridden — Specifies whether a user is
forced to use the Default isolation level or can specify any isolation
level.
• Object Tracking tab: QMF for Windows 6.1 contains detailed object
tracking abilities that are managed through the QMF for Windows
Administrator. During the installation QMF for Windows creates two tables
for Object Tracking:
- Q.OBJ_ACTIVITY_DTL (the detail table) holds all of the detailed
tracking options determined by the Object Tracking Tab within the
Resource Limits for your particular Resource Group.
- Q.OBJ_ACTIVITY_SUMM (the summary table) holds the summary
information for the objects.
Using this Object Tracking capability allows the database administrator to
perform such tasks as:
- Running detailed history report for all QMF objects.
- Locating unused objects
- Locating frequently accessed data sources (table/columns)
- Spotting potential problem areas.
Figure 48 shows the Object Tracking screen where this function will be
enabled and defined.
108 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
and the results. This option must be enabled if you want to use ad-hoc
object tracking or SQL text tracking.
Note:
If you enable this option, a large amount of data can be inserted into
the Q.OBJ_ACTIVITY_DTL table. See “Object tracking: maintenance”
on page 109 for more information.
When QMF for Windows connects to a database server, the user must provide
user information (user ID and password), which is validated by the database
server. If the user information is valid, QMF for Windows determines which
resource limits group to use by first locating the correct profile for the user; this is
done by searching the CREATOR, ENVIRONMENT, and TRANSLATION
columns in the RDBI.PROFILE_VIEW table.
Note:
If the user ID you want to assign does not have an entry in the
RDBI.PROFILE_VIEW table, click the Create New... button to create the
new user profile.
3. Select the appropriate user IDs and use the Assign and Unassign buttons
to move them to either list.
4. Click OK.
110 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 49 shows the QMF for Windows screen used to make these
definitions.
4.3 Security
QMF for Windows Administrator is the administrative component of QMF for
Windows. Using the Administrator module is strictly an administrator task.
There should not be any need for an end user to run QMF for Windows
Administrator. However, there is no security risk if an end user does run QMF
for Windows Administrator; the existing database and file-sharing security
mechanisms still apply and restrict what a user can or cannot do.
To prevent users from circumventing limits that you establish, resource limits
groups are securely stored in a database table at the database server.
Specifically, resource limits groups are stored in the table named
RDBI.RESOURCE_TABLE. A view named RDBI.RESOURCE_VIEW must
4.3.2 Lists
As mentioned previously, QMF for Windows knows four different types of
objects:
• Queries
• Forms
• Procedures
• Tables
112 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
If a user starts working with predefined queries and so on, they would
typically use the File -> Open from Server menu. This would open a window
that would then need to be modified if this user does not need to see all
objects from all users. Creating a predefined list provides an alternative way
to simplify the work, by using the File -> Open menu to see a list of tailored
objects.
Note:
Using this method does not prevent the user from being able to see all
objects by clicking the Refresh List button in the list window.
For true restriction, the Create View permission for Object View or Table
View should be edited at the creation of a collection. Different collections
can then be used by different user groups using different server definition
files.
Within the List window, several options are available using the icons in the
Toolbar or the right mouse button. These options are:
• Display object to view the selected object. This function is available for
Queries, Forms, Procedures, and Tables.
• Run object to execute the selected object. This is only available for
Queries and Procedures.
• Draw object will create a query based on a selected table. The type of
query may be either a SELECT query, an SQL UPDATE query, an SQL
INSERT query, or a prompted query. This options only works for tables.
• Edit object is available only for tables and will open the Table Editor for
this table.
• Properties again is available for all four types of objects and displays the
properties of the selected object, including comments, attributes, and
historical usage information.
114 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
QMF for Windows, as of this writing, has one problem when working with
Lists:
When logging on to a DB2 on OS/390 with a user with SYSADM
authorization, using Lists will not show the system catalog table and
views. The issue is that all tables with at least one row in
SYSIBM.SYSTABAUTH will show up in lists. If there are no rows in
SYSIBM.SYSTABAUTH (which can be the case for some of the system
tables), it will not show up. The work around is to grant at least one
permission to at least one user on each of the system tables.
All queries created through QMF for Windows use dynamic SQL. If the
database administrator, by using the object tracking capabilities of the
product, identifies certain queries that are executed very frequently, they
might be candidates for a conversion to static SQL. QMF for Windows allows
this conversion to be performed for SQL queries only. If you have any
prompted query that is supposed to be converted to a static query, the
following steps have to be performed first:
1. Open the prompted query.
2. Select Convert to SQL from the Query menu.
3. Save the new SQL query.
Once this is done, select the query and convert it to a static query using the
following steps:
1. Open the SQL query.
2. Select Bind Static Package in the File menu of QMF for Windows.
4. If the original query makes use of substitution variables, select the Input
Variable tab. Here all the substitution variables used have to be translated
to host variables for the static query. Not all of the substitution variables
are easy to map to host variables, as they provide direct text substitution
within the query text before being send to the database server, whereas
host variables are sent to the database server as part of the query.
116 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
5. Valid data types for host variables are:
- CHAR(n)
- VARCHAR(n)
- INTEGER
- SMALLINT
- FLOAT
- DECIMAL(p,s)
- DATE
- TIME
- TIMESTAMP
Figure 53 shows the Input Variable screen.
Note the comment at the bottom of the screen. If you do not save the
query that just has been translated into a static SQL query, it will not be
able to be executed as static SQL later.
With V.6 of DB2 UDB for OS/390, the predictive governing function of the RLF
provides an estimate of the processing cost of SQL statements before they
run. The cost estimate is expressed as a number of CPU milliseconds and
service units (SUs).
118 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Note
Statement cost estimation is supported for both dynamic and static
SELECT, INSERT, UPDATE or DELETE, but predictive governing is only
for dynamic statements.
Each company has its own procedures defined by your installation for adding,
dropping, or modifying entries in the Resource Limit Specification table.
If the database that will be accessed using QMF for WIndows contains tables
that have LOB fields defined, the database administrator might decide either
to prevent access to these tables in general, or to create a view of these
tables, omitting the LOB column.
Procedures are sets of commands that enable the DBA or other users to run
queries, print reports, import and export data, as well as perform other
functions. Like any other QMF object, procedures can be stored at the
database server, or saved in a file locally or on a file server. All commands
issued through procedures are governed by the resource limits you already
configured.
NOTE
In QMF for Windows you cannot create a procedure with logic to run a
series of QMF commands like in the host QMF where the commands are
run based on REXX logic you add to the procedure. QMF for Windows
does not support REXX procedures, but only forms calculations using IBM
Object REXX.
For more information on QMF for Windows Procedures, please see 6.4.4,
“Procedures” on page 196.
120 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
• /IProcFile:procedurefile: The /IProcFile parameter defines the location
and name of a locally stored procedure file to run after starting QMF for
Windows.
• /IUserID:userID: The /IUserID parameter defines the user ID to use when
running a procedure specified with the /IProcName or /IProcFile
parameters. It is used in conjunction with the /IPassword parameter.
• /IPassword:password: The /IPassword parameter defines the password
of the user specified with the /IUserID parameter.
Note: The /IPassword parameter includes the user's password in plain
text.
• /Batch: The /Batch parameter ends the current session of QMF for
Windows and closes the application, after running any procedure specified
on the command line.
• &variablename=variablevalue: The &variablename= parameter defines
or updates global variable values for use in any procedure or query being
run. Any number of variables can be defined.
122 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
2. Schedule with the Windows NT AT command: The Windows NT
operating system has its own scheduling mechanism that is usually
started with the AT command. The AT command schedules commands
and programs to run on a computer at a specified time and date. The
Schedule service must be running to use the AT command. The following
shows the AT command syntax:
AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"
124 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Chapter 5. Developer’s guide
As seen in the prior chapters, QMF for Windows is a tool for building
Enterprise Query Environments. We saw that in an Enterprise Query
Environment, all queries are stored in a query repository, so that the vehicle
for accessing the data and reports is centralized. This results in better
organization, control, and reliability of the data.
But one problem is that most companies have their own applications for
solving special needs such as calculations, marketing, human resources, and
many others. Many of these applications submit queries to the database
server to retrieve some data. Now, using QMF for Windows and storing all
queries in a central repository, the applications no longer need to have their
own SQL statements inside the code. Keeping the SQL text inside the
application would not allow the query execution to be controlled by QMF for
Windows. A better way to do this is to have the application use the queries
stored in the query repository. That way, when the QMF administrator
changes a query, the application is automatically changed and starts to
retrieve the data using the new query.
This chapter shows how an application can access the QMF queries stored at
a central repository and manipulate them. QMF for Windows has a set of
Application Program Interfaces (APIs) that enable the application to execute
the functions necessary to use the Enterprise Query Environment. For a
complete understanding of how application development is done using the
QMF for Windows API, this chapter shows some concepts of application
development using QMF for Windows, and provides examples of programs
using the APIs listed. For a complete API reference, see Appendix B, “QMF
for Windows APIs” on page 293.
Most of the programming languages designed for Windows can access the
APIs very easily. The way this is done differs a lot from one programming
language to another, but all of them have a way of calling the APIs. Once
these APIs are included in the programming language environment, using
them is like using a regular function in the program.
Any programming language that access the Windows API can also access
the QMF APIs. Some examples of programming languages that can access
the Windows APIs are Microsoft Visual Basic, Microsoft Visual C++, Borland
C++, Borland Delphi, IBM Visual Age for Java, and many others.
The same thing happens with the final application that you will distribute to
your users. The only middleware necessary for the application to run is the
middleware for the network and QMF installed within the environment.
126 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
DB2 ORACLE INFORMIX SYBASE MS-SQL ....
Application
Figure 57. Application architecture when using ODBC
ODBC is based on and closely aligned with the Open Group standard SQL
Call Level Interface. It allows programs to use SQL requests that will access
databases without having to know the proprietary interfaces to the databases.
ODBC handles the SQL request and converts it into a request that the
individual database system understands.
As with many other standards, ODBC solves some problems and creates
others. Some problems you may find when using ODBC include performance
issues and error handling. Rather than using ODBC, you might want to
connect directly to the database — QMF for Windows does that. It provides a
direct access from the client desktop to the database server, meaning that
there is no need to install the database client (CLI) or ODBC in order to
access the database.
All of the QMF for Windows API functions are synchronous. This means that
when a API is called in your application, it blocks, or does not return until the
requested action completes. In other words, the code line just below the line
calling the API will not be executed until the API completes its function.
This implementation is desirable because it simplifies programming the
application. However, if your application is single-threaded, it will not be able
to respond to user input or perform screen refreshes while it is waiting for a
QMF for Windows API function to return.
128 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
If it is necessary for the application to be asynchronous, the programmer has
to create a new thread within the application and call the API from the new
thread. This new thread will then be blocked, but all other threads will
continue to execute normally. The programmer has to manage the timing and
execution of the threads. When developing multi-threaded applications, keep
in mind that the QMF for Windows API responds to one function call at a time
from a client. That means you must wait for one function call to complete
before making another, or create multiple instances of the QMF for Windows
API (one for each thread using the API).
Classic Classic
Connect Connect TCP/IP TCP/IP TCP/IP
DB2 Family
DB2
Data Joiner
DB2 OS/390
DB2 NT TCP/IP CLI
DB2 AIX
DB2 AS/400
... QMF for Windows
Figure 58. QMF database access
To connect to multiple database servers serially (one after the other) using
the same QMF for Windows API object, call Commit() or Rollback() and then
InitializeServer(). The Commit() and Rollback() functions close the current
connection to the database server while the InitializeServer() function opens
a new connection. Calling these functions ends the current unit of work, and
subsequent calls start a new unit of work.
Due to the fact that all database activities occur within the same connection,
creating more than one query in a given instance of the QMF for Windows
API object by calling InitializeQuery() two or more times, they will share the
same single connection.
QMF for Windows creates and uses a second connection to the database in
order to handle administrative database activities, for example, retrieving
QMF information. This second connection is necessary to support a
consistent rollback and commit mechanism for client applications. The QMF
for Windows API object automatically handles these connections to the
database. However, if your system administrator has established a limit for
the number of connections allowed, remember that each instance of the QMF
for Windows API object may use two connections.
130 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
One way of allowing the queries to be accessed through the Web is by
developing a Web application, using for example CGI, ASP, Servlet, or one of
many other technologies. To develop such an application, the programmer
can still use the QMF APIs, so that the interface between the application and
QMF is the same as when developing a regular application.
5.2.1 GetServerList()
The first important API is GetServerList(). This API goes to the QMF for
Windows server definition file (SDF) and lists the database servers that QMF
is configured to access. If there is only one database server in the
environment, or if the database server name is already known, it is possible
to directly call the InitializeServer() API.
5.2.2 InitializeServer()
Once you have your database server name, it is necessary to initialize the
connection to that server. That is what the InitializeServer() API does. To
execute this API, it is necessary to pass the following parameters:
• ServerName — This name has to match the same name in the QMF for
Windows SDF.
• UserID — This is the user ID for accessing the database.
• Password — This is the password of that user ID.
• ForceDialog — If the value of this parameter is not zero, then a dialog
prompting the user ID and password will be shown. Otherwise, the dialog
will only be shown if necessary, that is, if there are no values in the UserID
and Password parameters.
• SuppressDialog — If the value of this parameter is not zero, then the
dialog box prompting for the user information will never be shown. This is
especially useful when developing applications for the Web, where the
user ID and password are to be prompted for in a different way.
5.2.4 InitializeQuery()
This API initializes a query for execution. It has two parameters:
• SourceType — There are three types of queries: the ones passed directly
to the API (0), the ones stored on the server (1), and the ones stored into
text files (2).
• Source — If the SourceType is 0, then the Source parameter must have
the SQL statement; if the SourceType is 1, then the Source parameter
must have the owner and the name (Owner.Name) of the query stored in
the server; and if the SourceType is 2, then the Source parameter must
have the file name.
The result of this API is the QueryID, a number that will identify the Query
exclusively. Many other APIs require the QueryID as input parameter.
5.2.5 GetQueryText()
This API returns the SQL statement from a QMF query passed in the input
parameter QueryID. It is very important for applications which have to
manipulate or show the SQL statement. In an Enterprise Query Environment,
all the queries will be stored together and all applications should be able to
retrieve any query at any time.
132 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
5.2.6 GetQueryVerb()
This API returns the verb of the query passed in the input parameter QueryID.
The verb of a query might be SELECT, INSERT, UPDATE, DELETE, CALL,
and others. In some cases it is extremely important that the application knows
what kind of action the query is taking, because queries that return values
may have to be manipulated, and those that only execute a certain action may
not return any value at all.
5.2.7 SaveQMFQuery()
This API allows the application to create new queries or to modify existing
queries on the server.
5.2.8 Open()
This API will execute the query initialized by the InitializeQuery() API. Note
that this API will only execute queries with the SELECT verb. Queries that
use the UPDATE, INSERT, DELETE, CALL and others verbs have to be
executed using the Execute() API.
5.2.9 GetColumnCount()
This API returns the number of columns that the query passed in the input
parameter QueryID has. This value is very useful for handling the return
value of the FetchNextRow() API within loops.
5.2.10 GetColumnHeadings()
This API returns the column names in the Headings parameter as a pointer
for the query specified in the input parameter QueryID. The pointer has to be
handled after the API is executed. The way that pointers are handled
depends a lot depending on the programming language used. This function is
especially useful to display the columns names for the end user or for
manipulating columns values within the application.
5.2.11 FetchNextRow()
This API has to be used after the Open() API. It fetches the next result row of
a query specified in the QueryID input parameter. The result data in the row is
returned in the pointer specified in the second input parameter Row. This
pointer has to be handled after the API executes. The way that pointers are
handled differs a lot, depending on the programming language. If the API
executes successfully, the result value is zero.
When the end of the result set has been reached (there are no more rows to
fetch) the result is empty and the return value of the API is -1.
One important aspect of this API is the data types supported. This types
include string, float, double, short, long, and binary.
5.2.12 Close()
This API closes a query passed in the input parameter QueryID. If there is a
cursor open for the query, the cursor is closed, freeing the database for other
users. This function does not terminate the connection to the database
server. Since the connection remains open, no rollback or commit is
performed.
134 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
5.3 Using Visual Basic with QMF for Windows
Visual Basic is a visual programming language developed by Microsoft that
allows you to easily create Windows applications. This chapter shows the
steps that need to be taken before using QMF for Windows APIs with Visual
Basic, and also shows some examples of programs.
All the APIs are property and methods of the QMFWin object.
Three examples will be used to illustrate the QMF for Windows APIs:
1. Execute a query stored on the server
2. Execute a query stored in a file
3. Execute an SQL statement
Grid.Clear
Grid.Cols = 2
Grid.Rows = 2
End Sub
• DataIntoGrid — Fetches the data from a specified query and displays the
data into a grid. The query has to be open before calling this procedure.
This is done using the FetchNextRow() API. The following example shows
the source code for this procedure.
136 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Public Sub DataIntoGrid(ByRef Grid As MSFlexGrid, QueryNumber As
Integer)
'This procedure fetches all the data in the QMF Query passed
'on the parameter QueryNumber and display the data on the
'grid passed on the parameter Grid
Grid.Row = 1
End If
End If
End If
End Sub
The first thing that this example does is to list all the servers that are
configured in the QMF for Windows SDF and show the servers found in a list
named lstServers. This is done on the event Form_Load as listed below:
Private Sub Form_Load()
Dim myServerList As Variant
Dim myServer As Variant
'try to get the server list and place it on the ServerList variable
lblState = "Getting Server List..."
If QMFWin.GetServerList(myServerList) <> 0 Then
'if not successful, display error message
138 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
lblState = "Could not find server list. " + QMFWin.GetLastErrorString()
lblState.Refresh
MsgBox (lblState.Caption)
Else
'if successful, display the list of server into the lstServers
lblState = "Displaying Server List"
lblState.Refresh
If Not IsEmpty(myServerList) Then
For Each myServer In myServerList
lstServers.AddItem (myServer)
Next
Else
lblState = "No server found."
lblState.Refresh
MsgBox (lblState.Caption)
End If
End If
End Sub
After that, the user has to select the desired server by double-clicking on the
server name. When this happens, it is necessary to initialize the server using
the InitializeServer() API. The API will then prompt the user for a userID and
password. Once the server is initialized, all existing queries are listed using
the GetObjectList() API and displayed in the lstQueries object on the top right
of the screen. The source code of that functionality is listed below:
Private Sub lstServers_DblClick()
Dim myQueryList As Variant
Dim myQuery As Variant
The user now has to select one from the query list by double-clicking on the
desired query. It is then necessary to initialize the query using the
InitializeQuery() API, execute the query using the Open() API, list all rows in
that query on the grid using the procedure DataIntoGrid listed in the
beginning of 5.3, “Using Visual Basic with QMF for Windows” on page 135,
and close the query using the Close() API. Following is the code to do this:
Private Sub lstQueries_DblClick()
140 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
'Shows the SQL statement
txtSQLText.Text = QMFWin.GetQueryText(QueryNumber)
Note:
This example is not able to execute queries that were saved as Prompted
Queries from QMF for Windows (extension *.pq). That is because this kind of
saved query does not contain the SQL statement in its standard format.
There is no way of executing this kind of query using the QMF APIs. In order
to execute them, it is necessary to convert them to SQL statements and save
them as Query Files (*.qry).
142 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
In this example, the following objects were added to a form:
• lstServers — ListBox
• lstDrives — DriveListBox
• lstDir — DirListBox
• lstFiles — FileListBox
• grdResult — MSFlexGrid
• lblState — Label
The first thing that this example does is to list all the servers that are
configured in the QMF for Windows SDF and show them in the list named
lstServers. This is done on the event Form_Load, as listed below:
Private Sub Form_Load()
Dim myServerList As Variant
Dim myServer As Variant
After that, the user has to select the desired server by double-clicking on the
server name. It then is necessary to initialize the server using the
InitializeServer() API. This API will prompt the user for his userID and
password. Once the server is initialized, the driver, directory, and file lists will
be enabled for the user to select the file. The source code of that functionality
is listed below:
If QMFWin.InitializeServer(lstServers.List(lstServers.ListIndex) _
, "", "", True) <> 0 Then
'if not successful display error message
lblState = "Could not initialize server "
lblState = lblState + lstServers.List(lstServers.ListIndex)
lblState = lblState + ". "
lblState = lblState + QMFWin.GetLastErrorString()
lblState.Refresh
MsgBox (lblState.Caption)
Else
'Enables the selection of files after the server is selected
lstDrives.Enabled = True
lstDrives.BackColor = -2147483643
lstDir.Enabled = True
lstDir.BackColor = -2147483643
lstFiles.Enabled = True
lstFiles.BackColor = -2147483643
lblState = ""
lblState.Refresh
End If
End Sub
The user now has to select the text file that contains the SQL statement. In
this example, the user will only be able to see files with the extension *.qry,
which is the extension under which QMF for Windows saves its SQL queries.
The following code must be implemented to link the drive, directory and file
lists, as shown below:
Private Sub lstDrives_Change()
'Changes the path property on the directory list object
lstDir.Path = lstDrives.Drive
End Sub
144 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
lstFiles.Path = lstDir.Path
End Sub
After the user has found the correct directory, he must double-click on the file
name in the list. It is then necessary to initialize the query using the
InitializeQuery() API, execute the query using the Open() API, display the
result on the grid using the procedure DataIntoGrid listed in the beginning of
5.3, “Using Visual Basic with QMF for Windows” on page 135, and close the
query using the Close() API. The code to do that is listed below:
Private Sub lstFiles_DblClick()
146 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 61. Visual basic — execute query stored on a file
After that, the user has to select the desired server by double-clicking on the
server name. It then is necessary to initialize the server using the
InitializeServer() API. The API will then prompt the user for his userID and
password. Once the server is correctly initialized, the SQL text box will be
enabled for the user to enter the SQL statement. The source code of that
functionality is listed below:
148 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
'try to initialize the server selected on the lstServer
lblState = "Initializing Server..."
lblState.Refresh
If QMFWin.InitializeServer(lstServers.List(lstServers.ListIndex) _
, "", "", True) <> 0 Then
'if not successful display error message
lblState = "Could not initialize server "
lblState = lblState + lstServers.List(lstServers.ListIndex)
lblState = lblState + ". "
lblState = lblState + QMFWin.GetLastErrorString()
lblState.Refresh
MsgBox (lblState.Caption)
Else
btClear.Enabled = True
btExecute.Enabled = True
btSave.Enabled = True
txtSQLStatement.Enabled = True
txtSQLStatement.BackColor = -2147483643
txtSQLStatement.SetFocus
lblState = "Server"
lblState.Refresh
End If
End Sub
Now, the user has to type the SQL statement. In this example, the statement
will be "SELECT * FROM EMPLOYEE" where Employee is an example of a
table that QMF creates when it is installed. After that the user can execute the
SQL by clicking on the Execute button, or clear the entry by clicking on the
Clear button. In case the user clicks on the Clear button, the following code
must be implemented.
Private Sub btClear_Click()
txtSQLStatement.SetFocus
End Sub
150 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
lblState = "Closing the Query..."
lblState.Refresh
If QMFWin.Close(QueryNumber) <> 0 Then
lblState = "Could not close query." _
+ QMFWin.GetLastErrorString()
lblState.Refresh
MsgBox (lblState.Caption)
Else
lblState = ""
lblState.Refresh
End If
End If
End If
End If
End Sub
Another important functionality of this example is the option to save the query
on the server. That is done using the SaveQMFQuery() API. When the user
clicks on the Save button, the application will be prompted for the query
owner, name, and comments of the query (if any). If the query is saved
successfully, a message will be displayed; otherwise, the error message will
appear. The code that does this is listed below:
Private Sub btSave_Click()
Dim Owner As String
Dim Name As String
Dim Comment As String
There is also a possibility to export the data retrieved from the query into
files. This can be done using the API Export(). This API can export the data to
text files, HTML files and IXS files. In this example, when the user clicks on
the export button, the user is prompted to enter the file name and all the data
retrieved from the typed query is saved into that file using the HTML format.
The function that does this is listed below:
Private Sub btExport_Click()
152 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
lblState = lblState + QMFWin.GetLastErrorString()
lblState.Refresh
MsgBox (lblState.Caption)
Else
lblState = "Displaing Result..."
lblState.Refresh
154 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 63. Delphi configuration
2. Add a reference to the QMF for Windows file qmfwin.tlb if the QMF for
Windows 6.1 Type Library is not found on the list.
3. A new Unit named QMFWinLibrary_TLB will be added to the project. Add
this unit in the "uses" statement in the desired form. A file called
QMFWinLibrary_TLB.pas will be created on the default Imports Delphi
directory (ex. C:\Program Files\Borland\Delphi4\Imports). There is no
need to create this file every time; this file can be added directly to your
project.
4. On the form, go to the private or public declaration and add an object of
the QMFWin type, as shown in the example below:
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, QMFWinLibrary_TLB;
public
QMF: QMFWin;
end;
5. Before using the QMF for Windows object it is necessary to initialize it,
which can be done in any appropriate event of the application. In the
example below, the initialization is in the Form.Create event.
procedure TForm1.FormCreate(Sender: TObject);
begin
QMF:= CoQMFWin.Create;
end;
After that, the QMF for Windows APIs are ready to be used. All the APIs are
property and methods of that object.
The functionality of this example allows the user to create, edit, delete, and
execute queries either on the server or in the file. To do that, the user first has
to select a server by double-clicking on it. A window prompting the user for a
userID and password will appear. After that, the list of queries stored on that
server will be displayed, as shown in Figure 64.
156 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 64. Delphi example, query list
Once the connection to the server has been established, the user can
perform several actions with the listed queries.
The first thing the user can do is to open an existing query that is stored in a
file. That can be done by clicking on the Open from File button. The user will
be prompted to select a file and, once the file is selected, the query is
executed automatically.
The next thing the user can do is to create a new query. When the New
button is clicked, the window shown in Figure 65 will appear. The user has to
type in the owner of the query, its name, and the SQL statement. After that,
there are two possibilities: save the query on the server, or save the query as
a file. When saving it on the server, if the owner and name already exist, the
new version will try to overwrite the old one, but this will not work if the older
version is a prompted query. It will only work if the older query is of the SQL
statement type.
The user can also edit on existing query. In order to do that, the user has to
select an existing query by clicking one time over the query name on the list
and clicking on the Edit button. The same window (shown in Figure 65) will
appear, but with the information of the selected query. The user can now
modify the SQL statement and save it on the server to overwrite the existing
query, or he can modify the owner and name and save it as a new query.
There is also the possibility to delete existing queries. That can be done by
selecting a query on the list and clicking on the Delete button. Be aware that
no confirmation will be prompted before deleting the query.
The last thing the user can do is to execute a query. The user has to select a
query from the list and click on the Execute button. The same thing happens
if the user double-clicks the desired query within the list. Figure 66 shows the
final result after a query is executed.
158 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 66. Delphi example, executing query
As you can see, this simple application has only two forms. The first one is
called frmMain (Unit1), and the other is called frmQuery (Unit2). Below is the
source code of the form frmMain (Unit1), including the uses clauses and the
class definition. Pay close attention to the QMFWinLabrary_TLB on the uses
clauses. Without that, the Unit will not be able to use the QMF APIs.
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, QMFWinLibrary_TLB, Grids, ExtCtrls, ComCtrls;
The uses clauses here identify that this form will be using the frmQuery.
uses Unit2;
The procedure ClearGrid is used all over the application. It only clears the
StringGrid passed in the input parameter Grid and resets its number of
columns and rows.
procedure TfrmMain.ClearGrid(Grid: TStringGrid);
//Clear everything on the grid and
//sets rowcount and colcount to 2
var
Col, Row: Integer;
begin
for Col:= 0 to (Grid.ColCount - 1) do
for Row:= 1 to (Grid.RowCount - 1) do
Grid.Cells[Col,Row]:= '';
Grid.RowCount:= 2;
Grid.ColCount:= 2;
Grid.FixedRows:= 1;
end;
160 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
This procedure is a generic procedure that receives a string identifying a
query (that has to be already open) as input parameter, and places all the
data retrieved by that query into the StringGrid passed on the parameter Grid.
This function was separated from the rest of the code because it may be
useful in other applications that use the QMF for Windows APIs.
procedure TfrmMain.DataIntoGrid(Grid: TStringGrid; QueryNumber: Integer);
//This procedure fetches all the data in the QMF Query passed
//on the parameter QueryNumber and display the data on the
//grid passed on the parameter Grid
var
ColumnHeadings: OleVariant;
Col, Row: Integer;
myColumnCount: Integer;
myRow: OleVariant;
FetchResult: Integer;
begin
//Clears the Grid
ClearGrid(Grid);
//try to get the number of columns of the selected query
myColumnCount:= QMF.GetColumnCount(QueryNumber);
if myColumnCount <= 0 then
ShowMessage ('Could not count numbers for columns. '
+ QMF.GetLastErrorString())
else
//if successful set the grdResult with the
//appropriate numbers of columns
begin
Grid.ColCount:= myColumnCount;
//try to get the column headers
if QMF.GetColumnHeadings(QueryNumber, ColumnHeadings) <> 0 then
ShowMessage ('Could not get columns headings. '
+ QMF.GetLastErrorString())
else
//if successful display the column headings on the grdResult
begin
for Col:= 0 to (Grid.ColCount - 1) do
Grid.Cells[Col,0]:= ColumnHeadings[Col];
//try to fetch all the rows from the query
//and place the data in the grid
Row:= 0;
FetchResult:= QMF.FetchNextRow(QueryNumber, myRow);
while FetchResult = 0 do
begin
Row:= Row + 1;
for Col:= 0 to (Grid.ColCount - 1) do
Grid.Cells[Col,Row]:= myRow[Col];
The procedure RefreshQueryList lists all the queries that are on the current
server (the server in which the QMF object is currently connected to) and
displays these queries in the lstQueries object. This is done using the
GetQMFObjectList() API. The procedure was separated from the rest of the
code because it is called several times from different parts of the program.
procedure TfrmMain.RefreshQueryList;
//List all available query in the connected server
var
myQueryList: OleVariant;
i: Integer;
begin
//try to list all queries
//(2048 parameter) in that server
StatusBar.SimpleText:= 'Getting Existing Queries...';
StatusBar.Refresh;
if QMF.GetQMFObjectList('%', '%', 2048, myQueryList) <> 0 then
//if not successful display error message
begin
StatusBar.SimpleText:= 'Could not list queries. '
+ QMF.GetLastErrorString();
StatusBar.Refresh;
ShowMessage (StatusBar.SimpleText);
end
else
//if successful, display all the queries into lstQueries
begin
StatusBar.SimpleText:= 'Displaying Query List...';
StatusBar.Refresh;
162 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
lstQueries.Clear;
//in case there is no query to be listed
//an exception occurs
try
for i:= VarArrayLowBound(myQueryList,1)
to VarArrayHighBound(myQueryList,1) do
lstQueries.Items.Add(myQueryList[i]);
StatusBar.SimpleText:=);
StatusBar.Refresh;
except
end;
ClearGrid(grdResult);
end;
end;
This procedure is executed once the OnCreate event of the frmMain form is
triggered. It list all servers available in the QMF SDF and displays the servers
in the lstServers object. The API used to do that is GetServerList().
procedure TfrmMain.FormCreate(Sender: TObject);
var
ServerList: OleVariant;
i: integer;
begin
//Clear Grid
ClearGrid(grdResult);
//create the QMF Object
QMF:= CoQMFWin.Create;
StatusBar.SimpleText:= 'Listing Servers....';
StatusBar.Refresh;
//try to list all servers that are configured on
//QMF for Windows
if QMF.GetServerList(ServerList) <> 0 then
//if fails show error message
begin
StatusBar.SimpleText:= 'Could not list servers.';
StatusBar.Refresh;
ShowMessage(StatusBar.SimpleText);
end
else
//if successful then display all servers in the
//lstServers object
try
for i:= VarArrayLowBound(ServerList,1) to
VarArrayHighBound(ServerList,1) do
lstServers.Items.Add(ServerList[i]);
StatusBar.SimpleText:= '';
This procedure is executed when the DblClick event of the lstServers object
is triggered. When the user double-clicks on a specific server name, the
application connects to the selected server. That is done using the
InitializeServer() API. After that the procedure lists all available queries on
the server and then displays them in the lstQueries object by calling the
RefreshQueryList procedure listed in the beginning of this chapter.
procedure TfrmMain.lstServersDblClick(Sender: TObject);
begin
lstQueries.Clear;
ClearGrid(grdResult);
//if there is any server selected
if lstServers.ItemIndex <> -1 then
begin
StatusBar.SimpleText:= 'Initializing Server....';
StatusBar.Refresh;
//try to initialize the server
if
QMF.InitializeServer(lstServers.Items.Strings[lstServers.ItemIndex]
,'','', True,'',null) <> 0 then
//if not successful show error message
begin
StatusBar.SimpleText:= 'Could not initialize server '
+
lstServers.Items.Strings[lstServers.ItemIndex]
+ '. '
+ QMF.GetLastErrorString();
StatusBar.Refresh;
ShowMessage (StatusBar.SimpleText);
btOpenFromFile.Enabled:= False;
btNewQuery.Enabled:= False;
btEditQuery.Enabled:= False;
btDeleteQuery.Enabled:= False;
btExecuteQuery.Enabled:= False;
end
else
//if successful, refresh the query list
//and enable buttons
begin
RefreshQueryList;
btOpenFromFile.Enabled:= True;
btNewQuery.Enabled:= True;
164 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
btEditQuery.Enabled:= True;
btDeleteQuery.Enabled:= True;
btExecuteQuery.Enabled:= True;
end;
end;
end;
The following procedure is executed when the OnClik event of the button
btNewQuery is triggered. It clears all fields and opens the frmQuery form.
procedure TfrmMain.btNewQueryClick(Sender: TObject);
//Shows the form frmQuery and clear
//all it's fields
begin
frmQuery.txtOwner.Text:= '';
frmQuery.txtName.Text:= '';
166 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
frmQuery.txtSQLStatement.Lines.Clear;
frmQuery.Show;
end;
The next procedure is executed when the OnClik event of the button
btEditQuery is triggered. It first checks the type of the query to be edited. If
the query is of the prompted query type, it cannot be edited. This type of
query can only be edited using the QMF interface. If the query is of the type
plain SQL, the frmQuery form will be displayed showing the query’s
informations. To retrieve the query type the GetQMFObjectInfo() API is used.
To get the SQL statement from a query the GetQueryText() API is used.
procedure TfrmMain.btEditQueryClick(Sender: TObject);
//Open the form frmQuery with and display
//the selected query information on it
var
DotPossition: integer;
QueryName: String;
QueryInfo: OleVariant;
begin
//if there is any query selected
if lstQueries.ItemIndex <> -1 then
begin
//copy the name of the selected query
//using the format owner.name
QueryName:= lstQueries.Items.Strings[lstQueries.ItemIndex];
StatusBar.SimpleText:= 'Getting query type...';
StatusBar.Refresh;
//get the query type, PROMPTED or SQL
if QMF.GetQMFObjectInfo(QueryName,3,2,QueryInfo) <> 0 then
//if not successful show error message
begin
StatusBar.SimpleText:= 'Could not get query type. '
+ QMF.GetLastErrorString();
StatusBar.Refresh;
ShowMessage (StatusBar.SimpleText);
end
else
//if successful verify the query type
begin
if QueryInfo = 'PROMPTED' then
//if the query is a prompted query it can not be edit
begin
StatusBar.SimpleText:= 'This query is a prompted query and '
+ 'can not be edit here.';
StatusBar.Refresh;
ShowMessage (StatusBar.SimpleText);
The following procedure will be executed when the OnClik event of the button
btDeleteQuery is triggered. It simply deletes the selected query, which is
done using the DeleteQMFObject() API.
procedure TfrmMain.btDeleteQueryClick(Sender: TObject);
//delete the selected query from the server
var
QueryName: String;
begin
//if there is any query selected
if lstQueries.ItemIndex <> -1 then
begin
//copy the owner.name of the selected query
QueryName:= lstQueries.Items.Strings[lstQueries.ItemIndex];
//try to delete the query
if QMF.DeleteQMFObject(QueryName) <> 0 then
//if not successful show error message
begin
StatusBar.SimpleText:= 'Could not delete query ' + QueryName;
StatusBar.Refresh;
ShowMessage (StatusBar.SimpleText);
end
else
//if successful refresh the query list
begin
ShowMessage('Query Deleted.');
168 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
RefreshQueryList;
end;
end;
end;
The next procedure is executed when the OnClik event of the button
btExecuteQuery is triggered. It executes the selected query using the Open()
API and displays the result on the grid using the DataIntoGrid procedure that
is listed in the beginning of this chapter.
procedure TfrmMain.btExecuteQueryClick(Sender: TObject);
//execute the selected query and display
//the retrieved data in the grid
begin
//if there is any query selected
if lstQueries.ItemIndex <> -1 then
begin
ClearGrid(grdResult);
StatusBar.SimpleText:= 'Initializing Query...';
StatusBar.Refresh;
//try to initialize the query selected by the user
QueryNumber:= QMF.InitializeQuery(1,
lstQueries.Items.Strings[lstQueries.ItemIndex]);
if QueryNumber < 0 then
//if not successful display error message
begin
StatusBar.SimpleText:= 'Could not initialize query '
+
lstQueries.Items.Strings[lstQueries.ItemIndex]
+ '. '
+ QMF.GetLastErrorString();
StatusBar.Refresh;
ShowMessage (StatusBar.SimpleText);
end
else
//if successful try to open the selected query
//without any limits of number of rows
begin
StatusBar.SimpleText:= 'Executing Query...';
StatusBar.Refresh;
if QMF.Open(QueryNumber, 0, False) <> 0 then
//if not successful display error message
begin
StatusBar.SimpleText:= 'Could not open the query '
+ lstQueries.Items.Strings
[lstQueries.ItemIndex]
+ '. '
The source code from the frmQuery is listed below, including the uses clause,
and the class definition. This unit does not need the include of the
QMFWinLibrary_TLB because no QMF object is created in this unit. The APIs
are used accessing the QMF object created on the frmMain form.
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
170 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
StdCtrls;
The code listed below shows the class definition for the form frmQuery.
type
TfrmQuery = class(TForm)
SaveDialog: TSaveDialog;
txtSQLStatement: TMemo;
btSaveOnServer: TButton;
btSaveOnFile: TButton;
lblOwner: TLabel;
lblName: TLabel;
txtOwner: TEdit;
txtName: TEdit;
procedure btSaveOnServerClick(Sender: TObject);
procedure btSaveOnFileClick(Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
Note that this form uses some resources from the form frmMain. That
requires the uses of the Unit1.
uses Unit1;
The next procedure is executed when the OnClik event of the button
btSaveOnServer is triggered. When that occurs, the procedure will save the
query on the server. A problem may rise when the owner and name already
exist. QMF has different types of queries, a prompted query and an SQL
query. If the owner and name of the query being saved exists and the existing
query is a prompted query, an error will occur. Otherwise, if the existing object
is of the type SQL query, then the existing query will be replaced. This is done
using the SaveQMFQuery() API.
If the owner and name already exists, the query will be replaced.
procedure TfrmQuery.btSaveOnServerClick(Sender: TObject);
//save the query on the server
begin
//if there is a owner and a name
if (txtOwner.Text <> '') and (txtName.Text <> '') then
begin
//try to save the query on the server with replace option
if frmMain.QMF.SaveQMFQuery(txtOwner.Text + '.' + txtName.Text
,txtSQLStatement.Text
,'',True,True) <> 0 then
172 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
5.5.1 Getting started
If you are using Microsoft Visual C++ and MFC, create a wrapper class for the
QMF for Windows API object from the QMF for Windows type library,
qmfwin.tlb. Then use the CreateDispatch() function:
COleException e;
IQMFWin QMFWin;
QMFWin.CreateDispatch("QMFWin.Interface", &e);
You must properly initialize the Variant variable before calling functions that
return data into this variable. Visual Basic and Delphi do this automatically,
but Visual C++ programmers must call VariantInit().
Many DBMSs have a two phase commit protocol that makes this process
independent from the application, meaning that the application sees the two
phase commit as a regular commit and the DBMS makes sure that the
transaction is done correctly. However, to use that protocol, it is necessary to
have a connection to all databases involved on the transaction opened at the
same time.
The first would be to use the DB2 DataJoiner and link all DBMSs on this
process to it. The application would then connect to the a single database
and the DB2 DataJoiner would communicate to the several DBMS using the
two phase commit protocol and the transaction would be completed.
The second option for implementing two phase commit would be controlling
the two phase commit inside your application. It is possible to create two
different QMF instances in your application and connect each instance to a
different DBMS. However, these two instances are not able to communicate
to each other without implementing some additional code in the application.
For example, it is possible to have an application that copies a query from
one server to another. The following code listed below shows how it can be
done.
var
QMF1: QMFWin;
QMF2: QMFWin;
QueryNumber: Integer;
Comment: OleVariant;
begin
QMF1:= CoQMFWin.Create;
QMF2:= CoQMFWin.Create;
if (QMF1.InitializeServer('DB2NT','XXXX','XXXX',False,'',false) = 0)
and (if QMF2.InitializeServer('DB2AIX','YYYY','YYYY',False,'',false) = 0)
then
if QMF1.GetQMFObjectInfo('IMRES2.TEST2',0,2,Comment) = 0 then
QMF2.SaveQMFQuery('db2inst1.test2'
,QMF1.GetQMFQueryText('IMRES2.TEST2')
,Comment
,True
,True);
end;
To implement the two phase commit inside your application a very good
knowledge of the two phase commit process as well as the DBMSs involved
is necessary.
174 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
5.6.2 Editing prompted queries
There are two ways of storing a query: the first way is to store the query on
the server, while the second way is to store the query in a file.
QMF for Windows allows users to work with prompted queries. This type of
query is very different from the SQL queries, and they are stored using a
different structure. Hence, the way to manipulate this type of query in your
application is also different.
If the prompted query is stored on the server, the QMF APIs will manage the
difference between the prompted query and the SQL query, so that for the
application they look exactly the same. That means that your application can
execute, delete, and view all properties from a prompted query just as from
an SQL query. However, it is not possible to edit or change a prompted query.
That can only be done using the QMF for Windows user interface. Using the
QMF for Windows environment, the prompted query can be converted to an
SQL query, and the application can then modify this query.
When prompted queries are stored in files, the QMF API will not be able to
work with them. In order for the application to access these queries, they
have to be converted to SQL queries from within the QMF for Windows
environment.
This chapter is dedicated to the end user who needs to become familiar with
the QMF for Windows product. It explains how to install, configure, and use
most of the QMF for Windows functions.
If using the product CD-ROM for installation, inserting it into the systems
drive will automatically start the installation process. Using a network drive
will require you to start the installation by double-clicking the SETUP.EXE file.
The installation itself is done just as with any other Windows product. In the
beginning you will be able to choose the kind of installation you want, as
shown in Figure 67.
In the same window it is also possible to change the default directory for the
installation by clicking on the Browse... button, and the next window will give
you the opportunity to change the installation directory.
178 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
After successful installation, it is necessary to configure QMF for Windows to
be able to access the database servers. The server definition file (SDF)
contains all of the technical information needed by QMF for Windows to
access the database servers.
For QMF for Windows, the term database server is used differently than the
term used by database administrators. If one DBMS controls multiple
databases (or subsystems), each of these is called a database server when
using QMF for Windows.
There are many functions in QMF that must have an active connection to a
database server. Every time a connection to a server is required, a dialog as
shown in Figure 69 will appear. It is important to remember which server you
are currently connected to.
QMF does not restrict the number of database servers you can have access
to. Please refer to Chapter 3, “Getting started” on page 25 for more
information on how to configure a connection to a database server, as this
typically is not an end user task, but should be provided by the database
administrator.
There are two ways you can use server definition files:
• Each user can be allowed to have his or her own SDF
• A single SDF can be shared by multiple users over a file-sharing network.
Having a local SDF on the end user system requires the user to either create
the file himself, which is not recommended, or has to download the
pre-configured file from a shared network drive and copy it to the appropriate
directory in the local system.
If you are using your own local file, you have to use the QMF for Windows
Administrator to configure the SDF file (for more information on how to
configure the access to the servers, see 3.8, “Installing QMF for Windows” on
page 65). If the server definition file is already defined, you only have to
configure the local QMF to use that file. From the main window in QMF for
Windows, specify the SDF using the Options... item from the View menu to
open the window shown in Figure 70.
To change the path to the SDF, type the file path and name in the entry field
or click on the button on the right of the field to select it. No other
modifications have to be done in that window.
180 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
6.2 Basic concepts
QMF has four types of objects:
• Queries
• Forms
• Procedures
• Tables
A single DBMS can control one or more databases, meaning that you can
have one DBMS installed in a computer and have several databases in it.
Figure 71 shows the structure of it. For example, a company may have
different databases for each department using the same DBMS. For QMF for
Windows, each database is called a database server.
Sales Production
Marketing Line
Human Data
Engineering Warehouse
Resources
Inside each database you have data, and that data is organized inside tables.
Each group of data is in a separate table, as shown in Figure 72. For
example, customer data will be in one table, while product data will be in
another table.
One table stores the data of all members of the group, or, to stay with the
example, all customer data has to be in the same table. Each customer data
entry will be a row in this table.
Sales Database
Supplier P roduct
T able T able
After you create a query and receive the result, you may want to modify the
result format. In QMF, forms provide a way of specifying different views to the
data retrieved by a query. Formatting, such as where each column will be
displayed, the width of each column, breaks, groups, and summaries, may be
specified. The result of a query, combined with a form, is a report.
182 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
The most important concept to keep in mind is that these objects are linked
together. A query is always linked to a table, and a form is always linked to a
query, as shown in Figure 73.
R eport
F orm
R esult
Q uery
Table
2. To select the object directly, select a database server, type in the owner,
and the name of the object, and click on the OK button.
3. To select the object from a list click on the List Objects... button. The list
of objects looks like the on in Figure 75.
184 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 75. List of objects
4. In that list, you may wish to adjust the filter of the objects you want to see.
The first filter is the owner. Type the owner, and only objects from that
owner will appear. The second one is the object name. In both cases it is
possible to use the character ’%’ as a wildcard. The last filter is the object
type. Select the object type you want to see displayed in the list by clicking
on the type name.
5. After any modification in the filters you have to click on the Refresh List
button or the List and the Refresh List menus for the filter to take effect.
6. Find the object you want to access in the list and just double-click in it or
use the List and Display menus and the object will be displayed.
Note:
There is no way of seeing if a query is an SQL query or a prompted query
in the list directly. However, when you access a query, QMF will
automatically identify the sub-type of the query and display the correct
window for you. To see the sub-type of the query, click on the query with
the right mouse button and go to Properties, or use the List and
Property menus.
186 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 76. Open object from file
QMF will automatically open the file and display the object.
Like every new SQL query you create, when you try to close the window,
QMF will prompt if you want to save the query or not.
6.4.2 Queries
As said before, there are two types of queries, the SQL query and the
prompted query. Depending on the type, the window that will be displayed
when you open the query will be different. However, the functionality and the
possible actions for the query may be the same.
188 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 77. Query result
View SQL allows you to view the SQL statement that was issued to the
DBMS. If you are working with prompted queries, you can see the SQL
generated, but you cannot change it.
Finally the View Results brings back the grid with the result of the query. This
option will only be available after the query has been executed at least once.
There is a great difference between run a query and view the result. When
you run a query, QMF will send the SQL statement to the DBMS, it will
process the SQL statement and send back the data. Depending on the query,
that process can take several minutes and consume a lot of resources at the
database server as well as generating traffic on the network. When you run a
query for the first time, QMF submits the SQL statement to the DBMS and
stores the result locally. If you use View Results, QMF will display the last
retrieved data that is stored locally in your computer without using the
network or the DBMS. Hence it is faster and the resources are free for others
users.
6.4.2.4 Find
On the result grid window, it is possible to find a particular value in the grid. To
do this, select to result window and click on the Find button or use the Edit
and Find menu. A window as shown in Figure 78 will appear. Type in the text
you want to find and click on the Find Next button.
190 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 78. Find
Be aware that this sort is not permanent. If you run the query again, the result
may not be sorted by the column you selected. To sort the result permanently
by one column, change the SQL statement using the ORDER BY clause in
the SQL query or the Sort Condition in the prompted query.
If you have the required permission and the query allows you to edit data, on
the result grid, double-click on the cell you want to change, type in the new
value and press the Enter key. A warning message will be displayed to ensure
that you really want to change that data. To continue with the change click on
the OK button or, to cancel, click on the Cancel button. If you decide to
change the data, a message will be displayed regarding the successful
operation.
6.4.2.7 Print
At any time you can print the query or its result by clicking on the Print button
or using the File and Print menus.
6.4.2.8 Export
After you have executed a query, it is possible to export the data to files using
different formats. To do so, go to the File and Export Data... menu. The
window shown in Figure 79 will appear. Be aware that this option is only
enabled when the query has already been run successfully at least once.
In this window you have to type in the file name and select the file type.
Available file types are:
• Text/DEL File (*.txt), which is a delimited ASCII file
• HTML File (*.html)
• IXF FIle (*.ixf), which is the Independent Exchange Format used by
DB2 UDB
• CSV File (*.csv)
You can also define some other options by clicking on the Option... button
where you can specify if all of the data or just the selected data is to be
exported, and also define if the column headers are to be exported together
with the data. After everything is defined, click on the Save button and the
data will be exported.
192 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 79. Export data
In this window you can specify the HTML tags you want before and after each
part of the form. If you do not know the HTML tags, you can use the default
tags by clicking on the button Reset... and select the Products Default. For a
better formatting, complete the default by typing the <PRE> tag in the end of
the Page Heading Suffix and type the </PRE> tag in the Page Footing Prefix.
That way the form is going to be displayed in the browser exactly like in QMF.
Do not forget to select the Save as user default before clicking on the OK
button. That will save the changes you made on the HTML tags.
194 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
After that, a new form will be created with some HTML tags in it, as shown in
Figure 81. At this point, it still possible to use all the functions for a normal
form, such as saving it at a server or checking for errors.
However, a new function is available for this new form, which is to preview the
result in the default Web browser configured for the local system. To do this,
you have to click on the Web Browser button or use the Form and View in
Web Browser menus. Your default Web browser will be automatically
launched, and the form will be displayed in it, as shown in Figure 82.
6.4.4 Procedures
Procedures allow you to do the following operations.
6.4.4.1 Run
To run a procedure, simply click on the Run Procedure button, use the
Procedure and Run menus or use the shortcut Ctrl + R. The execution of the
procedure will begin immediately.
196 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
6.4.4.2 Find
You can find any text string inside the procedure by using the Find button or
the Edit and Find menus. A window will appear for you to enter the text string
to be found. Then click on the Find Next button.
6.4.4.3 Print
It is always possible to print the procedure by clicking on the Print button or
using the File and Print menus.
Although each type of object has its specific characteristics, all have some
things in common. They can all be stored either on a server or in a file, and
they are all visible in the Object List. However, the most important aspect they
have in common is a database server. Whenever you create a new object, a
database server is associated with that object.
198 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
b. After the query has been executed, go to the File and Save Data...
menus. A window as shown in Figure 84 will be displayed. Type the
name and the comments for the new table. In case the table already
exists, it will not be replaced. If the data you are trying to save does not
have the same layout as the existing table, an error will occur.
Otherwise, two actions can be taken: The first possibility is to replace
the existing table with the new table, and the second possibility is to
replace the existing data with the new data. That option can be
selected in the bottom of the windows shown in Figure 84.
200 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 86. New query window
3. If the server shown is not the server you want to access, click on the
Query menu and select the Set Server... menu to switch to the desired
server.
4. In the SQL Query window, type the SQL statement.
5. Before saving the query you can execute it to test your SQL statement and
to check if it the result is exactly what you want. You can run the query
using the Run Query button, using the Query and Run menus, or using
the short cut Ctrl + R. To go back and change the SQL statement, you
have to click on the View SQL button. Repeat this process until the query
returns the desired result.
6. As a last step, when the query is correct, you may wish to save it if it will
be used repetitively. There are two possibilities for saving the query. You
can save it on a server or in a file. To save it on a server you can use the
File and Save at Server... menus or just click on the Save at Server
button and the window shown in Figure 87 will be displayed. In that
window, you have to enter the owner, query name, comment, select the
appropriate checkbox if the query is to be shared with other users and
click on the OK button. To save the query in a file, it is necessary to click
on the Save button, or use the File and Save or Save As... menus.
There is also another way of creating SQL queries. In the list of objects,
select a table. Some additional options in the toolbar and menu will become
available. The options are Draw Select, Draw Insert and Draw Update.
When using one of these options a new SQL query will be created with an
SQL statement predefined to use the selected table. Some modifications in
these SQL statements may be necessary.
One powerful feature of QMF is that it allows you to create queries using
variables. That means that whenever you execute a query QMF will prompt
you to input the values for these variables and execute the query with the
values you entered. To do this, use the ’&’ character as a prefix to a string in
the query and it will become a variable. For example:
SELECT *
FROM OWNER.TABLE
WHERE COLUMN = &VAR
In this case, the &VAR is called a substitution variable. Whenever this query
is executed, a window such as shown in Figure 88 will prompt for the value of
that variable. Be aware that whatever text you type in that window will be
copied into the query. So, if you are comparing the value with a column of the
string data type, you also have to include quotations marks.
202 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
For more information on variables, please refer to Appendix A, “Working with
variables” on page 277.
2. Pay attention to the title of this window as it indicates the database server
accessed by that query and the query name. If the server is not the one
you wish, go to Query menu and select Set Server... to change it.
3. This window is divided into several sections. The first one you have to fill
out is the table section, which is in the top left corner. Within this section
you need to select the tables being using in the new query. To do this,
click on the Add Table button. A dialog will be displayed to either enter the
table owner and name or click on the Add From List... button to select it
from a list, as shown in Figure 90. To add a table from the list, double-click
on the table name, or select the table and click the Add button.
204 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 90. Select tables to a new prompted query,
4. If you select more than one table, another window will be displayed for you
to enter the join condition to select those columns used to link the tables to
each other. This window is shown in Figure 91. This join condition is
displayed in the second section on the top right of the window. There is
always the possibility to change, add, or delete join conditions at any time
by using the button at the top of this section. QMF for Windows
remembers the most recently used join condition for any set of tables to
save time in the creation of future join conditions using the same set of
tables. The selection of the join conditions is extremely important for the
result of the query. Therefore, you have to know the structure of the tables
inside your database. Be aware that the join condition must be accurate;
otherwise, the result of the query may not be what you expected.
5. After the tables are selected and the join condition is set, the next section
to fill out is the Column section. There, you have to select which columns
will be retrieved and in which order. There is also the possibility to do
some calculations on the columns. To do this, it is necessary to click on
the Add Column button, and a window similar to the one in Figure 92 will
be displayed. You can select the column by double-clicking on the column
name, or selecting it and then clicking on the Add button. In this window, it
is also possible to add an SQL expression for a new column, like adding
two columns (as shown in Figure 92), dividing a column by 100 to get the
percentage, and more complex formulas such as concatenating strings, or
any other formulas that may be necessary. In case your expression is
written incorrectly, QMF for Windows will not add the column, and will
display an error message.
206 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 92. Adding columns to a new prompted query
6. The next section is the Sort section. In this section you can select the
column by which the query result will be sorted. You can also select if the
sort is to be ascending or descending. To add a sort condition, click on the
Add Sort Condition button, and a window similar to the one in Figure 93
will appear. Then select the column for the sort condition, select the
direction of the sort (ascending or descending), and click on the Add
button.
7. The last section is the Row Conditions section. It allows you to select a
subset of the data in the selected tables. In other words, you can use a
condition to retrieve only the rows that correspond to it. For example, if you
selected a sales table and want only the sales numbers from a certain
date, you can enter this condition here. To add the Row Conditions, click
on the Add Row Conditions button and a window similar to the one in
Figure 94 will appear. In this window, it is possible to select a column, an
operator, and a value (as shown) where the column is the HIREDATE, the
operator is “Less than or equal to” and the value is “01/01/1980”. This
condition means that the data shown in the result will only apply to
employees that have been hired before or at the first of January, 1980.
Click on the Add button to add the condition to the query. This process can
be repeated several times until all conditions are added.
208 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
When adding more than one condition, pay close attention to the option at
the top left corner of that window that says “Connector”. This will link the
different conditions to one another by the AND clause or the OR clause.
For example, if a second condition is added to the prior example saying
that only employees who are male are to be selected, and the two
conditions are linked by the AND clause, it would mean that only
employees who correspond to both conditions will be in the result. If these
conditions are linked by the OR clause, it would mean that employees who
correspond to either of the conditions would be shown in the result.
8. The prompted query is now ready and can be run by clicking the Run
Query button on the toolbar, using the Query and Run menu, or using the
shortcut CTRL +R. Doing this, the result of the query will be displayed as
shown in Figure 95, and you can verify if your query is exactly the way you
wanted it to be. If you want to change the query later, click on the View
Prompted button on the toolbar and the Prompted Query window will be
displayed again. Then go to the section you want to modify and click on
the Change button for the selected section.
9. If you want to see the SQL statement that the prompted query is going to
submit to the server, you can do that by clicking on the View SQL button.
Notice that the SQL is read-only, meaning you cannot change the SQL
statement directly. To do this, it is necessary to convert your prompted
query to an SQL query using the Query and Convert to SQL menus.
Doing this will create a new SQL query, and the original prompted query
will be maintained, but they are not linked to each other.
Note:
This is different than the way QMF works on the host platform.
So, if you change the prompted query the SQL query will not be changed
automatically and vice versa. Sometimes it is necessary to convert
prompted queries to SQL queries for other reasons.
210 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
10.The final step is to save the query. This can be done in two ways: save the
query at a server, or save it in a file. To save the query at a server, you can
either click on the Save At Server button or use the File and the Save At
Server... menu. A window as shown in Figure 96 will appear. You then
have to type the owner, name, and comments of that query as well as
selecting if that query can be shared with others users. Click on the OK
button and the query will be saved. To save a query in a file, you have to
use the Save button or the File and Save As... menu.
There are two main ways of creating a form. You can create an empty form
and create all fields from the beginning, or you can use the default form using
a query from the starting point.
FIRSTNME STRING(12)
LASTNAME STRING(15)
DEPTNAME STRING(29)
212 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 97. New blank form
2. To create new columns for the form, click on the Main button or use the
Form and Main... menu. The window shown in Figure 98 will be displayed.
3. In that window, click on the existing column called Column 1 and change
its name to the one you would like to appear as the column header.
4. Now it is necessary to add the other columns. To add a column, click on
the Add Column button and a window as shown in Figure 99 will be
displayed. In that window, type a name for the column and click on the
Add button. The column will be added and the window will be cleared for
you to enter the next column. Repeat this process until all required
columns are added. On the last column, instead of clicking on the Add
button, click on the OK button and the window will be closed.
5. After all columns are added, it is necessary to modify the width of these
columns. That can be done by simply clicking on the width column on the
Main window for each column, and modifying its value. Remember that the
width also should match the width of the columns in the query.
6. The space between the columns is 2, by default. But you can change it by
changing the Indent value for each column.
214 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 99. Adding columns to a new blank form
7. Another adjustment that can be made to the columns is the Edit Code.
This code indicates the data type of the column in the form. Again, this
data type has to match the data type in the query. There are several Edit
Codes for several data types. Table 6 shows the available Edit Codes.
There are some data types in this table that will be rarely used. To modify
the Edit Code, just click on the Edit column and choose the Edit Code
from the list. Click on the OK button and the changes will be applied to
your form.
CW Display character data with No special formatting unless the value cannot fit
wrapping based on column within the width of the column. In that case, text
width. will be wrapped within the column width to
subsequent lines.
CT Display character data with No special formatting unless the value cannot fit
wrapping based on column within the width of the column. In that case, text
value. will be wrapped based on the column value to
subsequent lines. That is, text will be wrapped at
the end of a line when a blank is found. If the
wrapped text is too long to fit in the column and
does not contain a blank, the text is wrapped
within the column width.
CDx Display character data with The column is always wrapped based on the
wrapping based on the delimiter specified. The delimiter can be any
specified delimiter. single character, including a blank. The delimiter
character does not appear in the report.
216 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Data Type Edit Format Notes
Code
GW Display graphic data with No special formatting unless the value cannot fit
wrapping based on column within the width of the column. In that case, text
width. will be wrapped within the column width to
subsequent lines.
8. If you want to display a title on top of the report, type the text in the
Heading Text field. It is also possible to display some text at the bottom of
the page by entering it in the Footing Text field. For beginning users, we
do not recommend changing any other parameter on this window.
9. The form is now ready to be used if every column in the form matches the
columns in the query. However, to use the form in the future, it is
necessary to save it. You can save the form on the server or in a file.
To save the form on the server, click on the Save At Server button or use
the File and Save At Server... menu. The window shown in Figure 100 will
appear. Fill out the owner, name and comment fields as well as selecting if
the form is to be shared with other users, and click on the OK button.
To save the form in a file, click on the Save button or use the File and
Save As... menu.
218 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 100. Saving new blank form
10.To use the form, you first have to open run the query. For more information
on how to access existing objects, refer to 6.3, “Accessing existing
objects” on page 183.
11.After the query has been executed, go to the Query and Display Report...
menu. A window as the one shown in Figure 101 will be displayed,
prompting you to select a form. To use the form you just saved, either
select the option From Database or From File, depending on how the
form was saved. In case it was saved on the server, select the database,
owner, and name of the form (or select it from the list by clicking on the
List Form... button). If the form was saved in a file, select the file name
and click on the OK button. The form will be displayed with the result data
of the query in it.
3. Select the Default Form option and click the OK button. A new form will
be automatically created with the same structure as the query result. Also,
the query data will be shown in this form.
220 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
4. You can now save the form on the server or on a file. To save the form on
the server, click on the Save At Server button or use the File and Save At
Server... menu. The window shown in Figure 100 will appear. Fill out the
owner, name, and comment fields, as well as selecting if the form is to be
shared with others users. To save the form in a file, Click on the Save
button or use the File and Save As... menu. Then click the OK button.
If the form is saved, instead of creating another default form every time you
access the query, you can use this form by selecting the option From
Database or From File.
A very important feature of the forms are the Usage Codes. These are
functions that can be applied to each column to provide more information
within the form. To access this, it is necessary to click on the Main button or
use the Form and Main... menu. A complete reference on these usage codes
is available in Table 7. We will only discuss the most common functions.
Table 7. Usage codes
2) The number of rows and the title of each row in the report are
dependent on the values in the GROUP column(s). There is one
row for each value in the GROUP column(s) and the title of each
row is the value of the column(s).
NOTE: The CSUM, PCT, CPCT, TPCT, and TCPCT usage codes
are only partially supported when generating reports that also use
the ACROSS usage code.
AVERAGE Average of the This usage code is only valid for numeric data. This calculated
values in the value appears as a total in the report. The calculated value is
column. formatted with the edit code of the column.
BREAKn Provide a control For example, BREAK1 specifies a control column for a level-1
break level (where n break and BREAK2 specifies a control column for a level-2 break.
represents a number Any change in the value of the column causes a section break in
between 1 and 6). the report. Subtotals are displayed for columns whose usage is
one of the aggregation usages. Also, the text specified in the
appropriate Form Break component is displayed. Your query
should use an ORDER BY clause that matches your BREAK
columns.
CALCid The evaluation of the This calculated value appears as a total in the report and applies
calculation only to the last row of data. The calculated value is formatted with
expression in the the edit code of the column. If the column value is used in the
Form Calculations calculation, only the last row of data is evaluated.
component whose
ID equals "id".
COUNT Count of the non-null This calculated value appears as a total in the report. The
values in the calculated value is formatted with the edit code K.
column.
CPCT Cumulative This calculated value replaces each detail line value and also
percentage each appears as a total in the report. The calculated value is formatted
value of the column with the edit code of the column.NOTE: The CPCT usage code is
is of the current total. only partially supported when generating reports that also use the
ACROSS usage code.
CSUM Cumulative sum of This calculated value replaces each detail line value and also
the values in the appears as a total in the report. The calculated value is formatted
column. with the edit code of the column.
NOTE: The CSUM usage code is only partially supported when
generating reports that also use the ACROSS usage code.
FIRST First value in the This calculated value appears as a total in the report. The
column. calculated value is formatted with the edit code of the column.
222 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Usage Code Description Notes
GROUP Displays only one More than one column can have usage GROUP. If so, a change in
line of summary value in any column starts a new group. All other columns with no
data for each set of usage code are omitted from the report.
values in the
column.
LAST Last value in the This calculated value appears as a total in the report. The
column calculated value is formatted with the edit code of the column.
MAXIMUM Maximum value in This calculated value appears as a total in the report. The
the column. calculated value is formatted with the edit code of the column.
MINIMUM Minimum value in This calculated value appears as a total in the report. The
the column. calculated value is formatted with the edit code of the column.
OMIT Excludes the The column and its values are not included in the tabular report.
column from the The values in the column can still appear in the report (for
report example, in a break footing) by use of form variables (such as &n,
where n represents the column number).
PCT Percentage each This calculated value replaces each detail line value and also
value of the column appears as a total in the report. The calculated value is formatted
is of the current total. with the edit code of the column.
NOTE: The PCT usage code is only partially supported when
generating reports that also use the ACROSS usage code.
STDEV Standard deviation This usage code is only valid for numeric data. This calculated
of the values in the value appears as a total in the report. The calculated value is
column. formatted with the edit code of the column.
SUM Sum of the values in This usage code is only valid for numeric data. This calculated
the column. value appears as a total in the report. The calculated value is
formatted with the edit code of the column.
TPCT Percentage each This calculated value replaces each detail line value and also
value of the column appears as a total in the report. The calculated value is formatted
is of the final total. with the edit code of the column.
NOTE: The TPCT usage code is only partially supported when
generating reports that also use the ACROSS usage code.
TCPCT Cumulative This calculated value replaces each detail line value and also
percentage each appears as a total in the report. The calculated value is formatted
value of the column with the edit code of the column.
is of the final total. NOTE: The TCPCT usage code is only partially supported when
generating reports that also use the ACROSS usage code.
In the same way we used the SUM function, we could have used many other
functions such as AVERAGE, COUNT, MAXIMUM, and so on. The resulting
value would be different, but the layout of the form would be the same.
Another important usage code is called BREAK. This function creates a new
break every time the value of a specific column changes. Therefore, if you
want to see a break by a specific column, the query must be ordered by
that column. In our example, we will create a break by Department, so the
query must be ordered by Department. To do this, click on the Usage and
224 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
select the BREAK function on the column Department. The result is shown in
Figure 103.
As you can see, every time the value in the column Department changes, a
break is generated. Also the sum of the Salary, Bonus, Commission, and
Total Income are displayed per Department as well as a total sum at the end
of the form. There are other functions, such as the GROUP function, that do
similar things.
There is still one more thing that could improve our example report. That is to
move the Department column to the first position. This can be done in the
Main window using the Seq column as shown in Figure 104. This number
represents the sequence in which the column will appear in the form. To
change it, click on the number and either type the number you want or use the
scroll buttons to increase or decrease the number. You have to reorder the
number yourself; otherwise, you will have two columns with the sequence
number, and QMF will use the column with lower number in the column Num
to appear first.
226 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
The result of this change is shown in Figure 105 below. The Department
Column is now shown in the first position of the form.
To make sure that there is no problem with your form, you can click on the
Check button or use the Form and Check menu and QMF will check the
entire form and show a message with the result.
228 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
2. In this window, you must now type your procedure. To do this, you need to
know the commands available for procedures. A list of these commands
can be found in Table 8. For a complete reference on their possible syntax,
refer to the on-line help. Type the commands you want with the
appropriate syntax in the window. The commands must be one per line,
and they will be executed one after the other. The second command will
not start until the first command has completed, and so on.
Table 8. Procedure commands
Command Description
BOTTOM BOTTOM scrolls to the last row of a query result set. This command
is equivalent to FORWARD MAX
CONVERT CONVERT will convert a prompted query to a new SQL query. The
original query (whether a named object in the database or a temporary
object) is unaffected by this operation.
DRAW DRAW creates a basic query for a table based on the description of
the table in the database.
FORWARD FORWARD scrolls forward in a query result set. The only acceptable
parameter for this command is MAX, making it equivalent to
BOTTOM.
IMPORT IMPORT copies data from a file into temporary storage or the
database.
SAVE SAVE stores the contents of an object in temporary storage into the
database.
SEND TO SEND TO exports reports and data from the database or temporary
storage and sends them to the specified target or application in your
Send To folder.
SET SET GLOBAL sets the values of existing global variables or creates
GLOBAL new variables and values. Any new global variables created exist for
the entire QMF for Windows session (unless manually deleted).
3. Before saving the procedure, you should test it. To run a procedure, click
on the Run Procedure button from the toolbar (shown in Figure 107) or
use the Procedure and Run menu. The execution should start
immediately after that. In case there is any error in the syntax of any
command in the procedure, an error message will be displayed. If no error
occurs, the commands will be executed. If necessary, change the
procedure until it performs its intended operation without errors.
4. After testing the procedure, you may wish to save it. It is possible to save
a procedure at a server or in a file. To save a procedure at the server, click
on the Save At Server button or use the File and Save At Server... menu.
A window similar to the one in Figure 107 will appear. Then type the
owner, name, and comments of the procedure, select if the procedure is to
be shared with other users, and click on the OK button. To save the
procedure in a file, use the Save button or use the File and Save As...
menu.
230 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 107. Saving new procedure
Procedures can vary tremendously from one to another. The one shown
above is only a very simple example of what a procedure can do.
232 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 108. Lotus 123 Snap-In
5. A window as shown in Figure 109 will appear. In that window you can
select several ways of importing the data. The most common one is the
Import Data option that places the result of the data in the spreadsheet,
but there are other options, like the Group option and the Cross Tab
Report. Whenever you change this option, the window will also change,
prompting for specific information for the selected way of importing the
data.
6. After the configuration of the options on how the data is going to be
imported, it is necessary to select the starting cell on the spreadsheet in
which the data will be imported. Click on the cell you want and then click
on the field Place Result At. The cell identification will appear
automatically.
7. The last step is to click on the Execute button, and the data will be
imported into your spreadsheet as shown in Figure 110.
234 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 110. Result of Lotus 123 Snap-In
At this point, you can use this data, as it is a regular spreadsheet. Keep in
mind that any modification in the data in the spreadsheet will not affect the
data in the database server and vice versa.
5. A window as shown in Figure 112 will appear, where you can select
several ways of importing the data. The most common one is the Import
Data option where it simply place the result of the data in the spreadsheet
but there are other options like the Group option, and also graphics.
Whenever you change this option, this window will also change, prompting
for specific information for the selected way to importing the data.
236 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 112. Formatting data using Excel Snap-In
6. Finally, click the Run Query button and the data will be imported to the
spreadsheet, as shown in Figure 113. The windows will not be closed
automatically, so you have to click on the Close button yourself.
At this point, you can use this data, as it is a regular spreadsheet. Keep in
mind that any modification in the data in the spreadsheet will not affect the
data in the database server, and vice versa.
238 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
4. After the login, a window as shown in Figure 114 will appear. In that
window, you can select the owner and the name of the query directly if you
know it, or you can use the wildcard ’%’ to view a list of available queries
and then click the OK button. In this window, there is also an opportunity
to save the query itself to MS Access. This means that a new query will be
created inside MS Access with the same SQL statement as the one in
QMF. That can be done by clicking on the Save button instead.
5. A window as shown in Figure 115 will appear. In that window, you can
either select an existing table where you want to place the data, or, if you
do not specify the table, a new table will be created. If selecting an existing
table and the result of the QMF query and the selected table do not match,
an error will occur.
240 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 116. Select and report list
7. The last step necessary is to click the OK button, and the data will be
imported. In the case of the example shown, a new table is created and
the data is imported into it as shown in Figure 117.
At this point, you can use this data, as it is a regular Access table. Keep in
mind that any modification in the data in that table will not affect the data in
the database server and vice versa.
If the DBA authorizes you to convert dynamic SQL to static SQL, follow the
procedure described in 4.4.1, “Convert dynamic SQL to static SQL” on page
115.
For most DB2 users, static SQL — embedded in a host language program
and bound before the program runs — provides a straightforward, efficient
path to DB2 data. You can use static SQL when you know the exact SQL
statement before your application needs to execute it.
242 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Dynamic SQL prepares and executes the SQL statements within a program
while the program is running. It is used when the user creates the SQL
statements dynamically, for example, using the QMF for Windows interface.
DB2 prepares and executes those statements as dynamic SQL statements.
The time at which DB2 determines the access path depends on these factors:
• Whether the statement is executed statically or dynamically
• Whether the statement contains input host variables
For dynamic SQL statements, DB2 determines the access path at run time when
the statement is prepared. This can make the performance worse than that of
static SQL statements. However, if you execute the same SQL statement very
often, you can use the dynamic statement cache to decrease the number of
times that those dynamic statements must be prepared. Ask your DBA about the
dynamic cache option in DB2.
It is important to keep in mind that QMF for Windows limits will not overwrite
the database server limits. In other words, you may have permission to
update a table on the QMF for Windows level, but you may not have the
permission to do this on the database level. In this case, you will not be
allowed to update that table. You must have permission both in QMF and the
database in other to execute a command. Therefore, you may see specific
permission available to you in the QMF for Windows resource limits, but still
may not be able to execute the command, due to the database limits.
Although you cannot change the resource limits, you can check them at any
time. To do this, first you have to be connected to the database server by
accessing one object in that database, such as the list of objects or a query.
Then go to the View and Resource Limits... menu.
A window as shown in Figure 118 will appear, asking for you to choose if you
want the most current resource limits. The reason for this is that the moment
QMF connects to a database server, it retrieves the resource limits and stores
them on your local computer. While you are working, the DBA may have
changed these limits, and you will not see them until the next connection.
Therefore, when you try to see your resource limits, QMF will ask you if you
want to see the most current version of these limits stored on the server, or if
you want to see the ones stored on your local computer.
244 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 118. Retrieve the most current resource limits
After that, a window as shown in Figure 119 will be displayed showing the
resource limits. In this window you can see (but not change) the limits that are
applied to you. As you can see, these limits set the timeout of the connection,
the maximum number of connections, the maximum number of rows to fetch,
the SQL verbs you can use in your SQL statements, and many other limits. To
check what each of these resource limits mean, refer to 4.2.2, “Creating
schedules” on page 94. In case you need to change these limits for any
reason, talk to the DBA responsible for setting your resource limits.
6.9 Security
QMF for Windows Administrator is the administrative component of QMF for
Windows, and using this module should be strictly an administrator task.
There should not be any need for an end user to run QMF for Windows
Administrator. QMF for Windows Administrator is used to maintain resource
limits groups. To use QMF for Windows Administrator to maintain resource
limits groups, you must have the authorization to execute the QMF for
Windows Administrator package. This prevents unauthorized users from
changing the limits that are established by the administrator.
246 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 120. Change password
6.9.2 Lists
The database administrator might want to restrict the visibility of these
objects to a certain number of users. To do this, QMF for Windows allows the
creation of predefined lists that the users will see by default when working
with the product. Lists are also useful to simplify the day’s work of the users
by providing them with a tailored set of QMF for Windows objects by default.
If a user starts working with predefined queries, and so on, the usual way
would be to use the File -> Open from Server menu. This would open a
window that then needs to be modified if the user does not need to see all
objects from all users. Creating a predefined list provides an alternative to
simplify the work by using the File -> Open menu to see a list of tailored
objects.
Within the List window, several options are available using the icons in the
Toolbar or the right mouse button. These options are:
• Display object to view the selected object. This function is available for
Queries, Forms, Procedures, and Tables.
• Run object to execute the selected object. This is only available for
Queries and Procedures.
• Draw object to create a query based on a selected table. The type of
query may be either a SELECT query, an SQL UPDATE query, an SQL
INSERT query, or a prompted query. This options only works for tables.
• Edit object is available only for tables and will open the Table Editor for
this table.
248 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
• Properties is available for all four types of objects, and displays the
properties of the selected object, including comments, attributes, and
historical usage information.
250 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
6.11 Migrating from OS/2 Query Manager
Longtime users of Query Manager/2 have relied upon its native connectivity
to DB2 and its robust performance in demanding environments. Many have
used it to accumulate valuable assets in the form of libraries of Query
Manager/2 reports. But at the same time, in addition to not being Year 2000
compliant, OS/2 Query Manager does not allow the use of all the new
functions introduced into DB2 UDB, and therefore leaves users unable to
extend the use of their reports to more applications across the enterprise.
The QMF for Windows procedure environment is not identical to the Query
Manager/2 environment. Therefore, Query Manager/2 customers are likely to
find that some of their Query Manager/2 procedures — especially those
containing REXX code — do not work after conversion in the QMF for
Windows environment. Some objects may require editing by hand, and others
will need to be completely rewritten or even discarded, for example because
of the fact that QMF for Windows does not support REXX procedures.
252 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Chapter 7. Web considerations
The Web is changing every aspect of our lives, but no area is undergoing as
rapid and significant a change as the way businesses operate. As businesses
incorporate Internet technology into their core business processes, they start
to dynamically alter the way to do business. Today, companies large and
small are using the Web to communicate with their partners, to connect with
their back-end data-systems, and to transact commerce.
In short, e-business isn't about re-inventing your business. It's about altering
your current business processes to improve operating efficiencies which in
turn will strengthen the value you provide to your customers — value that
cannot be generated by any other means, and value that will give you a
serious advantage over your competition.
One way to get started would be to use as many existing technology and
products available within a company, and start with using the Web as a
transport or access layer for the result presentation.
The term intranet will be used for talking about Web technology that has been
implemented to be used from within a company’s network, whereas the term
Internet will indicate accessibility to this information from outside the
company. QMF for Windows provides an easy way to get started delivering
data through the Web.
A typical environment might look like the one shown in Figure 124.
254 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
World Wide Web
Database
Web Web Server
Browsers Server
Generating static reports is best done using a procedure like the following:
1. Execute the query.
2. Generate the report using a QMF form.
3. Export the report to an HTML file with a predefined name in the Web
server’s HTTP directory.
Using this approach, the Web server does not need to have QMF for Windows
installed at this server. QMF may be installed anywhere within the network,
because only the resulting HTML document needs to be transferred to the
Web server.
The following sections cover some specifics for the use of QMF for Windows
HTML based reports and the way to schedule this entire process.
The first action to take is to create the query that lists the depar tments
and shows them as an HTML document, including links to the specific
repor ts. Figure 125 shows a query example.
The next step is to create the form to display the result in HTML format. This
can be done by using the Convert to HTML button. This example has been
created without specifying any parameters in the screen that shows up after
clicking this button. Clicking on the HTML button allows you to further specify
the HTML form by selecting Edit Form... .First select the Main.. selection to
specify the report header, as shown in Figure 126.
256 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 126. Form main
At this point, it still possible to use all the functions for a normal form, such as
saving it at a server, checking for errors, and so on. See Figure 127.
After defining the main header, go to the HTML -> Edit Form.. -> Details
menu to specify the appearance of the body of the document. The example
shown will list the query result in table format and define an HTML anchor for
each department. Clicking this anchor will link the user to the detailed report
for each department.
In the example shown in Figure 128, the Detailed Heading Text section
specifies a horizontal line as a separator between the heading and the body,
and also specifies the body to be formatted as a table. In the Detailed Block
Text part of the screen, the definitions are made to create the links and
descriptions for the final document.
258 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 128. Form detail
Other queries have been defined to select the detailed information for each
department, and the HTML form has been created, as explained in 6.4.3.3,
“Convert forms to HTML” on page 194.
7.2.3 Scheduling
The last step necessary in the small example is to automate the process of
executing the queries and saving the HTML reports to the Web server’s
HTML directory. Figure 130 shows the procedure to do this.
260 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 130. Publishing procedure
In the example shown, the Web server default HTML directory is located on
the D drive under \WWW\HTML, but if the Web server is not the same system
that QMF for Windows runs on, this path as well points to a shared LAN drive
of the Web server system.
The benefit here is due to the fact that the result displayed is the result of the
query executed at this time, and therefore guarantees up-to-date results. The
trade-off using this approach as a general (or single) implementation is that it
uses more resources — on the database server as well as on the Web server
— and therefore may be performance-sensitive. Using this access method is
shown in Figure 131.
Document
Request Start Application
SQL query
HTML input
SQL query
results
CGI, ...
262 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
4. The application receives the result from the query and has to present the
result in an HTML format and send it back to the Web server.
5. The Web server sends the HTML document, containing the query result,
back to the end user.
Today, there are many ways available to write applications that are “Web
enabled”. Starting with the Common Gateway Interface (CGI), this list is
expanded through the use of Web Server APIs that improve performance
compared to CGI, Java applets, Active Server Pages (ASPs), and so on. The
following section will describe an application example written using CGI, but
all other application development approaches will work as well.
7.3.1 CGI
A generic method of generating dynamic reports is to write an application that
uses CGI.The CGI applications are a way of using a programming or scripting
language on a server, to respond to requests from a Web client by executing a
file that returns HTML built “on-the-fly”. In other words, a CGI script is called from
a Web client, the script is executed by the Web server, and the script returns
HTML to the Web client as the output of its execution.
This HTML can be anything that the CGI application generates. To create
dynamic reports, this CGI could generate a report for a given input query,
meaning that the user would select a query on his Web browser, and the
result would also displayed on his Web browser.
Using the Web browser, the user has to indicate the Internet address of the
CGI application. In our case, the address was:
http://balboa.almaden.ibm.com/cgi-bin/cgisample.exe
where cgisample.exe is the CGI executable file. Once it is done, the screen
shown in Figure 132 will appear.
The user then has to input some information. The first input required is the
server name, which must match exactly with the name defined on QMF for
Windows. These names are defined on the server definition file by the QMF
administrator. The next inputs required are the user ID and password.
Remember that in some systems such as AIX or OS/390, it may be
case-sensitive. The last input is the SQL statement of the query. Only queries
using the SELECT verb are allowed in this example. If the SQL statement is
not properly written, an error will occur.
After all the input parameters have been correctly filled in, the user must click
on the OK button. All the input parameters will be sent through the Web to the
CGI application. The CGI application will then use the QMF APIs to connect
to the server, execute the query, and return the result, as shown in Figure
133.
264 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 133. CGI example -— second screen
The user can repeat the operation again by clicking on the Back button of the
browser, inputting the parameters, and submitting again.
The source code below shows how this CGI application was implemented.
Note that the QMFWinLibrary_TLB is included on the uses clause of the unit.
Without it, the CGI application will not be able to access the QMF APIs.
uses
Windows, Messages, SysUtils, Classes, HTTPApp,
ExtCtrls, QMFWinLibrary_TLB, ComObj, ole2;
The class definition is listed below. Two procedures were used in this
example:
type
TWebMod = class(TWebModule)
procedure WebModactConnectAction(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
procedure WebModactResultAction(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
private
public
end;
The first procedure simply creates an HTML answer for the first request of the
user, showing the screen as shown in Figure 132. The source code of this
procedure is listed below:
procedure TWebMod.WebModactConnectAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
//simply respond to the user an HTML with input boxes for
//the server name, user ID, password and SQL statement
Response.Content:= '<HTML>'
+ '<BODY>'
+ '<H1>'
+ '<H1>QMF CGI Sample</H1>'
+ '<FORM METHOD="POST" ACTION="http://'
+ Request.Host
+ Request.ScriptName +'/Result">'
+ '<CENTER><TABLE BORDER=3 CELLSPACING=0 COLS=1'
+ 'WIDTH="36%" BGCOLOR="#FFFFCC" >'
+ '<TR>'
+ ' <TD ALIGN=RIGHT WIDTH="25%">'
+ ' Server Name'
+ ' </TD>'
+ ' <TD ALIGN=LEFT>'
+ ' <INPUT TYPE="TEXT" NAME="edServerName" SIZE="40">'
+ ' Has match the Server Definition File serves'
+ ' </TD>'
+ '</TR>'
+ '<TR>'
+ ' <TD ALIGN=RIGHT WIDTH="25%">'
+ ' User ID'
+ ' </TD>'
+ ' <TD ALIGN=LEFT>'
+ ' <INPUT TYPE="TEXT" NAME="edUserID" SIZE="8">'
+ ' </TD>'
+ '</TR>'
+ '<TR>'
+ ' <TD ALIGN=RIGHT>'
+ ' Password'
+ ' </TD>'
+ ' <TD ALIGN=LEFT>'
+ ' <INPUT TYPE="PASSWORD" NAME="edPassword" SIZE="8">'
+ ' </TD>'
+ '</TR>'
266 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
+ '<TR>'
+ ' <TD ALIGN=RIGHT>'
+ ' SQL Statement'
+ ' </TD>'
+ ' <TD ALIGN=LEFT>'
+ ' <TEXTAREA NAME="edSQL" COLS=60 ROWS="8" WRAP="SOFT">'
+ ' </TEXTAREA>'
+ ' </TD>'
+ '</TR>'
+ '</TABLE></CENTER>'
+ '<CENTER>'
+ '<BR><INPUT TYPE="SUBMIT" VALUE=" Ok "></TD>'
+ '</CENTER>'
+ '</FORM>'
+ '</BODY>'
+ '</HTML>';
end;
The second procedure receives the input parameters and connects to the
server, executes the query, and creates an HTML response with the result of
the query. The source code of this procedure is listed below:
procedure TWebMod.WebModactResultAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
QMF: QMFWin;
Col: Integer;
myColumnCount: Integer;
FetchResult: Integer;
QueryNumber: Integer;
ColumnHeadings: OleVariant;
myRow: OleVariant;
UserID: String;
Password: String;
ServerName: String;
SQLStatement: String;
begin
//Receives the ServerName, UserID, Password and SQLStatement
//and copy them to a local variable
UserID:= Trim(Request.ContentFields.Values['edUserID']);
Password:= Trim(Request.ContentFields.Values['edPassword']);
ServerName:= Trim(Request.ContentFields.Values['edServerName']);
SQLStatement:= Trim(Request.ContentFields.Values['edSQL']);
if (UserID = '')
or (Password = '')
or (ServerName = '')
or (SQLStatement = '') then
268 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
//if successful display the column headings
//creating the HTML for the response
begin
Response.Content:= '<HTML>'
+ '<BODY>'
+ '<h1>QMF CGI Sample</h1>'
+ '<BR><b>SERVER: </b>' + ServerName
+ '<BR><b>SQL Statement: </b>' + SQLStatement
+ '<BR><center><table BORDER COLS='
+ IntToStr(myColumnCount)
+ ' WIDTH="100%" >'
+ '<BR>'
+ '<tr BGCOLOR="#FFFFCC">';
//fill the HTML with the column name
for Col:= 0 to (myColumnCount - 1) do
Response.Content:= Response.Content
+ '<td>'
+ ColumnHeadings[Col]
+ '</td>';
Response.Content:= Response.Content + '</tr>';
//try to fetch all the rows from the query
//and place the data on the HTML
FetchResult:= QMF.FetchNextRow(QueryNumber, myRow);
while FetchResult = 0 do
begin
for Col:= 0 to (myColumnCount - 1) do
Response.Content:= Response.Content
+ '<td>'
+ VarToStr(myRow[Col])
+ '</td>';
//close HTML
Response.Content:= Response.Content
+ ' </table></center>'
+ '</BODY>'
+ '</HTML>';
Note:
When using CGI examples that create OLE objects (in this case, the
QMF object), the procedure OleInitialize(nil) has to be called before
creating the object. At the end of the program, the procedure
OleUnInitialize() has to be called also. These procedures are available in
the windows DLL OLE32.DLL.
270 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Chapter 8. Summary
Throughout this book, we have described the benefits of using the QMF
family of integrated tools to build an Enter prise Quer y Environment. This
environment will answer the main needs of an enterprise when having
widely distributed database systems installed. QMF for Windows, which
has been used mainly to demonstrate QMF, is representative of all other
QMF tools available on different platforms. The entire environment not
only helps the database administrator with the daily work of performance
monitoring and checking for resource consumption, but it also simplifies
the end users work.
DB2
QMF for Windows: QMF for VM&VSE:
Execute Query Execute Query
There are, however, some functions not fully exploited with the current
version of the product. For example, some of the DB2 database features, like
the capability to store large objects (LOBS) inside the database tables, are
not yet supported. Also, as the QMF for Windows product reaches a new type
of end user, its interface will change in future releases. The ”grid” — that is,
the way the query result is presented to the user after executing a query
without specifying a form to be used — will allow for better direct formatting.
This will give the end user an easy way to reformat the result presentation
without having to define a separate form to do this.
272 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Another enhancement will also be seen, with the support of REXX logic to be
available within the QMF procedures. This will allow procedures to be more
flexible, and will enhance the functionality of procedures to incorporate logic,
rather than being “linear” only.
To furthermore expand the platforms that QMF is available on, the product
will be written in Java, thus allowing the product to be installed and executed
on any operating system that provides a Java Virtual Machine (JVM). This
way, QMF will also be available to be used from AIX based operating
systems, thus allowing both Windows and AIX users to access DB2 on any
platform using the same GUI.
Once the user has selected a specific query it, can be executed in by either
double-clicking on its name or selecting the Report -> Run menu. The query
result will then be displayed in the way specified in the Report -> Properties
menu, by default pointing to the Notepad application. Within these properties,
the user is also able to select the form used to format the query result. Other
available applications predefined by Personal Portal are:
• Web Browser (.HTML format)
• Lotus 123 (.123 format)
• MS Excel (.XLS format)
• Lotus Wordpro (.LWP format)
• MS Word (.DOC format)
• MS Access (.MDB format)
274 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
In addition, the user can specify if the report is to be written in a temporary
file or written permanently to the disk drive. Another option is to select a
certain QMF Procedure to be executed before running the query. Figure 136
shows the Properties screen where all these definitions can be made, either
temporarily or permanently, by selecting the Save as Favorite button.
The end user can even select favorite queries and report settings for the
Favorites folder, to allow easy access to the most frequently used objects.
Personal Portal allows all the objects shown in the main window to be copied
to the Favorites folder, as shown in Figure 137.
As the Rocket Personal Portal is downloadable for free from the Rocket
Software Web site, please check for the latest version of this application.
276 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Appendix A. Working with variables
Variables, as their name implies, are a part of a computer program code that
can be modified while that program is running. In this way, the same program
can be used for several actions. Let’s take, for example, a very simple
program that only sums two numbers. The program might look like this:
2 + 2 = X
In that case, the program result will always be 4, and that program will only be
useful if we want to sum 2 and 2. If we want to have a generic program that
sums any two numbers, we have to use variables. A program using variables
might look like this:
A is an Integer
B is an Integer
A + B = X
In this case, A and B are variables; they can be any integer numbers, and so
can the result, X. Now the same program can be used to sum any two
numbers.
QMF for Windows has two kind of variables, Substitution Variables and
Global Variables. The substitution variables are used in QMF objects for
substituting variables to strings at run time. In this way, you can substitute a
part of a SQL statement and make it more generic. Substitution variables are
only active while the object (Query, Procedure, Form) is running. Hence, just
one object can access it, and after the execution, the variable no longer
exists. On the other hand, global variables are active while QMF is active,
which means that variables will have the same value until the instance of
QMF is finished, and can be accessed by all QMF objects. Different instances
of QMF will not be able to see each other’s global variables.
From that moment on, all the global variables that you create will be stored in
HKEY_CURRENT_USER\SOFTWARE\IBM\RDBI\Global Variables in the
Windows registry, and will be kept from instance to instance.
278 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Registry Entry
Operating System
Global Variable
Substitution Variable
QMF Objects
The ’&’ character indicates that the string following is a substitution variable.
When you run that query, a prompt will appear for you to input the customer
number, as shown in Figure 140. After typing in the value, click on the OK
button and the query will be executed with the value that you typed. So, while
using the same query, you can retrieve all information from all customers that
are in debt without the need to create several different queries, one for each
customer. In QMF for Windows, you can have as many variables as you want
in one query, or use the same variable in different places of the query.
When using the substitution variables, you need to remember that they will be
substituted as typed; that means, if you are using the variable to substitute a
value to compare with a string column, it has to be delimited by quotation
marks, just as in the SQL statement.
Substitution variables can also be used in procedures with the same result.
However, if your procedure has to run overnight, you cannot use substitution
variables because the process will be stopped each time a variable is found
and it will prompt the user to enter the value, thus interrupting the procedure.
The solution to this problem is user defined global variables.
280 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
A.2 Global variables
Global variables are variables that stay active as long as the QMF instance is
active. Also, it is possible to configure QMF to save your global variables from
one instance to another as explained earlier. There are two types of global
variables, the user defined global variables and the pre-loaded global
variables.
2. Click on the Add button, and a window as shown in Figure 142 will appear.
3. In that window, type the global variable name and value. The name of the
variable may be a maximum of 17 characters long, and the value cannot
be longer than 55 characters. Also, variables may not begin with ’DSQ’.
4. After that, click on the Add button and the variable will be created as
shown in Figure 143.
282 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 143. New global variable created
To edit the value or change the name of a global variable use the Edit button
and to delete a variable use the Delete button.
QMF for Windows provides many variables for use in your queries, forms,
and procedures. All of the global variables defined for host QMF are
recognized by QMF for Windows, however, many are not applicable to the
Windows environment. Only those listed in the following tables are used and
accessible by QMF for Windows. Any references in queries, forms, or
procedures to QMF host global variables that are not supported by QMF for
Windows are ignored. See the host QMF reference for a complete listing of all
host QMF global variables. Global variables prefixed by DSQQW are QMF for
Windows global variables only; all other DSQ-prefixed global variables are
supported in both environments.
Identifier Description
DSQAO State information
DSQEC Control of how QMF for Windows executes commands and procedures
284 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Name Length Description
286 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Name Length Description
288 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Name Length Description
Form variables are codes you can insert into text fields to produce
information on the report itself. For example, you can insert a date variable to
produce the current date whenever the report is printed. Different form
variables are available, depending on the part of the form you are editing.
290 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
• &COUNT - Displays the number of rows retrieved or printed since the last
break at the same level.
• &CALCid - Identifies a Form Calculation expression to use, where "id" is
the ID number of the expression
• &n - Displays the value of a column, where "n" is the column number.
• &an - Displays the aggregation of a column, where "n" is the column
number, and "a" is one the following aggregation variables: AVG, COUNT,
CPCT, CSUM, FIRST, LAST, MAX, MIN, PCT, STDEV, SUM, TCPCT, or
TPCT. The aggregation is based on the rows retrieved or printed since the
last break at the same level.
• Global Variables – Displays the value of the global variable.
• HTML Variables – Displays the value of the HTML variable.
Table 15 shows the types of variables that can be used in each part of a form:
Table 15. Form variables
Page X X X X X
Heading
Page Footing X X X X X
Break X X X X X
Heading
Break X X X X X X X X
Footing
Calc X X X X X X X
Expression
Column X X X X
Definition
Condition X X X X
Detail X X X X X
Heading
Detail Block X X X X X X X X
Final Text X X X X X X X X
Global variables and HTML variables can be used throughout the form.
This appendix lists all of the QMF for Windows Application Programming
Interfaces (APIs) that the developer has available to create new applications.
B.1 AddDecimalHostVariable
short AddDecimalHostVariable(long QueryID, short Type, short Precision,
short Scale, const VARIANT& Value)
Description
This function applies the data in Value to a variable in the static SQL
statement initialized with QueryID. You call this function for each variable in
the statement. QMF for Windows makes no attempt to match values to
variables, so you must call this function in the same order as the variables in
the SQL statement.
Parameters
Table 16 shows the parameters for this API.
Table 16. AddDecimalHostVariable parameters
Name Description
Type The SQL data type of the value to be passed to the database server.
This value influences the conversion of Value from a VARIANT data
type to the value actually passed. The only valid value for
AddDecimalHostVariable() is 484 (RSDT_DECIMAL).
Value The data value to substitute in the statement. To specify a null value,
the type of the variant should be set to VT_EMPTY.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
Description
This function applies the data in Value to a variable in the static SQL
statement initialized with QueryID. You must call this function for each
variable in the statement. QMF for Windows makes no attempt to match
values to variables, so you must call this function in the same order as the
variables in the SQL statement.
Parameters
Table 17 shows the parameters for this API.
Table 17. AddHostVariable parameters
Name Description
Type The SQL data type of the value to be passed to the database server.
This value influences the conversion of Value from a VARIANT data
type to the value actually passed.
Value The data value to substitute in the statement. To specify a null value, the
type of the variant should be set to VT_EMPTY.
Value Meaning
388 (RSDT_TIME)Time
468 (RSDT_GRAPHIC)Graphic
294 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.3 BindDecimalHostVariable()
short BindDecimalHostVariable(BSTR CollectionName, BSTR
PackageName, short SectionNumber, short Number, BSTR Name, short
DataType, short Precision, short Scale)
Description
This function binds a variable in the specified section. Include the text :H in
the SQL text as a placeholder for a host variable. For each decimal host
variable in the SQL text, you must call BindDecimalHostVariable() to specify
information about the variable.
Parameters
Table 19 shows the parameters for this API.
Table 19. BindDecimalHostVariable parameters
Name Description
SectionNumber The section number of the statement within the collection and
package you want to bind.
Number The identifier for the variable you want to bind. The first variable in
the SQL statement is variable 0, etc.
Name Used by the database server for diagnostic purposes. This value
is not validated nor required by QMF for Windows.
DataType The SQL data type of the variable. The only valid value for
BindDecimalHostVariable() is 484 (RSDT_DECIMAL).
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Description
This function binds a variable in the specified section. Include the text :H in
the SQL text as a placeholder for a host variable. For each host variable in
the SQL text, you must call BindHostVariable() to specify information about
the variable.
Parameters
Table 20 shows the parameters for this API.
Table 20. BindHostVariable parameters
Name Description
SectionNumber The section number of the statement within the collection and
package you want to bind.
Number The identifier for the variable you want to bind. The first variable
in the SQL statement is variable 0, etc.
Name Used by the database server for diagnostic purposes. This value
is not validated nor required by QMF for Windows.
Value Meaning
384 (RSDT_DATE)Date
388 (RSDT_TIME)Time
296 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Value Meaning
468 (RSDT_GRAPHIC)Graphic
484 (RSDT_DECIMAL)Decimal
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.5 BindSection()
short BindSection(BSTR CollectionName, BSTR PackageName, short
SectionNumber, BSTR SQLText)
Description
This function sets the SQL text to be used in the specified section number of
the collection and package during binding.
Parameters
Table 22 shows the parameters for this API.
Table 22. BindSection Parameters
Name Description
SectionNumber The section number of the statement within the collection and
package you want to bind.
SQLText The SQL text for the statement you want to bind.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Description
This function cancels a previously initialized bind operation. All information
regarding the named package is released.
Parameters
Table 23 shows the parameters for this API.
Table 23. CancelBind Parameters
Name Description
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.7 ChangePassword()
short ChangePassword(BSTR NewPassword)
Description
This function changes the password for the user ID previously specified on
the InitializeServer() call.
Note
Not all types of database servers support changing passwords. If the
server specified on the InitializeServer() call does not support changing
passwords, an error is returned, and the password is not changed.
298 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Parameters
Table 24 shows the parameters for this API.
Table 24. ChangePassword parameters
Name Description
Return value
Zero if successful, non-zero if unsuccessful. If the return value is nonzero,
you can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.8 ClearList()
short ClearList(short Type)
Description
This function re-initializes the internal list specified by the Type parameter.
Parameters
Table 25 shows the parameters for this API.
Table 25. ClearList parameters
Name Description
Return value
Zero if successful, RS_ERROR_OUTOFRANGE if unsuccessful.
Related topics
Open()
B.9 Close()
short Close(long QueryID)
Description
This function closes a query and invalidates QueryID. If there is a cursor
open for the query, the cursor is closed, freeing the database for other users.
This function does not terminate the connection to the database server. Since
the connection remains open, no rollback or commit is performed.
Parameters
Table 26 shows the parameters for this API.
Table 26. Close parameters
Name Description
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
Execute(), Open()
B.10 Commit()
short Commit()
Description
This function commits any changes you made in the current unit of work,
ends the current unit of work, closes any open cursors, and invalidates all
outstanding query IDs.
Note
The name of this function conflicts with the Microsoft Access 2.0
keyword Execute. If you are using MS Access 2.0, place square brackets
[ ] around the function name.
300 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
Rollback()
B.11 CompleteQuery()
short CompleteQuery(long QueryID)
Description
This function fetches all rows of a result set and stores them internally in QMF
for Windows. If there is a cursor open for the query, the cursor is closed,
freeing the database for other users. You use FetchNextRow() or
FetchNextRows() to retrieve the rows. Call Close() when you are done with
this query.
Parameters
Table 27 shows the parameters for this API.
Table 27. Completequery parameters
Name Description
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.12 CopyToClipboard()
short CopyToClipboard(long QueryID, long FirstRow, long FirstCol, long
LastRow, long LastCol, BOOL IncludeColHeadings, [VARIANT
DateTimeFormat])
Description
This function copies the specified range of rows and columns to the
Clipboard. If you have not retrieved row data for all of the rows that you want
to copy to the Clipboard, you call CompleteQuery() prior to calling this
Parameters
Table 28 shows the parameters for this API.
Table 28. CopyToClipboard parameters
Name Description
LastRow The last row you want to include in the copy, or -1 if all rows
are included.
LastCol The last column that you want to include in the copy, or -1 if
all columns are included.
IncludeColHeadings Use nonzero to include the column headings in the first row
and zero to not include them
DateTimeFormat Optionally, the format to use for date and time values. Valid
values are 0 (ISO format), 1 (USA format), 2 (EUR format), 3
(JIS format), or 4 (Windows Control Panel format). The
default value is 4.
Note
The value of a first row in a result set is 0, and the value of the last row
is one less than the total number of rows. The value of the first column
in a result set is 0, and the value of the last column is one less than the
total number of columns.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information. If the result set is empty or no rows have been retrieved from the
database, nonzero is returned unless FirstRow = 0 and LastRow = -1. In this
case, zero is returned and an empty string is copied to the Clipboard.
Related topics
Export()
302 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
B.13 DeleteQMFObject()
short DeleteQMFObject(BSTR OwnerAndName)
Description
This function deletes a QMF object (query, form, procedure, or table).
Parameters
Table 29 shows the parameters for this API.
Table 29. DeleteQMFObject parameters
Name Description
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.14 EndBind()
short EndBind(BSTR CollectionName, BSTR PackageName)
Description
This function completes the bind process for a static SQL package. Calling
this function causes QMF for Windows to send the complete information for
the current package to the database for processing.
Parameters
Table 30 shows the parameters for this API.
Table 30. EndBind parameters
Name Description
B.15 Execute()
short Execute(long QueryID)
Description
This function executes an SQL statement that uses an SQL verb other than
SELECT. Use Execute() when the statement does not return any results. For
statements that do return results, use ExecuteEx(). For statements using the
SELECT verb, use Open() instead of Execute() or ExecuteEx(). To determine
the verb used by a query, call GetQueryVerb().
Note
The name of this function conflicts with the Microsoft Access 2.0
keyword Execute. If you are using MS Access 2.0, place square brackets
[ ] around the function name.
Parameters
Table 31 shows the parameters for this API.
Table 31. Execute parametes
Name Description
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.16 ExecuteEx()
short ExecuteEx(long QueryID, VARIANT* Result)
Description
This function executes an SQL statement that uses an SQL verb other than
SELECT. Use ExecuteEx() when the statement returns results, for example,
304 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
with a SELECT INTO statement. For statements that do not return any
results, use Execute(). For statements using the SELECT verb, use Open()
instead of Execute() or ExecuteEx(). To determine the verb used by a query,
call GetQueryVerb().
Parameters
Table 32 shows the parameters for this API.
Table 32. ExecuteEx parameters
Name Description
Result A pointer to a VARIANT in which the result will be stored. The result is
an array (variant type VT_ARRAY | VT_VARIANT) containing one
value for each column in the result.
Each value is specified in either its native data type or the closest
variant data type. The supported return types are: string (variant type
VT_BSTR), float (variant type VT_R4), double (variant type VT_R8),
short (variant type VT_I2), long (variant type VT_I4), and binary
(variant type VT_UI1 | VT_ARRAY).
You must properly initialize the VARIANT before calling this function.
Visual Basic does this automatically. Visual C++ programmers must
call VariantInit().
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.17 ExecuteStoredProcedure()
short ExecuteStoredProcedureEx(long QueryID, [VARIANT vaCommitOK],
[VARIANT vaMaxResultSets], [VARIANT vaColumnNames], [VARIANT
vaColumnLabels], [VARIANT vaColumnComments])
Description
This function executes an SQL statement that uses the SQL verb CALL, to
run a stored procedure at the database server. Use
ExecuteStoredProcedure() when the stored procedure does not return any
results (instead of or in addition to result sets). For stored procedures that do
return results, use ExecuteStoredProcedureEx().
Parameters
Table 33 shows the parameters for this API.
Table 33. ExecuteStoredProcedure parameters
Name Description
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
306 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
B.18 ExecuteStoredProcedureEx()
short ExecuteStoredProcedure(long QueryID, VARIANT* Result, [VARIANT
vaCommitOK], [VARIANT vaMaxResultSets], [VARIANT vaColumnNames],
[VARIANT vaColumnLabels], [VARIANT vaColumnComments])
Description
This function executes an SQL statement that uses the SQL verb CALL, to
run a stored procedure at the database server. Use
ExecuteStoredProcedureEx() when the stored procedure returns results
(instead of or in addition to result sets). For stored procedures that do not
return results, use ExecuteStoredProcedureEx().
Parameters
Table 34 shows the parameters for this API.
Table 34. ExecuteStoredProcedureEx parameteres
Name Description
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.18.1 Export()
short Export(long QueryID, long FirstRow, long FirstCol, long LastRow, long
LastCol, short Format, short StringDelimiter, short ColumnDelimiter, BOOL
IncludeColHeadings, BSTR FileName, [VARIANT DateTimeFormat])
Description
This function exports the specified range of rows and columns using the
specified options to the specified file. You call CompleteQuery() prior to
calling this function if you have not retrieved row data for all of the rows you
want to export. An error message is returned if you attempt to export rows
that have not been retrieved from the database.
308 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Note
The name of this function conflicts with the Microsoft Access 2.0
keyword Execute. If you are using MS Access 2.0, place square brackets
[ ] around the function name.
Parameters
Table 35 shows the parameters for this API.
Table 35. Export parameters
Name Description
LastRow The last row you want to include in the export, or -1 if all rows
are included.
LastCol The last column that you want to include in the export, or -1
if all columns are included.
IncludeColHeadings Use nonzero to include the column headings in the first row
and zero to not include them.
FileName A string containing the name of the file to which you want to
write the export.
DateTimeFormat Optionally, the format to use for date and time values. Valid
values are 0 (ISO format), 1 (USA format), 2 (EUR format), 3
(JIS format), or 4 (Windows Control Panel format). The
default value is 4.
Value Meaning
1 (RSEF_HTML) The output file will be written in HTML (Hyper Text Markup
Language) format, and the data will be organized in an
HTML table.
Value Meaning
Value Meaning
310 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information. If the result set is empty or no rows have been retrieved from the
database, nonzero is returned unless FirstRow = 0, and LastRow = -1. In this
case, zero is returned and an empty file is written.
Related topics
CopyToClipboard()
B.19 ExportForm()
short ExportForm(BSTR OwnerAndName, BSTR FileName)
Description
This function exports the specified QMF form to the specified file.
Parameters
Table 39 shows the parameters for this API.
Table 39. ExportForm parameters
Name Description
FileName A string containing the name of the file to which you want to
write the exported form.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
PrintReport()
B.20 ExportReport()
short ExportReport(long QueryID, short SourceType, BSTR Source, BSTR
OutputFileName, short PageLength, short PageWidth, BOOL
Description
This function creates a report for the specified query and writes it to a file.
You specify the formatting and layout for the report in a QMF form. The output
file is an ASCII text file with each line separated by a pair of carriage return
and line feed characters, and each page separated by a form feed character.
It is best to view the output file using a fixed-pitch font.
Parameters
Table 40 shows the parameters for this API.
Table 40. ExportReport parameters
Name Description
OutputFileName The name of the file to which you want to write the report.
IncludeDateTime Nonzero specifies that the date and time is included at the
bottom of each page. Zero specifies that the date and time is
not included.
312 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Name Description
Value Meaning
1 (RSF_DATABASE) Use a form from the database. Specify the form owner and
name (Owner.Name) in the FormName parameter. To use a
form located on a different database server, first use
ExportForm() to export the form to a file and then specify a
SourceType of RSF_FILE.
2 (RSF_FILE) Use the form contained in a file. Specify the filename in the
FormName parameter.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
ExportForm()
B.21 FastSaveData()
short FastSaveData(long QueryID, BOOL Replace, BSTR TableName, BSTR
TableSpaceName, [VARIANT Comment])
Description
This function runs the query specified by QueryID and saves the results of
that query in the specified table in the specified table space. The query is run
and the data is saved directly into the specified table at the database server.
You can use this function to save rows that have not been retrieved from the
database. If the specified table already exists, the new data must have the
same number and types of columns as the existing table.
This function operates in a separate unit of work than other API functions,
and its results are automatically committed. Calling Commit() or Rollback()
will have no effect on changes made by this function.
Parameters
Table 42 shows the parameters for this API.
Table 42. FastSaveData parameters
Name Description
Replace Use nonzero if you want the specified data to replace any
existing data in the table. Use zero if you want the specified
data to be appended to any existing data in the table.
TableName The name of the table in which you want to store the data. If
the table does not exist, QMF for Windows will create it.
TableSpaceName The name of the table space in which the table exists or will
be created. If TableSpaceName is NULL or an empty string,
QMF for Windows will use the default table space. If you
have configured QMF for Windows to always use the default
table space, this parameter is ignored. See
RSR_SDDIFFERENTTS in the description for
GetResourceLimit().
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.22 FetchNextRow()
short FetchNextRow(long QueryID, VARIANT* Row)
314 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Description
This function fetches the next row of data from the database.
Parameters
Table 43 shows the parameters for this API.
Table 43. FetchNextRow parameters
Name Description
Row A pointer to a VARIANT in which the result will be stored. The result is
an array (variant type VT_ARRAY | VT_VARIANT) containing one value
for each column in the row. Call GetColumnCount() to determine the
number of values in the array. Each value is specified in either its native
data type or the closest variant data type. The supported return types
are: string (variant type VT_BSTR), float (variant type VT_R4), double
(variant type VT_R8), short (variant type VT_I2), long (variant type
VT_I4), and binary (variant type VT_UI1 | VT_ARRAY).When the end of
the result set has been reached (there are no more rows to fetch) or if
the result set is empty, the result is empty (variant type VT_EMPTY)
instead of an array.You must properly initialize the VARIANT before
calling this function. Visual Basic does this automatically. Visual C++
programmers must call VariantInit().
Note
Due to a bug in Microsoft Excel 7.0 and Microsoft Access 7.0 (and possibly
other 32-bit Microsoft products that use Visual Basic for Applications),
string data in Variant variables received from QMF for Windows may not be
translated from Unicode (used by OLE) to ANSI (used by VBA). When this
occurs, only the first character of the string is displayed. To remedy this
problem, set the variable equal to an empty string before you call the QMF
for Windows function that uses the variable.
Return value
Zero if successful, nonzero if unsuccessful. When the end of the result set is
reached, the return value is -1. If the return value is nonzero, you can call
GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
FetchNextRows()
Description
This function fetches the next row of data from the database. You can use this
function in environments that do not support VARIANT arrays, such as
Microsoft Access 2.0. Use this function in conjunction with GetColumnValue()
to retrieve the data in each column for the current row.
Parameters
Table 44 shows the parameters for this API.
Table 44. FetchNextRowEx parameters
Name Description
Return value
Zero if successful, nonzero if unsuccessful. When the end of the result set is
reached, the return value is -1. If the return value is nonzero, you can call
GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
FetchNextRowsEx()
B.24 FetchNextRows()
short FetchNextRows(long QueryID, VARIANT* Rows, long* NumRows)
Description
This function fetches the next NumRows rows of data from the database.
Parameters
Table 45 shows the parameters for this API.
Table 45. FetchNextRows parameters
Name Description
316 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Name Description
Rows A pointer to a VARIANT in which the result will be stored. The result is
a two dimensional array (variant type VT_ARRAY | VT_VARIANT)
containing one value for each column in each row. Call
GetColumnCount() to determine the number of columns in the array.
The dimensions of the array are [NumRows][ColumnCount], even if
the number of unfetched rows in the result set is less than NumRows
(in this case, the array will contain extra, unused entries).
Each value is specified in either its native data type or the closest
variant data type. The supported return types are: string (variant type
VT_BSTR), float (variant type VT_R4), double (variant type VT_R8),
short (variant type VT_I2), long (variant type VT_I4), and binary
(variant type VT_UI1 | VT_ARRAY).
When the end of the result set has been reached (there are no more
rows to fetch) or if the result set is empty, the result is empty (variant
type VT_EMPTY) instead of an array.
You must properly initialize the VARIANT before calling this function.
Visual Basic does this automatically. Visual C++ programmers must
call VariantInit().
Note
Due to a bug in Microsoft Excel 7.0 and Microsoft Access 7.0 (and
possibly other 32-bit Microsoft products that use Visual Basic for
Applications), string data in Variant variables received from QMF for
Windows may not be translated from Unicode (used by OLE) to ANSI
(used by VBA). When this occurs, only the first character of the string is
displayed. To remedy this problem, set the variable equal to an empty
string before you call the QMF for Windows function that uses the
variable.
Return value
Zero if successful, nonzero if unsuccessful. When the end of the result set is
reached, the return value is -1. If the return value is nonzero, you can call
GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
FetchNextRow()
Description
This function fetches the next NumRows rows of data from the database. You
can use this function in environments that do not support VARIANT arrays,
such as Microsoft Access 2.0. Use this function in conjunction with
GetColumnValueEx() to retrieve the data in each column for a given row.
Parameters
Table 46 shows the parameters for this API.
Table 46. FetchNextRowsEx parameters
Name Description
Return value
Zero if successful, nonzero if unsuccessful. When the end of the result set is
reached, the return value is -1. If the return value is nonzero, you can call
GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
FetchNextRowEx()
B.26 FlushQMFCache()
void FlushQMFCache()
Description
This function tells QMF for Windows to flush its cache of QMF information,
discarding its contents. The next time QMF for Windows needs QMF
information it obtains it from the database. Normally, QMF Windows caches
QMF information obtained from the database to reduce database traffic and
improve performance. You call this function prior to calling
GetQMFObjectInfo(), GetQMFQueryText(), or GetQMFObjectList() to ensure
that the information returned by these functions is up to date.
318 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Return value
None.
B.27 GetColumnCount()
long GetColumnCount(long QueryID)
Description
This function returns the number of columns in the result set.
Parameters
Table 47 shows the parameters for this API.
Table 47. GetColumnCount parameters
Name Description
Return value
The number of columns in each row if successful. If unsuccessful, 0 or -1. If
the return value is 0 or -1, you can call GetLastErrorString(),
GetLastErrorType(), GetLastSQLCode(), GetLastSQLError(), or
GetLastSQLState() to get additional error information.
B.28 GetColumnDataValue()
short GetColumnDataValue(long QueryID, long Index )
Description
This function returns the data value for the column specified in Index for the
current row of data. After calling this function, the Value property can be
interrogated for the returned value. You use this function with
FetchNextRowEx() to access the data in a single row of data.
Parameters
Table 48 shows the parameters for this API.
Table 48. GetColumnDataValue parameters
Name Description
B.29 GetColumnHeader()
BSTR GetColumnHeader(long QueryID, long Index, short* Result)
Description
This function returns the column header (column name) associated with the
index Index.
Parameters
Table 49 shows the parameters for this API.
Table 49. GetColumnHeader parameters
Name Description
Note
Column headings are not available for static SQL statements. For query
IDs returned from InitializeStaticQuery(), GetColumnHeader() returns a
string of the form Coln where n is the column number.
Return value
The string returned represents the column name as specified in the Index
parameter.
B.30 GetColumnHeaderEx()
short GetColumnHeaderEx(long QueryID, long Index)
320 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Description
This function retrieves the column header (column name) associated with the
index Index. After calling this function, the Value property can be interrogated
for the returned value.
Parameters
Table 50 shows the parameters for this API.
Table 50. GetColumnHeaderEx parameters
Name Description
Note
Column headings are not available for static SQL statements. For query
IDs returned from InitializeStaticQuery(), GetColumnHeaderEx() will
return a string of the form Coln where n is the column number.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is zero, query
the Value property for the string representing the column name. If the return
value is nonzero, you can call GetLastErrorString(), GetLastErrorType(),
GetLastSQLCode(), GetLastSQLError(), or GetLastSQLState() to get
additional error information.
B.31 GetColumnHeadings()
short GetColumnHeadings(long QueryID, VARIANT* Headings)
Description
This function returns the column headings (also referred to as column
names).
Parameters
Table 51 shows the parameters for this API.
Table 51. GetColumnHeadings parameters
Name Description
Note
Due to a bug in Microsoft Excel 7.0 and Microsoft Access 7.0 (and possibly
other 32-bit Microsoft products that use Visual Basic for Applications),
string data in Variant variables received from QMF for Windows may not be
translated from Unicode (used by OLE) to ANSI (used by VBA). When this
occurs, only the first character of the string is displayed. To remedy this
problem, set the variable equal to an empty string before you call the QMF
for Windows function that uses the variable.
Note
Column headings are not available for static SQL statements. For query
IDs returned from InitializeStaticQuery(), GetColumnHeadings() will
return the strings Col1, Col2, etc.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.32 GetColumnValue()
short GetColumnValue(long QueryID, long Index, VARIANT* Value)
Description
This function returns the data value for the column specified in Index for the
current row of data. You use this function with FetchNextRowEx() to access
the data in a single row of data.
322 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Parameters
Table 52 shows the parameters for this API.
Table 52. GetColumnValue parameters
Name Description
Value A pointer to a VARIANT in which you want to store the results. The result
is a data value based on the variant type.You must properly initialize the
VARIANT before calling this function. Visual Basic does this
automatically. Visual C++ programmers must call VariantInit().
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.33 GetColumnValueEx()
short GetColumnValueEx(long QueryID, long RowIndex, long ColIndex,
VARIANT* Value)
Description
This function returns the data value for the column specified in ColIndex for
the row of data specified in RowIndex. You use this function with
FetchNextRowsEx() to access the data in a single row of data
Parameters
Table 53 shows the parameters for this API.
Table 53. GetColumnValueEx parameters
Name Description
Value A pointer to a VARIANT in which you want to store the result. You can
query the resulting variant to find out the data type for further
processing.You must properly initialize the VARIANT before calling this
function. Visual Basic does this automatically. Visual C++ programmers
must call VariantInit().
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.34 GetDefaultServerName()
BSTR GetDefaultServerName()
Description
This function returns a string containing the default server name.
Return value
A string that specifies the default server name.
B.35 GetGlobalVariable()
BSTR GetGlobalVariable(BSTR Name)
Description
This function retrieves the value of the specified global variable.
Parameters
Table 54 shows the parameters for this API.
Table 54. GetGlobalVariable parameters
Name Description
Name A string that contains the name of the variable you want to set.
Return value
A string containing the global variable value, or NULL if the variable has no
value or an error occurs.
324 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
B.36 GetHostVariableNames()
short GetHostVariableNames(long QueryID, VARIANT* Names)
Description
This function returns an array of the names of all host variables referenced in
the specified query. The query must be a static query referencing host
variables (either stored with the QMF query or created by AddHostVariable()).
Parameters
Table 55 shows the parameters for this API.
Table 55. GetHostVariableNames parameters
Name Description
Names A pointer to a VARIANT in which you want to store the result array.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() to get additional error information.
B.37 GetHostVariableTypeNames()
short GetHostVariableTypeNames(long QueryID, VARIANT* TypeNames)
Description
This function returns an array of the strings describing the data types of all
host variables referenced in the specified query. The query must be a static
query referencing host variables (either stored with the QMF query or created
by AddHostVariable()).
Parameters
Table 56 shows the parameters for this API.
Table 56. GetHostVariableTypeNames parameters
Name Description
B.38 GetHostVariableTypes()
short GetHostVariableTypes(long QueryID, VARIANT* Types)
Description
This function returns an array of the data types of all host variables
referenced in the specified query. The query must be a static query
referencing host variables (either stored with the QMF query or created by
AddHostVariable()). See AddHostVariable() for a list of the data types that
can be returned.
Parameters
Table 57 shows the parameters for this API.
Table 57. GetHostVariableTypes parameters
Name Description
Types A pointer to a VARIANT in which you want to store the result array.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() to get additional error information.
B.39 GetLastErrorString()
BSTR GetLastErrorString()
Description
This function returns a string containing information about the most recent
error. If you call this function after a function that executed successfully (with
no errors), then this function returns information about the last error that
occurred during a prior function call. To avoid confusion, always call this
function immediately after calling a function that returned an error.
Return value
A string containing error information. If no errors occurred since you created
the QMF for Windows API object, NULL is returned.
326 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Related topics
GetLastErrorType(), GetLastSQLCode(), GetLastSQLError(),
GetLastSQLState()
B.40 GetLastErrorType()
short GetLastErrorType()
Description
This function returns the type of the most recent error. If you call this function
after a function that executed successfully (with no errors), then this function
returns information about the last error that occurred during a prior function
call. To avoid confusion, always call this function immediately after calling a
function that returned an error.
Return value
The number returned indicates the type of error. Table 58 shows the error
types number and their meaning.
Table 58. GetLastErrorType - error types
Value Meaning
Related topics
GetLastErrorString(), GetLastSQLCode(), GetLastSQLError(),
GetLastSQLState()
B.41 GetLastSQLCode()
long GetLastSQLCode()
Description
This function returns the SQL code for the most recent error. If you call this
function after a function that executed successfully (with no errors), then this
function returns information about the last error that occurred during a prior
function call. To avoid confusion, always call this function immediately after
calling a function that returned an error.
Return value
The SQL code for the most recent error. If no errors occurred since you
created the QMF for Windows API object, or the most recent error was not an
SQL error, zero is returned.
328 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Related topics
GetLastErrorString(), GetLastErrorType(), GetLastSQLError(),
GetLastSQLState()
B.42 GetLastSQLError()
VARIANT GetLastSQLError()
Description
This function returns detailed SQL error information for the most recent error.
If you call this function after a function that executed successfully (with no
errors), then this function returns information about the last error that
occurred during a prior function call. To avoid confusion, always call this
function immediately after calling a function that returned an error.
Return value
An array (variant type VT_ARRAY | VT_VARIANT) containing error
information. If no errors occurred since you created the QMF for Windows
API object, or the most recent error was not an SQL error, empty (variant type
VT_EMPTY) is returned. The array format is shown in Table 59.
Table 59. Format of the array returned by the GetLastSQLError API
Related topics
GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLState()
B.43 GetLastSQLState()
BSTR GetLastSQLState()
Description
This function returns the SQL state for the most recent error. If you call this
function after a function that executed successfully (with no errors), then this
function returns information about the last error that occurred during a prior
function call. To avoid confusion, always call this function immediately after
calling a function that returned an error.
Return value
A string containing the SQL code for the most recent error. If no errors
occurred since you created the QMF for Windows API object, or the most
recent error was not an SQL error, NULL is returned.
Related topics
GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError()
330 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
B.44 GetOption()
short GetOption(short Option, VARIANT* Value)
Description
Gets the specified option value in QMF for Windows.
Parameters
Table 60 shows the parameters for this API.
Table 60. GetOption parameters
Name Description
Value A pointer to a VARIANT in which the result is stored. You must properly
initialize the VARIANT before calling this function. Visual Basic does this
automatically. Visual C++ programmers must call VariantInit().
Value Meaning
Note
Due to a bug in Microsoft Excel 7.0 and Microsoft Access 7.0 (and possibly
other 32-bit Microsoft products that use Visual Basic for Applications),
string data in Variant variables received from QMF for Windows may not be
translated from Unicode (used by OLE) to ANSI (used by VBA). When this
occurs, only the first character of the string is displayed. To remedy this
problem, set the variable equal to an empty string before you call the QMF
for Windows function that uses the variable.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
Related topics
SetOption()
B.45 GetOptionEx()
short GetOptionEx(short Option)
Description
Gets the specified option value in QMF for Windows. When the option value
is returned, you must query the Option property for the data.
Parameters
Table 62 shows the parameters for this API.
Table 62. GetOptionEx parameters
Name Description
Option The option values are the same as those for the GetOption() call.
332 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
Related topics
GetOption(), SetOption()
B.46 GetProcText()
BSTR GetProcText(long ProcID)
Description
This function returns the text that is executed for the specified procedure,
after variable substitution. You should use SetProcVariable() to set the value
of any variables used in the procedure before calling this function.
Parameters
Table 63 shows the parameters for this API.
Table 63. GetProcText parameters
Name Description
Return value
If successful, a string containing the procedure text is returned. If
unsuccessful, NULL is returned. If the return value is NULL, you can call
GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.47 GetProcVariables()
short GetProcVariables(long ProcID, VARIANT* Variables)
Description
This function returns an array of the names of the all of the variables in the
procedure's text. You must assign values to these variables by calling
SetProcVariable() prior to running the procedure using RunProc().
Name Description
Note
Due to a bug in Microsoft Excel 7.0 and Microsoft Access 7.0 (and possibly
other 32-bit Microsoft products that use Visual Basic for Applications),
string data in Variant variables received from QMF for Windows may not be
translated from Unicode (used by OLE) to ANSI (used by VBA). When this
occurs, only the first character of the string is displayed. To remedy this
problem, set the variable equal to an empty string before you call the QMF
for Windows function that uses the variable.
Return value
Zero if successful, nonzero if unsuccessful. If there are no variables in the
procedure, the return value is RS_ERROR_NO_DATA (-1). If the return value
is nonzero, you can call GetLastErrorString() or GetLastErrorType() to get
additional error information.
B.48 GetQMFObjectInfo()
short GetQMFObjectInfo(BSTR OwnerAndName, short Type, short Time,
VARIANT* Value)
Description
This function returns information about a QMF object (either a form or a
query). The information returned is specified by the Type and Time
parameters.
334 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Parameters
Table 65 shows the parameters for this API.
Table 65. GetQMFObjectInfo parameters
Name Description
Note
Due to a bug in Microsoft Excel 7.0 and Microsoft Access 7.0 (and possibly
other 32-bit Microsoft products that use Visual Basic for Applications),
string data in Variant variables received from QMF for Windows may not be
translated from Unicode (used by OLE) to ANSI (used by VBA). When this
occurs, only the first character of the string is displayed. To remedy this
problem, set the variable equal to an empty string before you call the QMF
for Windows function that uses the variable.
Value Meaning
0 (RSI_COMMENT) Comment
1 (RSI_LEVEL) Level
2 (RSI_TYPE) Type
4 (RSI_RESTRICTED) Restricted
5 (RSI_MODEL) Model
Value Meaning
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.49 GetQMFObjectInfoEx()
short GetQMFObjectInfoEx(BSTR OwnerAndName, short Type, short Time)
Description
This function returns information about a QMF object. The information
returned is specified by the Type and Time parameters. After calling this
function, the QMFObjectInfo property can be interrogated for the returned
value.
336 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Parameters
Table 68 shows the parameters for this API.
Table 68. GetQMFObjectInfoEx parameters
Name Description
Value Meaning
0 (RSI_COMMENT) Comment.
1 (RSI_LEVEL) Level.
2 (RSI_TYPE) Type.
4 (RSI_RESTRICTED) Restricted.
5 (RSI_MODEL) Model
Value Meaning
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.50 GetQMFObjectList()
short GetQMFObjectList(BSTR Owner, BSTR Name, short Type, VARIANT*
List)
Description
This function returns an array of the names of all QMF objects matching the
patterns specified in the Owner and Name parameters.
Parameters
Table 71 shows the parameters for this API.
Table 71. GetQMFObjectList parameters
Name Description
Owner A string containing the owner of the objects you want to include in the
returned list. To include all objects regardless of the owner this parameter
was to be left blank or contain the "%" caracter.
Name A string containing the name of the objects you want to include in the
returned list. To include all objects regardless of the name this parameter
was to be left blank or contain the "%" caracter.
Type Specifies the types of QMF objects you want to include in the list. These
values can be added together to specify multiple object types
338 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Name Description
List A pointer to a VARIANT in which the result are stored. The result is an
array of strings (variant type VT_ARRAY | VT_BSTR), each of the format
Owner.Name. If no matching QMF queries are found, the result is empty
(variant type VT_EMPTY). You must properly initialize the VARIANT
before calling this function. Visual Basic does this automatically. Visual
C++ programmers must call VariantInit().
Note
Due to a bug in Microsoft Excel 7.0 and Microsoft Access 7.0 (and possibly
other 32-bit Microsoft products that use Visual Basic for Applications),
string data in Variant variables received from QMF for Windows may not be
translated from Unicode (used by OLE) to ANSI (used by VBA). When this
occurs, only the first character of the string is displayed. To remedy this
problem, set the variable equal to an empty string before you call the QMF
for Windows function that uses the variable.
Value Meaning
Return value
Zero if successful, nonzero if unsuccessful. If no matching QMF objects are
found, the return value is zero. If the return value is nonzero, you can call
GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.51 GetQMFObjectListEx()
short GetQMFObjectListEx(BSTR Owner, BSTR Name, short Type, short
Index)
Parameters
Table 73 shows the parameters for this API.
Table 73. GetQMFObjectListEx parameters
Name Description
Owner A string containing the owner of the objects you want to include in the
returned list.
Name A string containing the name of the objects you want to include in the
returned list.
Type Specifies the types of QMF objects you want to include in the list.
These values can be added together to specify multiple object types
Index The index of the list of QMF objects that match the pattern.
Value Meaning
Return value
Zero if successful, nonzero if unsuccessful. If no matching QMF objects are
found, the return value is RS_ERROR_OUTOFRANGE. If the return value is
nonzero, you can call GetLastErrorString(), GetLastErrorType(),
GetLastSQLCode(), GetLastSQLError(), or GetLastSQLState() to get
additional error information.
B.52 GetQMFProcText()
BSTR GetQMFProcText(BSTR OwnerAndName)
340 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Description
This function retrieves the text stored in the specified procedure.
Parameters
Table 75 shows the parameters for this API.
Table 75. GetQMFProcText parameters
Name Description
Return value
A string containing the text for the procedure that was retrieved, or NULL if
the procedure could not be retrieved. If the return value is NULL, you can call
GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.53 GetQMFQueryText()
BSTR GetQMFQueryText(BSTR OwnerAndName)
Description
This function retrieves the SQL text stored in the specified query.
Parameters
Table 76 shows the parameters for this API.
Table 76. GetQMFQueryText parameters
Name Description
Return value
A string containing the text for the query that was retrieved, or NULL if the
query could not be retrieved. If the return value is NULL, you can call
GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.54 GetQueryText()
BSTR GetQueryText(long QueryID)
Parameters
Table 77 shows the parameters for this API.
Table 77. GetQueryText parameters
Name Description
Note
The query text is not available for static SQL statements. For query IDs
returned from InitializeStaticQuery(), GetQueryText() returns an empty
string.
Return value
If successful, a string containing the SQL text is returned. If unsuccessful,
NULL is returned. If the return value is NULL, you can call
GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.55 GetQueryVerb()
BSTR GetQueryVerb(long QueryID)
Description
This function returns a string containing the SQL verb you used in the query.
Parameters
Table 78 shows the parameters for this API.
Table 78. GetQueryVerb parameters
Name Description
342 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Note
The query verb is not available for static SQL statements. For query IDs
returned from InitializeStaticQuery(), GetQueryVerb() returns an empty
string.
Return value
If the query is successful, a string containing the SQL verb is returned. If the
query is unsuccessful, NULL is returned. If the return value is NULL, you can
call GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.56 GetResourceLimit()
short GetResourceLimit(short Resource, long* Value)
Description
This function gets the requested resource limit. You must call
InitializeServer() prior to calling this function, since resource limits are
handled on a per-server basis.
Parameters
Table 79 shows the parameters for this API.
Table 79. GetResourceLimit parameters
Name Description
Resource The valid values for this parameter are shown in Table 80
Value A pointer to a long in which the result is stored. The result is the value of
the requested resource limit. For boolean values, the result is non-zero
for true, zero for false. For RSR_SAVE_DATA_TABLE_SPACE_NAME,
RSR_DEF_COLLECTION, and RSR_ACCOUNT_STRING, -1 is
returned and the ResourceLimit property can be interrogated for the
returned string value.
Value Meaning
344 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Value Meaning
346 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Value Meaning
B.57 GetResourceLimitEx()
short GetResourceLimitEx(short Resource)
Description
This function gets the requested resource limit. You must call
InitializeServer() prior to calling this function, since resource limits are
handled on a per-server basis. After a call to this function, query the
ResourceLimit property for the result.
Parameters
Table 81 shows the parameters for this API.
Table 81. GetResourceLimitEx parameters
Name Description
Resource The resource values are the same as those for the GetResourceLimit()
call. This values are shown in Table 80
Value A pointer to a long in which the result is stored. The result is the value
of the requested resource limit. For boolean values, the result is
non-zero for true, zero for false. For
RSR_SAVE_DATA_TABLE_SPACE_NAME,
RSR_DEF_COLLECTION, and RSR_ACCOUNT_STRING, -1 is
returned and the ResourceLimit property can be interrogated for the
returned string value.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.58 GetRowCount()
long GetRowCount(long QueryID)
Description
This function returns the number of rows currently in QMF for Windows's
internal buffer. This may be greater than the number of rows retrieved with
348 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
FetchNextRow() or FetchNextRows(), since QMF for Windows buffers data
received from the database.
This function returns the number of rows already retrieved from the database.
If you want to retrieve the total number of rows in the result set, you can:
• Call CompleteQuery() and fetch all the rows using FetchNextRow() or
FetchNextRows().
• Specify FetchAllRows = TRUE when you call Open().
Parameters
Table 82 shows the parameters for this API.
Table 82. GetRowCount parameters
Name Description
Return value
The number of rows if successful (0 if no rows have been retrieved), or -1 if
unsuccessful. If -1, you can call GetLastErrorString() or GetLastErrorType()
to get additional error information.
B.59 GetServerList()
short GetServerList(VARIANT* List)
Description
This function returns an array containing the names of the database servers
defined in QMF for Windows's Server Definition File (SDF). You must define a
database server in the SDF file if you want to access it using the QMF for
Windows API.
Name Description
Note
Due to a bug in Microsoft Excel 7.0 and Microsoft Access 7.0 (and possibly
other 32-bit Microsoft products that use Visual Basic for Applications),
string data in Variant variables received from QMF for Windows may not be
translated from Unicode (used by OLE) to ANSI (used by VBA). When this
occurs, only the first character of the string is displayed. To remedy this
problem, set the variable equal to an empty string before you call the QMF
for Windows function that uses the variable.
Return value
Zero if successful, nonzero if unsuccessful. If you have not defined any
database servers, the return value is zero. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.60 GetServerListEx()
short GetServerListEx(short Index)
Description
This function retrieves the name of the server referenced by the Index
parameter. After calling this function, the Value property can be interrogated
for the returned value.
350 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Parameters
Table 84 shows the parameters for this API.
Table 84. GetServerListEx parameters
Name Description
Return value
Zero if successful, RS_ERROR_OUTOFRANGE when the index is greater
than the number of servers available, nonzero if unsuccessful. If you have not
defined any database servers, the return value is
RS_ERROR_OUTOFRANGE. If the return value is nonzero, you can call
GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.61 GetStoredProcedureResultSets()
short GetStoredProcedureResultSets(long QueryID, VARIANT* ResultSets)
Description
This function retrieves the query IDs for the result sets returned by the stored
procedure executed with the original QueryID. Each query ID returned can be
used with FetchNextRow() or FetchNextRows() to retrieve the result set rows,
and Close() when the end of each result set is reached.
Parameters
Table 85 shows the parameters for this API.
Table 85. GetStoredProceduresResultSets parameters
Name Description
ResultSets A pointer to a VARIANT in which the query IDs for the result sets are
stored. The result is an array of long integers (variant type
VT_ARRAY | VT_I4), with each integer being the query ID for the
corresponding result sets. If the stored procedure did not return any
result sets, the result is empty (variant type VT_EMPTY). You must
properly initialize the VARIANT before calling this function. Visual
Basic does this automatically. Visual C++ programmers must call
VariantInit().
B.62 GetVariables()
short GetVariables(long QueryID, VARIANT* Variables)
Description
This function returns an array of the names of the all of the variables in the
query's SQL text. You must assign values to these variables by calling
SetVariable() prior to running the query using either Open() or Execute().
Parameters
Table 86 shows the parameters for this API.
Table 86. GetVariables parameters
Name Description
Variables A pointer to a VARIANT in which the result is stored. The result is an array
of strings (variant type VT_ARRAY | VT_BSTR), with each string
containing the name of one variable. If there are no variables in the SQL
statement, the result is empty (variant type VT_EMPTY). You must
properly initialize the VARIANT before calling this function. Visual Basic
does this automatically. Visual C++ programmers must call VariantInit().
Note
Due to a bug in Microsoft Excel 7.0 and Microsoft Access 7.0 (and possibly
other 32-bit Microsoft products that use Visual Basic for Applications),
string data in Variant variables received from QMF for Windows may not be
translated from Unicode (used by OLE) to ANSI (used by VBA). When this
occurs, only the first character of the string is displayed. To remedy this
problem, set the variable equal to an empty string before you call the QMF
for Windows function that uses the variable.
Return value
Zero if successful, nonzero if unsuccessful. If there are no variables in the
SQL statement, the return value is RS_ERROR_NO_DATA (-1). If the return
value is nonzero, you can call GetLastErrorString() or GetLastErrorType() to
get additional error information.
352 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
B.63 GetVariablesEx()
short GetVariablesEx(long QueryID, short Index)
Description
This function returns the name of the variable in the query's SQL text
referenced by the Index parameter. After calling this function, the Value
property can be interrogated for the returned value. You must assign values
to this variable (and all others in the SQL text) by calling SetVariable() prior to
running the query using either Open() or Execute().
Parameters
Table 87 shows the parameters for this API.
Table 87. GetVariablesEx parameters
Name Description
Index An index into the internal list of variables. Query the Value property for
the string that corresponds with the index passed in. If there are no
variables in the SQL statement, the function will return
RS_ERROR_NO_DATA.
Return value
Zero if successful, nonzero if unsuccessful. If there are no variables in the
SQL statement, the return value is RS_ERROR_NO_DATA (-1). If the return
value is nonzero, you can call GetLastErrorString() or GetLastErrorType() to
get additional error information.
B.64 InitializeProc()
long InitializeProc(short SourceType, BSTR Source)
Description
This function sets the text that you want to use in a procedure. You can pass
the text as a parameter to this function, read it from a text file, or obtain it
from an existing procedure.
Name Description
Source A string containing the text, the owner and name (Owner.Name) of the
procedure, or the name of a file containing the procedure text.
Value Meaning
Return value
If successful, the ID of the procedure (ProcID). If unsuccessful, -1. You must
use this value in all interface calls that require the ProcID parameter.
B.65 InitializeQuery()
long InitializeQuery(short SourceType, BSTR Source)
Description
This function sets the SQL text that you want to use in a query. You can pass
the SQL text as a parameter to this function, read it from a text file, or obtain
it from an existing query. Call Close() when you are finished with the query.
Parameters
Table 90 shows the parameters for this API.
Table 90. InitializeQuery parameters
Name Description
354 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Name Description
Source A string containing the SQL text, the owner and name
(Owner.Name) of the query, or the name of a file containing SQL
text.
Value Meaning
1 (RSS_QMFQUERY) The SQL text is contained in the query whose owner and
name are specified by the Source parameter.
2 (RSS_FILE) The SQL text is contained in the text file whose name is
specified by the Source parameter.
Return value
If successful, the ID of the query. If unsuccessful, -1. You must use this value
in all interface calls that require the QueryID parameter.
B.66 InitializeServer()
short InitializeServer(BSTR ServerName, BSTR UserID, BSTR Password,
BOOL ForceDialog, [VARIANT Account], [VARIANT SuppressDialog])
Description
This function initializes a connection to a database server. You must call this
function prior to calling any other function in the QMF for Windows API. You
can call this function multiple times. However, if you call this function and do
not end by calling Commit() or Rollback() an implicit rollback results.
Parameters
Table 92 shows the parameters for this API.
Table 92. InitializeServer parameters
Name Description
ServerName A string containing the name of the database server that you want
to use. This name must match one of the names defined in QMF
for Windows's Server Definition File. Call GetServerList() to
retrieve a list of valid servers.
UserID A string containing the User ID you want to use. If UserID is NULL
or an empty string, QMF for Windows will attempt to use the
UserID from the most recent query, if available. Otherwise, QMF
for Windows will display the User Information Dialog box to obtain
a User ID and password.
Password A string containing the password for the specified user ID. If
Password is NULL or an empty string, QMF for Windows will try to
use a memorized password if available (requires Windows For
Workgroups). If no password is available, QMF for Windows will
display the User Information dialog box to obtain a password.
ForceDialog Nonzero indicates that QMF for Windows will display the User
Information dialog box regardless of whether a UserID and
Password were specified. This gives the user a chance to change
the information before it is used. Zero indicates that QMF for
Windows should display the User Information dialog box only
when necessary.
SuppressDialog Nonzero indicates that QMF for Windows will never display the
User Information dialog box, even if a user ID and password have
not been specified. In this case, an error is returned indicating that
no user ID and password were specified. This option is useful
when executing in an environment where no user is present to
respond to the User Information dialog box, for example, on a web
server.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
SetParent()
B.67 InitializeStaticQuery()
long InitializeStaticQuery(BSTR CollectionName, BSTR PackageName,
BSTR ConsistencyToken, short SectionNumber)
356 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Description
This function specifies the section of a package that you want to run as a
static query.
Parameters
Table 93 shows the parameters for this API.
Table 93. InitializeStaticQuery parameters
Name Description
ConsistencyToken The token used by the above named collection and package.
SectionNumber The section number of the statement within the collection and
package you want to run.
Return value
If successful, the ID of the query. If unsuccessful, -1. You must use this value
in all interface calls that require the QueryID parameter.
B.68 IsStatic()
BOOL IsStatic(long QueryID)
Description
This function determines whether or not the specified query ID refers to a
static query or a dynamic query.
Parameters
Table 94 shows the parameters for this API.
Table 94. IsStatic parameters
Name Description
Return value
Returns nonzero if successful and QueryID refers to a static query, zero
otherwise.
Description
Use this function to run a query that uses the SELECT verb, by opening a
cursor in the database for the query. Use FetchNextRow() or
FetchNextRows() to retrieve the data for the query, and call Close() when you
are done. If QMF for Windows is configured to automatically fetch all rows
(see RSR_AUTOFETCHALLROWS in the description for
GetResourceLimit()) or the FetchAllRows parameter is nonzero, QMF for
Windows fetches all rows of the result set into its internal buffer before
returning from this call.
Note
The name of this function conflicts with the Microsoft Access 2.0 keyword
Execute. If you are using MS Access 2.0, place square brackets [ ] around
the function name.
Note
Use this function only in statements that contain the SQL verb SELECT.
For statements containing any other verb, for example, SET, call Execute()
instead. To determine the verb used by a query, call GetQueryVerb().
Parameters
Table 95 shows the parameters for this API.
Table 95. Open parameters
Name Description
FetchAllRows A boolean value that indicates whether or not all rows in the result
set are automatically fetched into QMF for Windows's internal buffer.
If nonzero, all rows are automatically fetched, closing the cursor and
freeing the database for use by other users. This is the same as
calling CompleteQuery().
358 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.70 Prepare()
short Prepare(long QueryID)
Description
This function prepares the query specified by QueryID. The statement is
examined by the database server, checking for object existence, required
authorizations, etc. If the query is a SELECT statement, information about the
columns returned by the statement are available after completing Prepare().
Parameters
Table 96 shows the parameters for this API.
Table 96. Prepare parameters
Name Description
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
Execute(), Open()
B.71 PrintReport()
short PrintReport(long QueryID, short SourceType, BSTR Source, BSTR
OutputFileName, short PageLength, short PageWidth, BOOL
IncludeDateTime, BOOL IncludePageNumbers, [VARIANT Format],
[VARIANT UseFormPageSetup])
Description
PrintReport() is a synonym for the ExportReport() function.
Description
This function reinitializes the connection to a database server. Normally, you
only need to call this function if one of the other QMF for Windows API
functions returns an error. Calling this function results in an implicit rollback,
which closes any open cursors and invalidates all outstanding query IDs.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.73 Rollback()
short Rollback()
Description
This function cancels any changes made in the current unit of work, ends the
current unit of work, closes any open cursors, and invalidates all outstanding
query IDs.
Note
The name of this function conflicts with the Microsoft Access 2.0 keyword
Execute. If you are using MS Access 2.0, place square brackets [ ] around
the function name.
Note
The rollback only affects SQL changes that were run by calling Open() or
Execute(). Rollback does not affect changes made by other QMF for
Windows API functions, such as FastSaveData(), SaveData(), or
DeleteQMFObject().
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
360 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Related topics
Commit()
B.74 RunProc()
short RunProc(long ProcID)
Description
This function runs the specified procedure. The procedure runs to completion
or until an error occurs. You cannot access any of the results of the procedure
(for example, data from a query that was run) through this programming
interface. However, any files exported or data saved by the procedure are
available after the run.
Parameters
Table 97 shows the parameters for this API.
Table 97. RunProc parameters
Name Description
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.75 SaveData()
short SaveData(long QueryID, long FirstRow, long FirstCol, long LastRow,
long LastCol, BOOL Replace, BSTR TableName, BSTR TableSpaceName,
BSTR ServerName, BSTR UserID, BSTR Password, BOOL ForceDialog,
[VARIANT Account], [VARIANT Comment], [VARIANT CommitScope])
Description
This function saves the specified range of rows and columns into the
specified table in the specified table space. You must call CompleteQuery()
prior to calling this function if you have not retrieved row data for all of the
rows you want to save in the table. If you try to save rows that have not been
retrieved from the database, the save will fail. If the table already exists, the
new data must have the same number and types of columns as the existing
table.
Parameters
Table 98 shows the parameters for this API.
Table 98. SaveData parameters
Name Description
FirstRow The first row you want to include in the save. The value of a first
row in a result set is 0.
FirstCol The first column you want to include in the save. The value of
the first column in a result set is 0.
LastRow The last row you want to include in the save, or 1 if all rows are
included. The value of the last row in a result set is one less than
the total number of rows.
LastCol The last column that you want to include in the save, or -1 if all
columns are included. The value of the last column in a result
set is one less than the total number of columns.
Replace Nonzero indicates that the specified data will replace any
existing data in the table. Zero indicates that the specified data
will be appended to any existing data in the table.
TableName The name of the table in which the data will be stored. If the
table doesn't exist, it is created.
TableSpaceName The name of the table space in which the table exists or will be
created. If TableSpaceName is NULL or an empty string, the
default table space is used. If you have configured QMF for
Windows to always use the default table space (see
RSR_SDDIFFERENTTS in the description for
GetResourceLimit()), this parameter is ignored.
ServerName The name of the database server in which the table is stored. If
ServerName is NULL or an empty string, the server you specify
in the call to InitializeServer() is used, and UserID, Password,
ForceDialog, and Account are ignored.
362 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Name Description
CommitScope Optionally, how many rows to insert into the table at a time
before committing the unit of work. Specifying zero indicates
that all of the rows should be inserted before committing.
Specifying 10 (for example), indicates that a commit should be
performed after every ten rows are inserted.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
If the result set is empty or no rows are retrieved from the database, nonzero
is returned unless FirstRow = 0, and LastRow = -1. In this case, zero is
returned and an empty table is created.
B.76 SaveQMFProc()
short SaveQMFProc(BSTR OwnerAndName, BSTR Text, BSTR Comment,
BOOL Replace, BOOL Share)
Description
This function saves a procedure at a database server.
Name Description
Text A string containing the text that you want to save in the procedure.
Comment A string containing any comment you want to save with the
procedure. If there is no comment, pass this parameter as either
an empty string or NULL.
Share Nonzero shares the procedure with other users. Zero does not
share the procedure with other users.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.77 SaveQMFQuery()
short SaveQMFQuery(BSTR OwnerAndName, BSTR Text, BSTR Comment,
BOOL Replace, BOOL Share)
Description
This function saves a query at a database server.
Parameters
Table 100 shows the parameters for this API.
Table 100. SaveQMFQuery parameters
Name Description
364 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Name Description
Comment A string containing any comment you want to save with the query.
If there is no comment, pass this parameter as either an empty
string or NULL.
Replace Nonzero replaces an existing query with the same name. Zero
aborts the operation if there is an existing query with the same
name.
Share Nonzero shares the query with other users. Zero does not share
the query with other users.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.78 SetBindOption()
short SetBindOption(BSTR CollectionName, BSTR PackageName, short
Option, short Value)
Description
This function sets options for the collection and package prior to calling
EndBind().
Parameters
Table 101 shows the parameters for this API.
Table 101. SetBindOption parameters
Name Description
CollectionName The collection ID of the package for which you want to set the
option.
PackageName The name of the package for which you want to set the option.
Value One of the values listed below for the specified option.
366 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Option Meaning Values
Return value
Zero if successful, nonzero is unsuccessful. If the return value is nonzero,
you can call GetLastErrorString() or GetLastErrorType() to get additional
error information.
B.79 SetBindOwner()
short SetBindOwner(BSTR CollectionName, BSTR PackageName, BSTR
OwnerID)
Description
This function enables you to specify an owner different from your user ID for
the package you are binding. This may be necessary if your user ID does not
have the required authorizations to bind the package, but the specified owner
does.
Name Description
CollectionName The collection ID of the package for which you want to specify
the owner.
PackageName The name of the package for which you want to specify the
owner.
OwnerID The desired owner ID for the package you are binding.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
B.80 SetBusyWindowButton()
void SetBusyWindowButton(BSTR Text)
Description
This function specifies the text displayed on the busy window's Cancel
button.
Parameters
Table 104 shows the parameters for this API.
Table 104. SetBusyWindowButton parameters
Name Description
Text A string that specifies the text displayed on the busy window's Cancel
button. The default value is "Cancel". If you specify an empty string the
button is hidden. Regardless of the text you specify, the button always
cancels, or closes the window.
Return value
None.
Related topics
SetBusyWindowMessage(), SetBusyWindowMode(), SetBusyWindowTitle(),
ShowBusyWindow()
368 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
B.81 SetBusyWindowMessage()
void SetBusyWindowMessage(BSTR Message)
Description
This function specifies the text displayed in the busy window's message area.
Parameters
Table 105 shows the parameters for this API.
Table 105. SetBusyWindowMessage parameters
Name Description
Message A string that specifies the text displayed in the busy window's message
area.
Return value
None.
Related topics
SetBusyWindowButton(), SetBusyWindowMode(), SetBusyWindowTitle(),
ShowBusyWindow()
B.82 SetBusyWindowMode()
short SetBusyWindowMode(short Mode)
Description
This function determines whether or not QMF for Windows displays the busy
window. The busy window is useful to provide feedback to the user and to
enable the user to cancel a pending database action. Your changes take
effect the next time QMF for Windows performs an operation that causes the
busy window to display or hide.
Parameters
Table 106 shows the parameters for this API.
Table 106. SetBusyWindowMode parameters
Name Description
Mode Specifies when QMF for Windows displays the busy window.
Value Meaning
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
Related topics
SetBusyWindowButton(), SetBusyWindowMessage(), SetBusyWindowTitle(),
SetParent(), ShowBusyWindow()
B.83 SetBusyWindowTitle()
void SetBusyWindowTitle(BSTR Title)
Description
This function specifies the text displayed in the busy window's title bar.
Parameters
Table 108 shows the parameters for this API.
Table 108. SetBusyWindowTitle parameters
Name Description
Title A string that specifies the text displayed in the busy window's title bar.
Return value
None.
370 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Related topics
SetBusyWindowMode(), SetBusyWindowButton(),
SetBusyWindowMessage(), ShowBusyWindow()
B.84 SetGlobalVariable()
short SetGlobalVariable(BSTR Name, BSTR Value)
Description
This function assigns a value to the specified global variable. This value is
available for use in queries, forms, and procedures.
Parameters
Table 109 shows the parameters for this API.
Table 109. SetGlobalVariable parameters
Name Description
Name A string that contains the name of the variable you want to set.
Value A string that contains the value you want to assign to the specified
variable.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.85 SetHostVariable()
short SetGlobalVariable(long QueryID, VARIANT Index, VARIANT Value)
Description
This function assigns a value to the specified host variable referenced by the
query. The query must be a static query referencing host variables (either
stored with the QMF query or created by AddHostVariable()). Index can
specify either the numeric index of the host variable, or the name of the host
variable.
Name Description
Index Either a number (variant type VT_I2) specifying the index of the host
variable in the query, or a string (variant type VT_BSTR) specifying the
name of the host variable.
Value The value for the host variable. To specify a null value, the type of the
variant should be set to VT_EMPTY
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.86 SetOption()
short SetOption(short Option, VARIANT Value)
Description
This function sets the specified option value in QMF for Windows. For some
options, the changes may not take affect until QMF for Windows restarts.
Under normal conditions, you do not restart QMF for Windows until you have
destroyed all instances of the QMF for Windows API object.
Parameters
Table 111 shows the parameters for this API.
Table 111. SetOption parameters
Name Description
Value Meaning
372 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Value Meaning
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
Related topics
GetOption()
B.87 SetParent()
short SetParent(long ParentWnd)
Description
This function sets the parent window for dialogs. Normally, when QMF for
Windows displays a dialog (in the busy window or the User Information dialog
box), it is centered on and modal to QMF for Windows's main window. This
Parameters
Table 113 shows the parameters for this API.
Table 113. SetParent parameters
Name Description
ParentWnd The HWND of the new parent window. Specify NULL to use QMF for
Windows's main window as the parent.
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
Related topics
ShowBusyWindow()
B.88 SetProcVariable()
short SetProcVariable(long ProcID, BSTR Name, BSTR Value)
Description
This function assigns a value to the specified variable. This value is
substituted for the variable prior to running the procedure. If your procedure
has one or more variables in it, you must call this function to set the variable
values prior to calling RunProc().
Parameters
Table 114 shows the parameters for this API.
Table 114. SetProcVariable parameters
Name Description
Name A string that contains the name of the variable you want to set.
Value A string that contains the value you want to assign to the specified
variable.
374 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.89 SetVariable()
short SetVariable(long QueryID, BSTR Name, BSTR Value)
Description
This function assigns a value to the specified variable. This value is
substituted for the variable prior to running the SQL statement. If your SQL
statement has one or more variables in it, you must call this function to set
the variable values prior to calling either Open() or Execute().
This function has an effect only for dynamic queries. For static queries, you
should use the GetHostVariableNames(), AddHostVariable(), and
SetHostVariable() functions.
Parameters
Table 115 shows the parameters for this API.
Table 115. SetVariable parameters
Name Description
Name A string that contains the name of the variable you want to set.
Value A string that contains the value you want to assign to the specified
variable
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString() or GetLastErrorType() to get additional error
information.
B.90 ShowBusyWindow()
void ShowBusyWindow(BOOL Show)
Description
This function tells QMF for Windows to either show or hide the busy window.
The busy window is useful to provide feedback to the user and enables the
Parameters
Table 116 shows the parameters for this API.
Table 116. ShowBusyWindow parameters
Name Description
Show Nonzero shows the busy window; zero hides the busy window. If
nonzero, the busy window displays until you call ShowBusyWindow()
with Show set to zero.
Return value
None.
B.91 StartBind()
short StartBind(BSTR CollectionName, BSTR PackageName, BSTR
ConsistencyToken)
Description
This function begins the process of binding a package in the database.
Parameters
Table 117 shows the parameters for this API.
Table 117. StartBind parameters
Name Description
376 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Return value
Zero if successful, nonzero if unsuccessful. If the return value is nonzero, you
can call GetLastErrorString(), GetLastErrorType(), GetLastSQLCode(),
GetLastSQLError(), or GetLastSQLState() to get additional error information.
Related topics
EndBind(), CancelBind()
This section describes all of the tables and views that are added to the
database when QMF for Windows is installed.
C.1 Tables
The following tables in Figure 144 through Figure 153 will be created in a
database when QMF for Windows is configured to access it:
C.1.1 Q.OBJ_ACTIVITY_DTL
380 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
C.1.3 Q.OBJECT_DATA
C.1.4 Q.OBJECT_DIRECTORY
C.1.6 Q.RAA_SUBTYPE
C.1.7 RDBI.AUTHID_TABLE
382 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
C.1.8 RDBI.PROFILE_TABLE
C.1.9 RDBI.RESERVED
C.2 Views
The following views in Figure 154 through Figure 161 will be created in a
database when QMF for Windows is configured to access it. Each section
shows the data definition language that creates the view and a graphical
presentation.
C.2.1 Q.RAA_OBJECT_VIEW
CREATE VIEW Q.RAA_OBJECT_VIEW
(
OWNER, NAME, TYPE, SUBTYPE, OBJECTLEVEL, RESTRICTED, MODEL, REMARKS
)
AS
SELECT A.OWNER, A.NAME, A.TYPE, A.SUBTYPE,
A.OBJECTLEVEL, A.RESTRICTED, A.MODEL,
B.REMARKS
FROM Q.OBJECT_DIRECTORY A, Q.OBJECT_REMARKS B
WHERE (A.OWNER = B.OWNER AND A.NAME = B.NAME)
AND (A.RESTRICTED = 'N'
OR A.OWNER IN (USER, CURRENT SQLID)
OR A.OWNER IN (SELECT C.SECONDARY_ID
FROM RDBI.USER_AUTHID_VIEW C)
OR EXISTS (SELECT D.AUTHID
FROM RDBI.USER_ADMIN_VIEW D));
384 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Figure 154. RAA object view
C.2.2 RDBI.ADMIN_VIEW
CREATE VIEW RDBI.ADMIN_VIEW
(
"AUTHID"
)
AS
SELECT A.GRANTEE
FROM SYSIBM.SYSUSERAUTH A
WHERE A.SYSADMAUTH IN ('G', 'Y');
C.2.3 RDBI.AUTHID_VIEW
CREATE VIEW RDBI.AUTHID_VIEW
(
PRIMARY_ID,
SECONDARY_ID
)
AS
SELECT A.PRIMARY_ID, A.SECONDARY_ID
FROM RDBI.AUTHID_TABLE A;
C.2.5 RDBI.RESOURCE_VIEW
CREATE VIEW RDBI.RESOURCE_VIEW
(
RESOURCE_GROUP,
386 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
RESOURCE_OPTION,
INTVAL,
FLOATVAL,
CHARVAL
) AS SELECT RESOURCE_GROUP, RESOURCE_OPTION,
INTVAL, FLOATVAL, CHARVAL
FROM RDBI.RESOURCE_TABLE;
-- FROM Q.RESOURCE_VIEW;
C.2.6 RDBI.TABLE_VIEW
CREATE VIEW RDBI.TABLE_VIEW
(
OWNER, NAME, TYPE, SUBTYPE, OBJECTLEVEL, RESTRICTED, MODEL, REMARKS
)
AS
SELECT DISTINCT A.CREATOR, A.NAME, 'TABLE', A.TYPE, 0, 'Y', ' ', A.REMARKS
FROM SYSIBM.SYSTABLES A, SYSIBM.SYSTABAUTH B
WHERE (A.CREATOR = B.TCREATOR AND A.NAME = B.TTNAME)
AND (B.GRANTEE IN (USER, CURRENT SQLID, 'PUBLIC', 'PUBLIC*')
OR B.GRANTEE IN (SELECT B.SECONDARY_ID
FROM RDBI.USER_AUTHID_VIEW B)
OR EXISTS (SELECT C.AUTHID
FROM RDBI.USER_ADMIN_VIEW C))
AND (B.GRANTEETYPE IN (' ', 'U','G'))
AND (B.DELETEAUTH IN ('Y', 'G')
OR B.INSERTAUTH IN ('Y', 'G')
OR B.SELECTAUTH IN ('Y','G')
OR B.UPDATEAUTH IN ('Y','G'));
C.2.8 RDBI.USER_AUTHID_VIEW
CREATE VIEW RDBI.USER_AUTHID_VIEW
(
PRIMARY_ID,
SECONDARY_ID
)
AS
SELECT A.PRIMARY_ID, A.SECONDARY_ID
FROM RDBI.AUTHID_VIEW A
WHERE A.PRIMARY_ID = USER;
388 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Q.RAA_OBJECT_ VIEW
Looks at the owner names in Q.OBJECT_DIRECTORY and displays or fails
to display each object based on the conditions below. An answer of Yes to any
single question causes the query, proc, or form to be displayed in the list.
1. Does the Object Owner match the current USER id?
2. Does the Object Owner match the current SQLID?
3. Does the Object Owner match the Sec. Auth. ID of the current USER id?
4. Is the object SHARED? (That is Restricted =N)
5. Is the User a SYSADM?
RDBI.ADMIN_VIEW RDBI.AUTHID_VIEW
This view gets a list of GRANTEEs from This view simply copies all rows from the
The base table base table RDBI_AUTHID_TABLE
SYSIBM.SYSUSERAUTH.
It takes GRANTEEs who have been
granted G or Y for SYSADMAUTH
SYSIBM.SYSUSERAUTH RDBI.AUTHID_TABLE
A base table listing Primary and Secondary
Authorization Ids
For the tables, the view called RDBI.TABLE_VIEW is the key and interacts
with other views and tables as shown in Figure 163.
PLUS
The table must have one of the GRANTEETYPEs U or G
PLUS
The GRANTEE for the table must have Y or G authority in one of
the following four categories
1. DELETEAUTH
2. INSERTAUTH
3. SELECTAUTH
4. UPDATEAUTH
RDBI.USER_ADMIN_VIEW RDBI.USER_AUTHID_VIEW
This view answers the question: Is the This view gets all rows from the base table
User, or a Sec. Auth. Id of the User, a RDBI.AUTHID_VIEW where the Primary
SYSADM? ID is that of the current USER.
It checks RDBI.ADMIN_VIEW for: Thus it will list ALL SEC AUTH Ids for
1. The current USER id the current USER
2. Sec. Auth Id of the Current User,
which it gets from here
RDBI.AUTHID_VIEW
This view simply copies all rows from the
base table RDBI_AUTHID_TABLE
RDBI.ADMIN_VIEW
This view gets a list of GRANTEEs from
The base table
SYSIBM.SYSUSERAUTH. RDBI.AUTHID_TABLE
It takes GRANTEEs who have been A base table listing Primary and Secondary
granted G or Y for SYSADMAUTH Authorization Ids.
390 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Appendix D. Using the additional material
ftp://www.redbooks.ibm.com/redbooks/sg245746
http://www.redbooks.ibm.com/
Select the Additional materials and open the directory that corresponds with
the redbook form number.
392 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Appendix E. Special notices
IBM may have patents or pending patent applications covering subject matter
in this document. The furnishing of this document does not give you any
license to these patents. You can send license inquiries, in writing, to the IBM
Director of Licensing, IBM Corporation, North Castle Drive, Armonk, NY
10504-1785.
Licensees of this program who wish to have information about it for the
purpose of enabling: (i) the exchange of information between independently
created programs and other programs (including this one) and (ii) the mutual
use of the information which has been exchanged, should contact IBM
Corporation, Dept. 600A, Mail Drop 1329, Somers, NY 10589 USA.
The information contained in this document has not been submitted to any
formal IBM test and is distributed AS IS. The information about non-IBM
("vendor") products in this manual has been supplied by the vendor and IBM
assumes no responsibility for its accuracy or completeness. The use of this
information or the implementation of any of these techniques is a customer
Any pointers in this publication to external Web sites are provided for
convenience only and do not in any manner serve as an endorsement of
these Web sites.
This document contains examples of data and reports used in daily business
operations. To illustrate them as completely as possible, the examples
contain the names of individuals, companies, brands, and products. All of
these names are fictitious and any similarity to the names and addresses
used by an actual business enterprise is entirely coincidental.
Java and all Java-based trademarks and logos are trademarks or registered
trademarks of Sun Microsystems, Inc. in the United States and/or other
countries.
Microsoft, Windows, Windows NT, and the Windows logo are trademarks of
Microsoft Corporation in the United States and/or other countries.
SET and the SET logo are trademarks owned by SET Secure Electronic
Transaction LLC.
The publications listed in this section are considered particularly suitable for a
more detailed discussion of the topics covered in this redbook.
This section explains how both customers and IBM employees can find out about ITSO redbooks,
redpieces, and CD-ROMs. A form for ordering books and CD-ROMs by fax or e-mail is also provided.
• Redbooks Web Site http://www.redbooks.ibm.com/
Search for, view, download, or order hardcopy/CD-ROM redbooks from the redbooks Web site. Also
read redpieces and download additional materials (code samples or diskette/CD-ROM images) from
this redbooks site.
Redpieces are redbooks in progress; not all redbooks become redpieces and sometimes just a few
chapters will be published this way. The intent is to get the information out much quicker than the
formal publishing process allows.
• E-mail Orders
Send orders by e-mail including information from the redbooks fax order form to:
e-mail address
In United States usib6fpl@ibmmail.com
Outside North America Contact information is in the “How to Order” section at this site:
http://www.elink.ibmlink.ibm.com/pbl/pbl
• Telephone Orders
United States (toll free) 1-800-879-2755
Canada (toll free) 1-800-IBM-4YOU
Outside North America Country coordinator phone number is in the “How to Order”
section at this site:
http://www.elink.ibmlink.ibm.com/pbl/pbl
• Fax Orders
United States (toll free) 1-800-445-9269
Canada 1-403-267-4455
Outside North America Fax phone number is in the “How to Order” section at this site:
http://www.elink.ibmlink.ibm.com/pbl/pbl
This information was current at the time of publication, but is continually subject to change. The latest
information may be found at the redbooks Web site.
Company
Address
We accept American Express, Diners, Eurocard, Master Card, and Visa. Payment by credit card not
available in all countries. Signature mandatory for credit card payment.
400 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Glossary
data type. There are different kinds of
A Intelligent Miner data types, for example,
application programming interface (API). A discrete numeric, discrete nonnumeric, binary,
functional interface supplied by the operating or continuous.
system or a separate orderable licensed
program that allows an application program
written in a high-level language to use specific F
data or functions of the operating system or the
licensed program. field. A set of one or more related data items
grouped for processing. In this document, with
architecture. The number of processing units in regard to database tables and views, field is
the input, output, and hidden layer of a neural synonymous with column .
network. The number of units in the input and
output layers is calculated from the mining data file. A collection of related data that is stored
and input parameters. An intelligent data mining and retrieved by an assigned name.
agent calculates the number of hidden layers file name. (1) A name assigned or declared for
and the number of processing units in those a file. (2) The name used by a program to
hidden layers. identify a file.
attribute. Characteristics or properties that can flat file. (1) A one-dimensional or
be controlled, usually to obtain a required two-dimensional array; a list or table of items.
appearance. For example, color is an attribute (2) A file that has no hierarchical structure.
of a line. In object-oriented programming, a data
element defined within a class. formatted information. An arrangement of
information into discrete units and structures in
a manner that facilitates its access and
processing. Contrast with narrative information.
D
function. Any instruction or set of related
DATABASE 2 (DB2). An IBM relational instructions that perform a specific operation.
database management system.
database table. A table residing in a database.
database view. An alternative representation of I
data from one or more database tables. A view input data. The metadata of the database table,
can include all or some of the columns database view, or flat file containing the data
contained in the database table or tables on you specified to be mined.
which it is defined.
instance. In object-oriented programming, a
data field. In a database table, the intersection single, actual occurrence of a particular object.
from table description and table column where Any level of the object class hierarchy can have
the corresponding data is entered. instances. An instance can be considered in
data format. There are different kinds of data terms of a copy of the object type frame that is
formats, for example, database tables, filled in with particular information.
database views, pipes, or flat files.
data table. A data table, regardless of the data
format it contains.
P
pass. One cycle of processing a body of data.
processing unit. A processing unit in a neural
network is used to calculate an output by
summing all incoming values multiplied by their
respective adaptive connection weights.
R
record. A set of one or more related data items
grouped for processing. In reference to a
database table, record is synonymous with row.
rule. A clause in the form head<== body. It
specifies that the head is true if the body is true.
S
Structured Query Language (SQL). An
established set of statements used to manage
information stored in a database. By using these
statements, users can add, delete, or update
information in a table, request information
through a query, and display results in a report.
symbolic name. In a programming language, a
unique name used to represent an entity such as
a field, file, data structure, or label. In the
Intelligent Miner you specify symbolic names, for
example, for input data, name mappings, or
taxonomies.
402 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
List of abbreviations
404 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
Index
BOTTOM 229
BREAK 222
A business intelligence 3, 10
access
existing QMF objects 183
objects stored at a database 183 C
objects stored in a file 186 C++ 172
table 188 considerations 173
access controll 102 setup 173
access path 243 CALC 222
ACROSS 221 Call Level Interface 64
Active Server Page 263 cancel query 189
add from list 204 CancelBind 298
add row condition 208 CCSID 85
add sort condition 207 centralized administration 180
AddDecimalHostVariable 293 CGI 131, 263
AddHostVariable 294 programming 263
API 126 sample 263
APPC change password 112, 246
Conversations 51 ChangePassword 298
Logical Units 50 check
LU 6.2 50 resource limits 243
Sessions 51 check form 227
Terminology 50 ClearList 299
Transaction Programs 51 Close 299
application development 125 collection name 81, 88
application requester 26 column
application server 26 add to form 214
application services 49 column sequence 225
ARPANET 27 command line interface 15
ASCII 85 command line mode 120
ASP 131, 263 Commit 300
assign user 110 commit 130
asynchronous application 128 Common Gateway Interface 263
AT command 123 Common Object Request Broker Architecture 127
authorization ID 85 communication protocols 25
AVERAGE 222 compact installation 178
CompleteQuery 301
CONNECT 229
B connection timeout 98
bind
control resource consumption 92
permissions 105
CONVERT 229
static package 115
convert to SQL 210
bind packages 88
CopyToClipboard 301
bind privileges 88
CORBA 127
BindDecimalHostVariable 295
cost estimation 119
BindHostVariable 296
COUNT 222
BindSection 297
covert to HTML 194
406 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
edit codes 215 FTP 28
e-mail 28
encoding schema 85
EndBind 303
G
gateway 16, 33
Enterprise Query Environment 11
GetColumnCount 134, 319
requirements 11
GetColumnDataValue 319
environment
GetColumnHeader 320
multi vendor 15
GetColumnHeaderEx 320
ERASE 229
GetColumnHeadings 134, 321
Execute 304
GetColumnValue 322
ExecuteEx 304
GetColumnValueEx 323
ExecuteStoredProcedure 305
GetDefaultServerName 324
ExecuteStoredProcedureEx 307
GetGlobalVariable 324
EXPORT 229
GetHostVariableNames 325
Export 308
GetHostVariableTypeNames 325
export data 192
GetHostVariableTypes 326
ExportForm 311
GetLastErrorString 326
ExportReport 311
GetLastErrorType 327
GetLastSQLCode 328
F GetLastSQLError 329
FastSaveData 313 GetLastSQLState 330
fetch limit 98 GetOption 331
FetchNextRow 134, 314 GetOptionEx 332
FetchNextRowEx 316 GetProcText 333
FetchNextRows 316 GetProcVariables 333
FetchNextRowsEx 318 GetQMFObjectInfo 334
filter objects 185 GetQMFObjectInfoEx 336
find 190 GetQMFObjectList 132, 338
FIRST 222 GetQMFObjectListEx 339
FlushQMFCache 318 GetQMFProcText 340
footing 218 GetQMFQueryText 341
form 211 GetQueryText 132, 341
add column 214 GetQueryVerb 133, 342
change 221 GetResourceLimit 343
check 227 GetResourceLimitEx 348
column sequence 225 GetRowCount 348
column width 214 GetServerList 131, 349
convert to HTML 256 GetServerListEx 350
create default 220 GetStoredProcedureResultSets 351
default 220 GetVariables 352
edit codes 215 GetVariablesEx 353
HTML heading 256 Global Variables 277
indent 214 global variables 281
main window 213 Gopher 28
save 218, 221 governing 15
usage code 221 grant permissions 89
Form calculations 15 grid 272
FORWARD 229 GROUP 223
407
grouping 221 L
Large Object 119
LAST 223
H
heading 218 linear procedure 120
history report 107 linear procedures 15
host address 29 list
host name 74 display 185
hostname 46, 47 refresh 185
hostnames 48 remove from 186
hosts file 48 work with 247
HTML list objects 184
dynamic reports 262 LOB 119, 272
edit form 258 local host 36
heading text 258 local SDF 179
preview 259 location name 73
response 267 logical unit 49
scheduling 260 loopback network 30
Lotus 123
import data 233
I Snap-In 232
implementation samples 20
IMPORT 229
indent 214 M
Indirect Routing 33 MAXIMUM 223
infrastructure maximum rows 98
solution 13 Microsoft Access
typical 11 Access Report List 240
InitializeProc 353 Snap-In 238
InitializeQuery 354 Microsoft Excel
InitializeServer 130, 355 Import Data 236
InitializeStaticQuery 356 Snap-In 235
Internet 253 middleware 16, 126
environment 254 migrate from Query Manager 251
IP addressing 29 MINIMUM 223
IP datagram 32 modify data 192
IP Routing multitasking 128
algorithm 35 multithreading 128
table 34
IP routing 33 N
Isolation level 103 Needs
IsStatic 357 IS 10
needs
end user 12
J
Java Database Connectivity 127 power user 12
JDBC 127 travelling user 13
join 205 network address 29
networking protocols 11
NFSNET 27
408 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
O Q
object QMF
create new 197 APIs 293
working with 187 architecture 25
Object REXX 15 benefits 271
object tracking 107 CGI programming 263
ODBC 11, 126 CGI sample 264
OMIT 223 components 178
Open 358 concepts 181
owner ID 81 customize interface 249
existing installations 85
future 272
P High Performance Option 7
packages 81
history 6
authorization 82
HPO/Compiler 7
replacing 82
HPO/Manager 7
path control 49
installation 177
PCT 223
internet 254
Persistent Object Service 127
objects 83, 181
Personal Portal 273
packages 81
application support 274
prerequisites 25
Favorite 275
procedure 196
physical control 49
Snap-In 231
port number 74
tables 84, 379
POS 127
views 379
predictive governing 118
web publishing 254
Predictive Governor 118
QMFWinLibrary_TLB 155
Prepare 359
queries
preprocessor 115
predefined 12
presentation services 49
query 1, 182, 188
PRINT 229
add column 206
print 192
cancel 189
PrintReport 359
create 199
procedure 196
definition 1
Clear Grid 136
draw 202
commands 229
environment 3
create 227
needs 10
DataIntoGrid 136
run 188, 201
run 196, 230
save 211
save 230
types 188
programming
view prompted 189
CGI 263
Query Management
considerations 173
challenge 9
programming concepts 125
characteristics 3
prompted Query
introduction 1
create 203
Query Manager 251
prompted query 175
quick start 16
view 209
provider DLL 75
409
R save procedure 230
RDB name 73 save user defaults 194
reactive governing 118 SaveData 361
ReinitializeServer 360 SaveQMFProc 363
remote host 36 SaveQMFQuery 133, 364
remove from list 186 schedule 94, 95
report 212 day range 96
column sequence 225 number 95
display 186, 219 status 96
footing 218 time range 96
heading 218 schedule service 123
preview 259 scheduling 122
scheduling 260 SEND TO 230
report distribution 5 server
report management 5 set 197
reporting server definition file 179
distributed 5 local 179
needs 10 shared 179
reporting environment 3 server name 73
reports servlet 131
predefined 12 SET GLOBAL 230
resource governor 92 set server 197
resource group 87 SetBindOption 365
Resource Limit Facility 118 SetBindOwner 367
resource limits 85 SetBusyWindowButton 368
check 243 SetBusyWindowMessage 369
result SetBusyWindowMode 369
order by 191 SetBusyWindowTitle 370
print 192 SetGlobalVariable 371
view 189 SetHostVariable 371
Rocket Personal Portal 273 SetOption 372
Rollback 360 SetParent 373
rollback 130 SetProcVariable 374
router 33 SetVariable 375
routing 49 shared SDF 179
row condition 208 SHOW 230
RowLimit 133 ShowBusyWindow 375
RUN 230 SMTP 28
run a query 188 SNA
run procedure 196, 230 Layers 49
RunProc 361 Snap-In 231
Lotus 123 232
Microsof Excel 235
S Microsoft Access 238
SAVE 230
solution
save
cost 5
default form 221
sort 191
form 218
ascending 191
query 211
condition 191
410 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
descending 191 transaction services 49
SQL 2 transmission control 49
dynamic 243 two phase commit 173
permissions 100 typical installation 178
static 16, 243
verbs 100
SQL expression 206
U
UDP 28
SQLDS 63
unit of work 130
StartBind 376
unused objects 107
static queries 115
usage code 221
static SQL 16, 243
user interface 5
STDEV 223
user profile 85, 86
stored procedures 15
string delimiter 82
subnet 30 V
substitution variable 202 variables
Substitution Variables 277 global 277, 281
substitution variables 279 in registry 277
SUM 223 lifetime 277
symbolic destination name 75 pre-loaded global 283
SYNC_LEVEL 53 structure 279
synchronization 128 substitution 277, 279
synchronous application 128 user defined global 281
SYNCPOINT 53 working with 277
variant 173
view
T in Web Browser 259
table 188
prompted query 209
create new 198
view prompted query 189
join 205
view result 189
table editing 103
view SQL 188
TCP/IP 27, 47
Visual Basic 135
Application Layer 28
export data 152
architecture 28
initialize query 140, 145, 150
Internet Layer 29
initialize server 143, 148
Network Interface Layer 29
list directory 144
Transport Layer 28
list drives 144
TCP/IP Architecture 28
list file list 144
TCPCT 223
list queries 139
Telnet 28
list servers 138, 143, 148
test connection 78
sample 136
thin client 13
save query 151
thread 128
setup 135
timeouts 96
toolbar
customize 250 W
totals 221 web
TPCT 223 environment 262
Trace 79 publishing 15, 254
411
static reports 255
Web Warehouse 261
wildcard 185
WINDOWS 230
Windows NT scheduler 122
WinSock 37
wrapper class 173
412 A DB2 Enterprise Query Environment — Build It with QMF for Windows !
ITSO redbook evaluation
A DB2 Enterprise Query Environment - Build it With QMF For Windows !
SG24-5746-00
Your feedback is very important to help us maintain the quality of ITSO redbooks. Please complete this
questionnaire and return it using one of the following methods:
• Use the online evaluation form found at http://www.redbooks.ibm.com/
• Fax this form to: USA International Access Code + 1 914 432 8264
• Send your comments in an Internet note to redbook@us.ibm.com
Please rate your overall satisfaction with this book using the scale:
(1 = very good, 2 = good, 3 = average, 4 = poor, 5 = very poor)
Was this redbook published in time for your needs? Yes___ No___