• Windows Multi-DBMS Programming

Using C++, ®, ODBC, OLE2, and Tools for DBMS Projects

Ken North

John Wiley & Sons, Inc. New York • Chichester • Brisbane • Toronto • Singapore : . ... • - .

Contents

Preface XXV

Chapter 1 Overview and Introduction 1

The Changing Face of Development 2 Overview 2 Required Hardware and Software 3

Chapter 2 Windows Software Development: Concepts and Issues Terms and Concepts 5 Windows Features and Database Applications 7 Processes, Tasks, and Threads 7 Multitasking 8 Protected Addresses and Safe Multitasking 8 Threads: NetWare and Win32 9 Scheduling 9 Windows Programming 10 Static and Dynamic Linking 11 Dynamic Link Libraries 12 INI Files 12 Resources and Help Files 12 Dialog Boxes 13 Custom Controls 14 Notation 14 Windows Developer's Notebook 15 Baselines 15 Version Control 16 Common Development Steps 16

VH viii Contents

Pseudocode 17 Debugging 17 Visual Programming 19 Formal Development Methods 19 Crafting Code for Windows 20 GUI Design Considerations and Database Applications 20

Chapter 3 Database Applications: Concepts and Issues 22 Building Database Applications 22 Database Architectures 23 DBMS Evolution 23 ISAM 24 Network and Hierarchical Databases 24 SQL and Relational Databases 25 Desktop, File Server, and Client-Server 29 Terms and Concepts 30 SQL Concepts 38 Database Design 39 Network Database Design 40 Relational Database Design 40 Query Optimization 45 Issues 48 Sample Database and Applications 49 Info Enterprises 49 Sample Applications 50 Road Map for Database Developers 55 Tools for Developing Database Front Ends and Client Applications 56

Chapter 4 Solutions for Multidatabase Programming 57 Terms and Concepts 57 Gateways and Routers 58 Embedded SQL 59 and CLIs 59 Standard Database APIs: A Historical Perspective and Future 60 Open Database Connectivity (ODBC) 61 INTERSOLV/Q+E Database Library 63 Contents ix

EDA/CLI 64 Oracle Glue 65 ODBC Drivers 65

• Components and Custom Controls 66 Using Objects to Access Data 66 Data Access Objects 67 Interoperable Objects 67 Late Binding 68 Issues Affecting Interoperability 69 Distributed Objects and Remote Data Access 69 Formulating a Database Development Strategy 70 Chapter 5 Servers and Database Engines 71 SQL Server for Windows NT 72

• SQL Server Tools 74 Transact-SQL 76 Stored Procedures, Triggers, and Rules 78 Preparing for ODBC 80 INI Files 81 Creating Databases and Tables 84 Watcom SQL 91 Locking and Isolation Levels 93 Administering Watcom SQL 93 ODBC Setup 98 Programming Notes 98 Quadbase-SQL 105 VBQUERY 106 Quadbase-SQL XB/Server 107 SQL Scripts 108 Quadbase SQL Command Details 111 Microrim R:BASE and R:BASE SQL Engine 111 R.-BASE Functions 112 Raima Database Server 115 Database Administration 115 Database Navigation 115

• RDSSQL 120 ODBC and Raima SQL Functions 120 x Contents

Oprifm'zaft'o« 122 Extension Module Programming 123 Gupta SQLBase 123 Transaction Logs and History Files 124 Configuration File 125 SQLBase Administration and SQLTalk 127 Data Organization 128 Networking, SQLGateway, and SQLRouter 130 SQLBase SQL Notes 130 Optimization, Query Plans, and Indexes 131 Stored Procedures, Triggers, and Events 132 С Programming API 133 Example Database 133 Information Builder's EDA / SQL 141 Programming EDA/SQL 141 Coromandel Integra VDB 143 Visual Data Manager 143 Visual Query Builder 146 Trigger Definition 146 Custom Controls 147 Page Ahead's Simba and ODBC Desktop Databases 155 Desktop Driver Notes 156 Conclusion 159

Chapter 6 Using ODBC 160 Г1*" v wein^ wwww Architecture 161 Components 163 Functions and Features 166 Conformance Levels 166 Relationship to the Windows API 166 Driver Manager Processing 171 Data Types 172 Installation 174 Setup 174 ODBC SDK 174 Files Used with ODBC 175 Contents xi

