Open Query File
description
Transcript of Open Query File
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
by Tim JannsenASNA
© Copyright 2007 by ASNA. All rights reserved.
Open Query FileOpen Query File
Dynamically creating logical views.
1
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
OPNQRYF Heritage
•DclDiskfile at design time:
•File name Properties at runtime:
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Implementation Differs With Engine
• DataGate Windows– Simple Query
• Implements Select/Omit
• DB2/400– OPNQRYF
• Implements QRYSLT & KEYFLD parameters
• SQL Server– SQL
• Implements SELECT WHERE
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Basics
• File created in QTEMP – QTEMP in SQL Server introduced: DG-SQL 8.1.433
• Give File any name you wish‡
• *NAME uses DclDiskFile Name keyword value ‡
• *UNIQUE creates a unique name‡ Avoids risk of duplicate file names
• Sequential Access is Intended • Random Access Allowed (some restrictions apply)
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
QRYSELECT for DataGate Windows
• Select/Omit Rule• Relational Operators:
• Use either ' or " for literal token• Field to Field comparison allowed• No built in functions
> GT Greater than
>= GE Greater than or equal
< LT Less than
<= LE Less than or equal
= EQ Equal
!= <> NE Not equal
& AND
| OR
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
DataGate Windows Examples
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
QRYSELECT for DB2/400
• Whatever is valid in QRYSLT • Relational Operators:
• Use either ' or " for literal token• Field to Field comparison allowed• Lots of built in functions
> *GT Greater than >= *GE Greater than or equal
< *LT Less than <= *LE Less than or equal
= *EQ Equal ¬= *NE Not equal
¬> *NG Not greater than ¬< *NL Not less than
& *AND And | *OR Or
&& *XOR Exclusive OR *CT Contains
|| *CAT Concatenate *NOT Not
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
DB2/400 Examples
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
QRYSELECT for SQL Server
• Whatever is valid following Select From WHERE • Relational Operators:
• Use only ' for literal token• Field to Field comparison allowed• Lots of built in functions• Wildcards allowed
> Greater than >= Greater than or equal
< Less than <= Less than or equal
= Equal <> != Not equal
!> Not greater than !< Not less than
AND And OR Or
+ Concatenate NOT
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
SQL Server Examples
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
QRYKEYFLDS
• Specifies presentation sequence of records – ORG( *indexed and *Arrival )
• Target File can be Logical or Physical• Syntax
– Field name– Ascending or Descending– Absolute value (numeric fields only)
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
When Things Go Wrong – DG Windows
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Copy and Paste QRYSelect
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Need A Little Help? Use Default Select Tab
Notice the Drop
Downs
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
When Things Go Wrong – DB2/400
What's wrong with this?
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Check the Job Log for DataGate JobWRKACTJOB
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
When Things Go Wrong – SQL Server
What's wrong with this?
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Use SQL Server Management Studio
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Use SQL Server Management Studio
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Random or Sequential Processing?
• Open Query intended to be sequential • Random Access commands:
– CHAIN; SETLL; SETGT; nnnRANGE
• Random is OK – If QRYKeyFlds matches compiled file's key parts– If you say so (see Random keyword)
• dclDiskFile's Random Keyword– Tells Compiler of your intention
• *NO raises compiler error if you use random commands
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Single Source?
• Syntax and punctuation differences can be normalized in code– e.g., use <> instead of *NE
• How do you do know to which engine application is connected at runtime?
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Database Class Members
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Database Properties
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Distinguishing DB Object Properties
• Server Host Name or IP address
of DB server
• Port IP Port for DB service
• Label Identifies DB Instance
• PlatformAttribute Identifies server linkage
• PoolingTimout 0 = No pooling 1-255 = Pool Idle
TimeOut• User
User ID or *DOMAIN• Password
User password if not *DOMAIN
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Use Server Property?
• IP Address– 10.1.3.25
• Host Name– "S1055523"– "NetServ3500\MySQLServerName"
• Not cast in bronze• *LOCAL
– My Computer for DG Windows instances– My Computer for Default SQL Server instance
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Use Port Property?
• 0 or 5042– *LOCAL
• 5042– Required for Remote DG SQL Server– Default for DG iSeries
• nnnn– Multiple DG iSeries versions
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Use PlatformAttribute Property?
• *DATALINK– Native DataGate protocol
• DG iSeries• DG Windows
• *SQLOLEDB– SQL Server 2000 & 2005
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Use Label Property?
• Identifies DG Windows DG location• Not meaningful for DG iSeries or DG SQL
Server• PlatformAttribute Property distinguishes
iSeries from SQL Server• So, use meaningful Label to identify iSeries
– e.g., "AS400", "iSERIES", "SYSTEM i"
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Mix in ADO for Embedded SQL
ASN
Apalo
oza
20
07
ASN
Apalo
oza
20
07
© Copyright 2007 by ASNA. All rights reserved.
Open Query FileOpen Query File
30