logo资料库

Delphi深度编程-FireDAC篇.pdf

第1页 / 共549页
第2页 / 共549页
第3页 / 共549页
第4页 / 共549页
第5页 / 共549页
第6页 / 共549页
第7页 / 共549页
第8页 / 共549页
资料共549页,剩余部分请下载后查看
Delphi in Depth: FireDAC ________________________________ by Cary Jensen
Delphi in Depth: FireDAC Published by Jensen Data Systems, Inc., USA. Copyright 2017 Cary Jensen, Jensen Data Systems, Inc. World rights reserved. The code samples and example database depicted herein are fictitious, and were created for this book as copyrighted freeware to be used by this book's readers. The information and code samples contained or referred to in this book are provided as is, without any express, statutory, or implied warranties. Neither the author nor Jensen Data Systems, Inc. will be held liable in any way for any damages caused or alleged to be caused either directly or indirectly by this book or its contents, the code samples and example database, or any other related online content and/or files for any particular purpose. The copyright prevents you from republishing the content, code, example database, and any online accompanying content in print, electronic media, or in any other form without the prior permission and explicit written permission of the author. No part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way, in the original or in a translated language, including but not limited to photocopy, photograph, digital, magnetic, or other record without the prior permission and explicit written permission of the author. ISBN-10: 1546391274 ISBN-13: 978-1546391272 ISBN-10: (e-book edition) Printed copies of this book are available for sale from companies listed at, and linked to from, http://www.JensenDataSystems.com/firedacbook. Any other download or sale outlet is likely to be illegal. This is not a free ebook - do not distribute it. Project Editor: Loy Anderson Contributing Technical Editors: Dmitry Arefiev, Holger Flick, Jens Fudge, and Bruce McGee Cover Designer: Loy Anderson Indexer: Cary Jensen For more information and links for purchasing this book, visit: http://www.JensenDataSystems.com/firedacbook Delphi is a trademark of Embarcadero Technologies. Windows is a trademark of Microsoft Corporation. Advantage Database Server is a trademark of SAP. Other product and company names mentioned herein or in accompanying online material may be the trademarks of their respective owners.
Chapter Titles v Chapter Titles Chapter Titles .................................................................................................................. v Table of Contents ......................................................................................................... vii About the Author ........................................................................................................ xvii About the Technical Reviewers .................................................................................. xix Acknowledgements ..................................................................................................... xxi Introduction ..................................................................................................................... 1 Chapter 1 Overview of FireDAC ..................................................................................... 5 Chapter 2 Connecting to Data ..................................................................................... 15 Chapter 3 Configuring FireDAC ................................................................................... 47 Chapter 4 Basic Data Access ...................................................................................... 81 Chapter 5 More Data Access ..................................................................................... 109 Chapter 6 Navigating and Editing Data .................................................................... 145 Chapter 7 Creating Indexes ....................................................................................... 165 Chapter 8 Searching Data .......................................................................................... 197 Chapter 9 Filtering Data ............................................................................................. 217 Chapter 10 Creating and Using Virtual Fields .......................................................... 259 Chapter 11 Persisting Data ........................................................................................ 297 Chapter 12 Understanding FDMemTables ................................................................ 329 Chapter 13 More FDMemTables: Cloned Cursors and Nested DataSets ............... 369 Chapter 14 The SQL Command Preprocessor ......................................................... 397 Chapter 15 Array DML ................................................................................................ 425 Chapter 16 Using Cached Updates ........................................................................... 439 Chapter 17 Understanding Local SQL ...................................................................... 487 Appendix A Code Download, Database Preparation, and Errata ............................ 507 Index ............................................................................................................................ 519
Table of Contents vii Table of Contents Dedication ......................................................................................................... 3 Chapter Titles .................................................................................................................. v Table of Contents ......................................................................................................... vii About the Author ........................................................................................................ xvii Cary Jensen ................................................................................................... xvii About the Technical Reviewers .................................................................................. xix Dmitry Arefiev ............................................................................................... xix Holger Flick ................................................................................................... xix Jens Fudge ...................................................................................................... xx Bruce McGee .................................................................................................. xx Acknowledgements ..................................................................................................... xxi Introduction ..................................................................................................................... 1 Who Is This Book For ...................................................................................... 2 Conventions ...................................................................................................... 2 Chapter 1 Overview of FireDAC ..................................................................................... 5 FireDAC Features ............................................................................................. 6 Cross-Platform Support .......................................................................................... 7 Exceptional Support for Databases ......................................................................... 7 Flexible Queries Using the SQL Command Preprocessor ...................................... 8 Blazing Performance with Array DML ................................................................... 8 Support for a Variety of Query Execution Modes ................................................... 9 Powerful Monitoring Capabilities ........................................................................... 9 Cached Updates .................................................................................................... 10 Result Set Persistence ............................................................................................ 10 Data Type Mapping ............................................................................................... 11 Local SQL .............................................................................................................. 11 Additional Features ............................................................................................... 12 Connection Recovery ................................................................................................................... 12 Advanced Transaction Support ..................................................................................................... 12 Built-In Dialog Support ................................................................................................................ 12 Support for Database-Specific Services........................................................................................ 12 Customizable Data Access ........................................................................................................... 13 Batch Move Support ..................................................................................................................... 13
viii Delphi in Depth: FireDAC Written in Object Pascal .............................................................................................................. 13 Chapter 2 Connecting to Data ...................................................................................... 15 Creating Unnamed Connections ..................................................................... 15 Creating Temporary Connections ......................................................................... 16 Defining a Temporary Connection Using FDConnection.Params ........................ 26 Defining a Temporary Connection at Runtime ...................................................... 27 Creating Named Connections ......................................................................... 28 Creating Named Connections Definition Using the Database Explorer ............... 29 Creating a Named Connection Definition Using the FireDAC Explorer .............. 33 Creating a Persistent Connection .......................................................................... 36 Creating a Private Connection .............................................................................. 39 Connecting to Any Database Using ODBC .................................................... 41 Chapter 3 Configuring FireDAC ................................................................................... 47 Share Configuration Properties ....................................................................... 48 Configuration Property Inheritance ...................................................................... 48 Overriding Individual Configuration Properties ................................................... 50 Restoring Configuration Property Inheritance ...................................................... 50 Configuring the Shared Properties .................................................................. 51 Fetch Options ......................................................................................................... 54 General Fetching .......................................................................................................................... 56 Items to Fetch .............................................................................................................................. 57 Items to Cache ............................................................................................................................. 57 Master-Detail ............................................................................................................................... 57 Live Data Window ....................................................................................................................... 58 Format Options ...................................................................................................... 58 Data Mapping Rules .................................................................................................................... 60 Handling BCD/FmtBCD Type and DataSnap Compatibility ....................................................... 62 Handling String Type ................................................................................................................... 62 Parameters Default Type .............................................................................................................. 63 Value Preprocessing .................................................................................................................... 63 Dataset Sorting ............................................................................................................................. 64 Quotation Identifier ...................................................................................................................... 64 Default Field Formats .................................................................................................................. 65 Resource Options ................................................................................................... 65 Command Text Processing .......................................................................................................... 67 Persistence Mode ......................................................................................................................... 68 Command Execution .................................................................................................................... 69 Connection Resources .................................................................................................................. 69 Update Options ...................................................................................................... 70
Table of Contents ix General Updating.......................................................................................................................... 72 Locking......................................................................................................................................... 72 Refreshing .................................................................................................................................... 73 Automatic Incrementing ............................................................................................................... 73 Posting Changes ........................................................................................................................... 74 Transaction Options .............................................................................................. 75 Isolation Level .............................................................................................................................. 76 Update Ability .............................................................................................................................. 76 Automatic Committing ................................................................................................................. 77 DBMS-Specific Parameters .......................................................................................................... 77 Disconnection Action ................................................................................................................... 78 Nesting ......................................................................................................................................... 78 Understanding UpdateOptions.UpdateMode .................................................. 78 Chapter 4 Basic Data Access ...................................................................................... 81 The User Interface and Data Binding ............................................................. 85 Navigation and VCL Data Links ........................................................................... 86 The DBNavigator ......................................................................................................................... 86 Multi-Record VCL Controls and Navigation: DBGrid and DBCtrlGrid ...................................... 89 Navigation and LiveBindings ................................................................................ 91 The BindNavigator ................................................................................................ 92 Position-Related LiveBindings .............................................................................. 94 Understanding FDTable .................................................................................. 97 Configuring an FDTable ....................................................................................... 97 Executing Datasets at Design Time ....................................................................... 99 Executing DataSets at Runtime ........................................................................... 100 When Should You Connect? ................................................................................ 100 Live Data Window ............................................................................................... 102 Executing Queries and Stored Procedures .................................................... 103 Executing Queries ............................................................................................... 103 Executing Stored Procedures ........................................................................ 105 Chapter 5 More Data Access ..................................................................................... 109 Parameterized Queries and Stored Procedures ............................................. 109 The Advantages of Parameters ............................................................................ 110 Greater Flexibility ...................................................................................................................... 110 Improved Performance ............................................................................................................... 110 Prevention of SQL Injection ....................................................................................................... 111 Defining Parameters at Design Time .................................................................. 112 Parameterized FDQueries and the Query Editor................................................ 115
分享到:
收藏