ODBC Administrator 176 Tracing 177 Configuring Data Sources 178 ODBC SQL 184 SQL Extensions 185 Qualifiers, Owners, and Procedures I9l ODBC Programming 192 Handles 192 Options That Govern Behavior 192 Connections 194 Metadata, Catalog Information 196 Statements 197 Cursor Operations 200 Results Processing 201 Termination 204 Typical Processing Sequence 205 Referential Integrity 206 Asynchronous Processing 206 Transaction Processing and Concurrency 206 Cursor Library 208 Translation Libraries 211 Interoperable ODBC Applications 211 Л Fundamental Concept 211 Issues Affecting Interoperability 212 Interrogating for Available Features 217 Interrogating for Available Functions 217 Creating Databases and Tables 219 Interrogating for Available Data Types 219 Developer Guidelines 220 Linker Errors with C++ 221 Debugging and Testing 221 Development and Optimization Hints 223 ODBC or Access Engine ? 224 ODBC as a Tool 225 Why ODBC? 225 Supplemental Information 226 0ШС Benchmark Kit 226 xii Contents Chapter 7 Using INTERSOLV QELIB 228

Installation and Features 228 Multiple Access to Data Sources 229 QELIB Data Types 230 Required ODBC Functions 231 Dates 233 Format Strings 233 Joins 233 Functions 233 Connections and Statements 234 Parameter Queries 235 Transactions 236 Retrieving Data 237 Fetching and Caching Result Sets 238 Column Values Retrieval 239 Metadata and Catalog Functions 240 Column Functions 240 Processing Memo and BLOB Data 241 Modifying Records 241 Уег^гои Information and Initialization 243 £rror Handling and Debugging 243 Query Tools 244 Para'/ig 5ßL 246 ODBC Handle Conversion 246 Date-Time Functions 247 Data Conversion 247 Language Considerations 248 Programming Notes 249 0£L/S and ODBC 249 Portable SQL Functions for QELIB 249 Example Programs 250 T • i /-i ост Typical Query 252 Column Description Information 252 Chapter 8 Data Access and Data Presentation Tools 258

Gupta Quest 259 QuestWindow 260 Contents xiii

Queries 260 Aggregate Functions Nonaggregate Functions ZOl Excel 271 Setup 272 Accessing Data 272 ODBC Extensions 272 Executing Queries 274 Using Microsoft Query 275 Dynamic Data Exchange (DDE) 277 Microsoft Word for Windows 279 Setup 279 Accessing Databases 280 Executing a Query with Word 280 Using Attached ODBC Tables and Access 280 Word Developer's Kit and WordBasic 283 Using the ODBC Extensions 284 Example Report Macro 285 Mail Merge 287 InfoPublisher 288 Tables 288 Queries 289 InfoPublisher and Databases 290 Crystal Reports for Windows 290 Report Language Functions 291 _ 292 Pro Edition Indexes Report Layout Mode Zyi Print Engine Programming 293 Crystal Reports VBX Properties 298 Example Reports 301 305 Dynamic Queries 305 Form Designer 305 Links to Other Applications 306 Lotus 1-2-3 307 Lotus DataLens 309 DataLens Driver Notes 310 xiv Contents Chapter 9 Rules, Facts, and Objects 312 Asymetrix InfoModeler 312 Views and Modeling a Database 313 FORML 313 Repository, Versions, and Object Reuse 314 Predicates 314 Fact Compiler, Diagrammer, and Table Browser 315 Constraints 316 Mandatory Roles 316 Cardinality 317 Sample Populations 317 Quick Tour 317 Verbalizer and Fact Assistant 319 Driver Notes 320 Example Model 320 InfoEnterprise Tables 321 Using Rules and Databases 322 Rule-based Applications 323 Information Builders' LEVEL 5 OBJECT 323 Actions and RuleTalk 324 Knowledge Base and Inference Engine 325 Editors 325 Actions 327 Using Databases 328 Object Orientation and Object-Oriented Programming 330 Messages, Late Binding, Virtual Methods 332 Data Hiding 333 Object Limitations 335 Conclusion 336

Chapter 10 Tools for Software Developers 337 Developer Tool Roadmap 338 ProtoGen+ Workbench 339 ViewPaint 339 WinControl Library 341 ProtoView Screen Manager 341 Contents xv

• SQLView 347 Field Controls 348 Methods 348 SQLView API Error Handling 353 Visual Development Example 353 Proto View's ProtoGen+ 355 Application Regeneration 355 Steps to Creating a User Interface 355 Proto View DataTable 357 Setup 358 Graphics Server SDK and ChartBuilder 358 Charting Features 359 Oracle Glue for Windows 360 Containers 361 Glue Architecture and API 361 Generic Glue DLL 362 SQL Glue Language 363 Palmtop Glue and Wizards 365 Visual Basic Glue Programming 367 WizLink Sample Application 368 Magic Fields 373 Magic Fields API 374 • WindowsMAKER Pro 376 Visual Screen Designer 376 Extended Functionality Modules 376 Quick Look 377 Visual AppBuilder 379 Visual Programming 379 Layout Window 380 Database ALM and the Database Object 382 Browser Object 382 Table Object 383 Other Database ALM Objects •JO.J Using AppBuilder Client-Server ALMs 389 Client-Server Example Program 389 xvi Contents Chapter 11 Client-Server Tool Suites 391

ObjectView 391 Database Interface 393 Visual SQL and Personal SQL 395 Workgroup Library 396 Other Features 397 Command Files 398 Development Cycle 399 Developing with ObjectView 399 ObjectView Scripts 400 Panel Events 401 ObjectView and the TODO List Example Application 402 Gupta SQLWindows 403 Objects and Data Types 404 Messages 405 SQL Programming 406 ReportWindows 408 EditWindows 409 TeamWindows 409 Data Dictionary 411 Creating a PERINFO Data Dictionary Using TeamWindows 412 Template Library 413 QuestWindow Example 413 SQLWindows 5.0 416 Powersoft PowerBuilder 419 Painters 420 PowerScript Programming 425 Libraries, Executables, and INI Files 429 ODBC Interface 430 PowerBuilder and OLE 432 Extending PowerBuilder *? 432 Advanced Developer Toolkit 433 Required Resources 433 Report Generation and PowerViewer 434 Example SQL Scripts 434 Creating a PERSINFO ToDo Example Browser 437 Contents xvii Chapter 12 Client or Client-Server (FoxPro and Access) 442

Microsoft FoxPro for Windows 442 Architecture 443 Screen Builder 443 Menu Builder and Report Writer 443 RQBE 444 Using Index Files 445 Creating FoxPro Tables for the Example Application 445 FoxApp and the Sample Application 453 FoxPro Connectivity Kit 455 FPSQL Programming 457 Getting ODBC Data Source Table Information 459 Executing Remote Queries Using ODBC 460 FoxPro Connectivity Demo Executive Information System 462 463 Database Organization and Permissions 464 Tables and Views 465 Referential Integrity 467 Queries 468 Forms 471 Reports 473 Customizing Access Applications 473 Macros 473 Events 473 DDE and OLE 476 SQL and Data Types 476 Btrieve Files 479 Mapping Data Types 480 Using Access and the Access Engine with ODBC 481 Cursor Model 482 Connections and Statements 482 Cursor Commit Behavior 482 Dynasets and Snapshots 483 Level 1 ODBC and Unique Indexes 484 Exporting Data 484 SQL Pass-through 484 xviii Contents

Local Processing and Heterogeneous Joins 485 Server Data Modification 486 Configuration Information 486 Frequently Asked Questions 487 Programming with Data Access Objects in Access and Visual Basic 487 DAO Programming Notes 489 Collection Methods 491 DBEngine Object 492 Database Object 492 Container Object 493 Document Object 493 Relation Object 494 Group Object 494 User Object 494 Workspace Object 495 Field Object 495 Index Object 496 TablesDefs and Database Structure Information 497 QueryDefs 498 Parameter Object 498 Recordsets 499 Property Object 502 Considerations for the Future 509 Fi'eW Properties 509 Indexes 509 Example Access Database 510 Performance Hints for Using Access in Client-Server Applications 511 Local Tables 512 Forms 512 Connections 512 Timestamps 513 Transactions 513 Indexes 513 Stored Procedures 513 ^, CIO Queries 513 Locks 513 Contents xix Chapter 13 Database Programming with Visual Basic 514 Choice of Techniques 520 Programming with the Data Control 522 Data Control Example 523 Calling ODBC API Functions 525 Developer Notes 534 Object Layer vs. API 535 OLE Automation Client ^ Stored Procedures 535 Multimedia and the Media Control Interface (MCI) 538 Optimizing VB 539 E-mail, Messaging, and MAPI 543 Electronics Forms Designer 543 Registrant Sample 547 Database Updates with MEF 547 Distributed Report Applications 548 Visual Basic Add-ons 549 Bound Controls 549 Custom Controls for Visual Basic 550 INTERSOLV MultiLink/VB 553 Custom Controls 554 Programming with MultiLinWVB 554 Visual Basic for Applications 561 Conclusion 563

Chapter 14 Database Programming with C++ 564

Infrastructure 564 Component Development (DLLs, VBXs, OCXs) Windows 95 SDK 567 Client-Server Tool Suites 567 Libraries JOo Wizards and Experts JO4A.Q» Message and Event Handling 568 Serializable, Streamable Objects 570 xx Contents

Record Handling with Record Field Exchange and Transfer Buffers 570 Resource Editors 571 Document/View Architecture 571 Exception Handling and Templates 572 Browsers 572 Borland C++ 572 Class Libraries 572 Resource Workshop 574 Winsight and WinSpector 574 IDE, AppExpert, and Class Expert 574 IDE Debugging, Turbo Debugger 576 Streams 577 ObjectWindows Library (OWL) 578 ObjectWindows 2.0 Classes 579 Database Development with OWL 583 Borland Database Engine 584 ++ 584 Visual Workbench 586 AppWizard, ClassWizard 586 Microsoft Foundation Classes (MFC) 587 MFC Class Hierarchy 588 AppStudio 591 Integrated Debugging and Codeview 592 Exception Handling and Templates 593 Multithreading Routines 594 Version Control with VER.DLL 594 Developing ODBC Programs 595 Developing SQL Classes 595 Design Issues 596 Polymorphism 596 Caveats 597 C++ and SQL Objects 598 Developing QELIB Classes 598 Developing ODBC Classes 600 Building the Applications 603 Program Example: Metadata with ODBCDict and QEStruct 603 QEStruct 605 Contents xxi

Back-end Interrogation 607 Guidelines for Extensions 608

Chapter 15 Solutions for C++ Database Programming 610

Borland C++ and Visual Solutions Pack 610 Date Formats 611 Database Operations 614 Triggers 618 Modifying the To Do Example 618 Using Integra VDB and Visual C+ + 621 MFC Database Classes 624 Database Class 627 Recordset Class 628 Record View Class 632 Database Exceptions Class 633 BLOBs (Long Binary Class) 634 Data Exchange Class 634 ODBC Conformance Issues 635 Cursor Library 635 MFC Components* 636 AppWizard Database Support Options 636 Example Application 637 Using a Single Database Object with Multiple Recordsets 651 OLE and OCXs 651 OLE Control Developer's Kit 652 Bound Controls /« Why Use the CDK? 655

Chapter 16 Programming with OLE 2.0 657

Overview 657 OLE versus "Traditional" Techniques 658 Standards for Interoperable Objects 658 OLE 2.0 Architecture 659 Terms, Concepts, and Features 660 Component Object Model 661 User Interface Issues 661 xxii Contents

Linking and Monikers 661 Compound Documents and Embedded Objects 662 Embedding and Linking Issues 662 Object Interfaces 663 Interface Inheritance 663 Unique Identifiers and the Registration Database 663 Marshaling, Concurrency, and Notifications 664 Data Objects and Uniform Data Transfer 665 Structured Storage and Streams 666 Clipboard and Drag and Drop 666 In-place Activation 666 OLE Automation 667 OLE Interfaces and Functions 667 Debugging 673 DispTest 673 MFC OLE 2 Classes 674 OLE Classes 674 OLE 2 Features Not in MFC 2.5 679 Updating the Registration Database 679 Automation Server Example Using MFC 679 Examining the Application Class 682 Dispatch Interface 683 Examining the Document Class 683 Getting, Setting, and Exposing Properties 689 Exposing Methods 690 Dispatch Map 692 Automation Client Example 692 Visual Basic for Applications 692

Chapter 17 Lagniappe 694

Sharp Wizard -J* 694 Oracle Palmtop Glue 696 Monitoring and Tracing Tools 696 odbc Inspector 697 SQL Inspector 699 Dr. DeeBee Tools 699 DataSync 703 Contents xxiii

Rules and Operation 703 Subset Definition 704 Access Upsizing Tools 704 Permissions 706 RoboHELP 706 Query Analyzer 707 SQL Code Profiler 708 Workgroup Applications 709 Schedule+ 710 Lotus Notes Connectivity 710 УВЯШ 711 Using Voice and Sound in Database Applications 711 Attaching Sounds to Alerts 711 Voice Recognition 711 Windows Sound System 712 Video for Windows 718 MCI Command Messages for A VI Data 718 MCI Control 719 Computer Eyes 720

Appendix A Windows Multi-DBMS Programming Companion Software 721 Companion CD-ROM 721 IMPORTANT NOTICE 721 CD-ROM Contents 722 SQL Scripts for the Sample Databases 723 ScreenCam Movies 725 ODINFO 726 Windows Software 726 Code Manager and Search Professional 726 Crystal Reports for Windows 726 ObjectView Limited Edition 727 Microsoft ODBC Desktop Drivers 727 ODBSEEME 727 Q+E Database Library and MultiLink/VB 727 Quadbase-SQL 3.0a 727 xxiv Contents

Microsoft Video for Windows Runtime System 728 Watcom SQL 3.2 Runtime System for Windows 728 SDP Technologies S-Designor Evaluation Kit 728

Appendix В Sample ODBC Initialization (ODBC.INI)

File for a Client PC 729

Appendix С Sources for ODBC Applications and Tools 737

Appendix D ODBC Driver Contact Information 742

Index 749

';; ••••','• , .;:

fr