reverse of cover - firebase - o maior portal sobre … issues that prohibit reuse of the legacy...

37

Upload: trinhnguyet

Post on 12-Apr-2018

220 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and
Page 2: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

R e v e r s e o f C o v e r

Page 3: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

i

Page 4: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

ii

The Firebird Book (Second Edition): A Reference for Database Developers

Copyright 2011, 2012 by Helen Borrie and IBPhoenixAll rights reserved. Except where content is indicated explicitly as copied from documents licensed under open document licensing, no part of this work may be reproduced in any form or by any means, electronic or mechanical, without the prior written permission of the copyright owners and the publisher, IBPhoenix Publications.Reviewers were Aage Johansen, Dimitry Sibiryakov, Thomas Steinmaurer, Calin PirteaDesign of the cover and Part headers is by Stella Damaschin.Body text is 10pt Garamond.

Page 5: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

iii

AUTHOR’S FOREWORDThis, the second edition of The Firebird Book, has been gestating for more than seven years, since the first edition in August, 2004. The first book’s milestone was Firebird 1.5. Its objective was to to provide an up-to-date working reference for developers, whether coming to Firebird from another database management system or moving into it with past experience in its closed source cousin, InterBase. In the intervening years, Firebird has evolved through three further major versions: 2.0, 2.1 and 2.5. At the time of this writing, all three are still under maintenance and the re-architected version 3.0 is in alpha development. Maintenance of version 1.5 ceased in 2009. The energy and dedication of Firebird’s development team continue to be a source of wonder and inspiration to me and, I’m sure, to anyone else who works with Firebird. The polyglot Core team—Dmitry Yemanov, Vlad Khorsun, Alex Peshkov and Adriano dos Santos Fernandes—works closely and tirelessly under Dmitry’s chieftainship. Pavel Cisar and Philippe Makowski perform quality assurance testing and Claudio Valderrama is responsible for scrutinising incoming code changes. Claudio’s hand is often seen in improvements to the command-line tools, as well.Because Firebird is distributed free, in all senses of the word, it produces no revenue to pay salaries to the code workers. Except for the QA people, these volunteers depend on Firebird Foundation grants to supplement their incomes to make space for their Firebird work.The Firebird Foundation is funded by donations, cash sponsorships and membership subscriptions from individuals and companies that perceive and acknowledge the benefits of using Firebird and keeping it under active development. You can view the current list of sponsors at http://www.firebirdsql.org/en/sponsors/. Bless ’em all!Some sponsors contribute much more than cash. IBPhoenix, for example, contributes the manpower for QA, binary builds and basic documentation. Neither this book nor its predecessor would have come to fruition without IBPhoenix funding. Broadview Software hosts the issue tracker, pre-release and build servers while IBSurgeon funds the hosting and development of the Firebird web site at www.firebirdsql.org.Amongst the volunteers who contribute their time and expertise to the Firebird Project without grants I must name Paul Vinkenoog, who has been almost single-handedly responsible for filling the free documentation gap between the legacy InterBase manuals and the release notes that are distributed with the binary kits. It is a vast and ongoing task that is often thankless. At the time of writing this, Paul is working with Dmitry Yemanov to produce comprehensive on-line SQL documentation that will not be inhibited by the copyright issues that prohibit reuse of the legacy InterBase material.Under the Firebird Project umbrella, volunteers also develop and maintain several of the drivers and language interfaces for Firebird—Jaybird (for Java), the Firebird .NET providers, the ODBC driver and the interfaces for PHP and Python.If you are coming to Firebird as a newcomer, welcome! I wish you a long and happy experience with our software. To you and to those devotees who are freshening up your Firebird experience, I wish you great satisfaction from your use of this Second Edition of The Firebird Book.Helen Borrie, authorDecember 2011

Page 6: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

iv

This page is intentionally left blank.

Page 7: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

v

ABOUT THE AUTHORHelen Borrie is a contracting software engineer who doubles as a writer and technical editor. She has been involved with database development for 30 years and with Firebird and its ancestors since 1996.Helen is an active member of the Firebird online support community and a founding member of the Firebird Foundation, incorporated as a non-profit organisation in New South Wales, Australia, in 2002.

Page 8: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

vi

Page 9: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • vii

ContentsAuthor’s Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii

About the Author. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v

Part I Firing Up with Firebird. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1 Firebird Servers and Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3The Role of the Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Operating System Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Server-side Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Multi-database Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Server Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Database Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

The Firebird Server Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Resource Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Comparing Superserver, Superclassic and Classic Architectures . . . . . . . . . 8Embedded Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Introduction to Client/Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Servers and Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Client/Server vs File-Served Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Characteristics of a Client/Server DBMS . . . . . . . . . . . . . . . . . . . . . . . . . . 14Typical Deployment Topologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Firebird Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20What is a Firebird Client?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21The Firebird Client Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Table of Contents

Page 10: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

viii • Contents

2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Server Memory (All Platforms) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Installation Drives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Minimum Machine Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Operating System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

How to Get an Installation Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Kit Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Installing a Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29The FIREBIRD Variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Finalise your Server Choice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Linux and Many Other POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33MacOSX/Darwin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36Other Host Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Testing Your Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Network Protocol. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Checking That the Firebird Server Is Running. . . . . . . . . . . . . . . . . . . . . . 38

The Client Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40Performing a Client-Only Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Installing an Embedded Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Uninstalling Firebird. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47MacOSX/Darwin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

Other Things You Need to Know . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48Default User Name and Password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

3 Network Setup and Initial Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Network Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

TCP/IP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Named Pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Local Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Mixed Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

A Network Address for the Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54Hosts File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

Page 11: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • ix

Server Name and Database Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55Connection string syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Inconsistent connection strings for Windows connections . . . . . . . . . . . . 57

Testing Connections. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57If ping fails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

Initial Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59The Firebird Configuration File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

4 Operating Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Looking for a User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Running Firebird on POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

Superserver and Superclassic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Classic server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

Running Firebird on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Servers and the Guardian. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Running as a service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Running as an application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Running Firebird on MacOSX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70The Super* Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70Classic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

Mixed Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70Database aliasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71The SYSDBA User and Password. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73Administering Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

The employee.fdb Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Starting isql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Summary of Command-line Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

5 Migration Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Version Lineage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Firebird 1.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Firebird 1.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Firebird 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Firebird 2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

Page 12: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

x • Contents

Firebird 2.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Backward Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

Preparing to Migrate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Major Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Sub-releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Dialect 1 Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85Back Up! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

Migration Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88Get the Latest Sub-release! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88The FIREBIRD Variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88Platform Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Security Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Metadata Repair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90Application Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

Migration Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

Part II Firebird Data Types & Domains. . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

6 About Firebird Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

Where to Specify Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99Supported Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99SQL “Dialects”. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100Optional SQL-92 Delimited Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . 101Context Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101Pre-defined Date Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Converting Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Changing column and domain definitions . . . . . . . . . . . . . . . . . . . . . . . . 105Keywords Used for Specifying Data Type . . . . . . . . . . . . . . . . . . . . . . . . 106

Demystifying NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107NULL in expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107NULL in calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108Gotchas with True and False. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108Setting a value to NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

Page 13: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xi

7 Number Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111Numerical Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

Points About Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112Operations on Number Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112Integer Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113Integer/integer division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

Fixed Decimal (Scaled) Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Internal Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116Special restrictions in static SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117Behaviour of fixed types in operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

Floating Point Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120Supported Float Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121Arithmetic mixing fixed and floating-point types. . . . . . . . . . . . . . . . . . . 121

8 Date and Time Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Choices for Date and Time Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123TIMESTAMP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

Date/Time Literals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125Recognised Date/Time Literal Formats . . . . . . . . . . . . . . . . . . . . . . . . . . 125Pre-defined Date Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128Type-casting of Date/Time Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Date and Time Context Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130Specifying Sub-seconds Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

Operations Using Date and Time Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131General rules for operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132Using CAST( ) with Date/Time Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 133Quick Date/Time Casts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136The EXTRACT( ) Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136Other Date/Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

A sample date/time type conversion task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

Page 14: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xii • Contents

9 Character Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141String Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

String Delimiter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Concatenation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Escape Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143Limitations with Character Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144Fixed-length Character Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Variable-length Character Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

Character Sets and Collation Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Client Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148Firebird character sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149Special Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152Transliteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154Collation Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155Adding an Alias for a Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159Custom character sets and collations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160Metadata Text Conversion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

10 BLOBS and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167BLOBs and Subtypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

Supported User Subtypes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168Custom Subtypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168Declaration Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169BLOB Segments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169When to Use BLOB Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170Operations on BLOBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

Array Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173ARRAY Types and SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173When to Use an Array Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173Eligible Element Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173Defining Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174Storage of ARRAY Columns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Accessing Array Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Limited DSQL Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

Page 15: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xiii

11 Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177Benefits of Using Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

Creating a Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178Using a Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

Domains in Column Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182Domains in PSQL Variable Declarations . . . . . . . . . . . . . . . . . . . . . . . . . 184Using Domains with CAST(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184Where domains won't work. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185Defining a BOOLEAN Domain. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

Changing a Domain Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185Dropping a Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

Part III A Database & Its Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

12 Designing and Defining a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191Designing a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

Description and analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192The Physical Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193Referential integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197Indexes and query plans. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198Stored procedures and triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198Generators (Sequences) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

Object Naming Conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Optional SQL-92 delimited identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . 201File-naming Conventions for Databases. . . . . . . . . . . . . . . . . . . . . . . . . . 201

Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202The system tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

Firebird’s SQL Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202SQL “Dialects”. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203Firebird and the ISO Standards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204Data Definition Language (DDL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204Data Manipulation Language (DML) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204Procedural language (PSQL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205Interactive SQL (ISQL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

Schemas and Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

Page 16: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xiv • Contents

Using isql to run scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206

13 Data Definition Language—DDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207SQL Data Definition Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

CREATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207RECREATE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208ALTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208DECLARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209DROP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209Storing Descriptive Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

Object Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Using DDL to Manage User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Reference Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

14 Creating and Maintaining a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215Physical Storage for a Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215About Security Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

ISC_USER and ISC_PASSWORD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217Creating a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

Dialect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217CREATE DATABASE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218Getting information about the database . . . . . . . . . . . . . . . . . . . . . . . . . . 220Single and Multi-file Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221The Database Cache. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223

Read-only Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227Keeping a Clean Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228

Background garbage collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229Sweeping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229Garbage collection during backup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229Objects and counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230Validation and repair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

Backup and Stand-by . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232Dropping a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

Page 17: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xv

15 Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235About Firebird Physical Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

Structural descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235Creating Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236

Table ownership and privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236CREATE TABLE statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236

Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Scope of Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Integrity Constraints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241The referential constraint. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Named constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242The NOT NULL Constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242The PRIMARY KEY constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243The UNIQUE constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248CHECK constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

Using External Files as Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251Restrictions and recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253Converting external tables to internal tables. . . . . . . . . . . . . . . . . . . . . . . 255Dropped database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256

Altering Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256Preparing to use ALTER TABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256Altering Columns in a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256

Removing (Dropping) a Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261The RECREATE TABLE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 261

Temporary Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261Global Temporary Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262Temporary Storage for Older Versions. . . . . . . . . . . . . . . . . . . . . . . . . . . 263

Tree Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264

16 Indexes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265Automatic vs User-defined Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

Importing legacy indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266Directional indexes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

Page 18: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xvi • Contents

Query plans. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267How Indexes Can Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

Sorting and grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268Comparisons. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

What to Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268When to index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269Using CREATE INDEX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

Mandatory elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269Optional elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270

Multi-column Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272OR predicates in queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272Search criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273

Inspecting Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273Making an Index Inactive. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273

Housekeeping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273‘Index is in use’ error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274Altering the structure of an index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274

Dropping an Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274

17 Referential Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275The FOREIGN KEY Constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276

Implementing the constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276Action triggers to vary integrity rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278

Interaction of Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279Custom Action Triggers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280Lookup Tables and Your Data Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280The REFERENCES Privilege. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282Handling Other Forms of Relationship . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282

One-to-one relationship. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282Many-to-many relationship . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283Self-Referencing Relationship . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286Mandatory relationships. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287

Page 19: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xvii

“Object is in Use” Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287

Part IV Working With Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289

18 Data Manipulation Language—DML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291The Concept of Sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

Cardinality and degree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292A table is a set. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292Output sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292Input sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293Output sets as input sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294Cursor sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294Nested Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

SQL Privileges and DML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296

19 DML Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297The SELECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

Clauses in a SELECT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298INSERT and UPDATE Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307

INSERT INTO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307UPDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311UPDATE OR INSERT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315MERGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316

The DELETE Statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318EXECUTE Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318Using Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

Batch operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320Queries That Execute Server-side Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

Executable procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321Selectable procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

DML operations and state-changing events . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322Referential integrity action clauses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322Custom triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322

Query Plans and the Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323Plans and the Firebird query optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . 323

Page 20: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xviii • Contents

Understanding the optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325Examples of plans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327Specifying your own plan. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332Optimal Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333Housekeeping indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335Index toolkit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337

20 Expressions and Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340

The Truth Testers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341Deciding What is True . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342

Elements Used in Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342SQL Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344

Precedence of Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344Concatenation Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345Logical Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350The IS [NOT] NULL Predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351Existential Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351

Considering NULL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354NULL in Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354NULL in Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355Gotchas with True and False. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355NULL and External Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356Setting a Value to NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356

Using Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357Computed Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357Search Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363Ordering and Grouping Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365Expression Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366CHECK expressions in DDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366Expressions in PSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367

Function Calls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367Conversion Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368

Page 21: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xix

String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369Function for Getting a Generator (Sequence) Value . . . . . . . . . . . . . . . . 371Aggregating Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372Functions for Setting and Getting Contextual Data. . . . . . . . . . . . . . . . . 373External Functions (UDFs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376

21 Querying Multiple Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381Kinds of Multi-table Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381

Joining. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382UNION queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382Using Relation Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382The internal cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383

Joining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384The INNER join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384OUTER joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387Equi-joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390Re-entrant joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391

Subqueries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393Specifying a column using a subquery. . . . . . . . . . . . . . . . . . . . . . . . . . . . 393Searching using a subquery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395Inserting using a subquery with joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395The Derived Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396

UNION Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396Union compatible sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396UNION ALL | DISTINCT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397Using run-time columns in unions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398Search and ordering conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399Re-entrant UNION queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399Recursive Queries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400

22 Ordered and Aggregated Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401Considerations for Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401

Presentation order of sorting clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403

The ORDER BY Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403Sorting items. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403

Page 22: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xx • Contents

Sort direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406NULLS placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406

The GROUP BY Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407The groupable field list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407Aggregating expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408The grouping item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409The HAVING sub-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411The COLLATE sub-clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412Using ORDER BY in a grouped query . . . . . . . . . . . . . . . . . . . . . . . . . . 412Advanced grouping conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412

Aggregating Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415AVG( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415SUM( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415MAX( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416MIN( ). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416Using COUNT( ) as an aggregating function . . . . . . . . . . . . . . . . . . . . . 416The LIST( ) function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417

23 Views and Other Run-time Set Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419Forms and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420

What is a view? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420Creating a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421How views can be useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425Some simple view specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425Read-only and updatable views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426Modifying a view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429Dropping a view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430Privileges for Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430Using views in SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431Using query plans for views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432

Derived Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433Rules for Derived Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434When to Use a Derived Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435

Common Table Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435Syntax for a CTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436

Other Virtual Set Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440

Page 23: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xxi

Global temporary tables (GTTs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440Selectable stored procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440External virtual tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441

24 Interactive SQL Utility (isql) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443Interactive Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443

Default text editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443Starting isql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444Connecting to a database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445Using the Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446Interactive Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450General isql Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451SHOW Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454SET Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463Exiting an interactive isql session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470

Command Mode isql. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470Operating isql in command mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470Command-line switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471

Creating and Running Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474About Firebird scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474Basic steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477Managing your schema scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480

Part V Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483

25 Overview of Firebird Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485The ACID Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486

Atomicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486Consistency. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486Isolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486Durability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486

Context of a Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487One transaction, many requests. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487

Transactions and the MGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488Post vs COMMIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488Rollback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489Row locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489

Page 24: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xxii • Contents

Table-level locks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490Inserts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491

Transaction “Aging” and Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491Transaction ID and age . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491“Interesting transactions” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492Background garbage collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492Keeping the OIT and the OAT moving . . . . . . . . . . . . . . . . . . . . . . . . . 494Transaction statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496

26 Configuring Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499Anatomy of a Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499

The Default Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499Default settings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500

About Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500Factors affecting concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501

Isolation level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501Standard levels of isolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501

Locking Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504Table Reservation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505

Uses for Table Reservation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505Parameters for table reservation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506

Other Optional Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507Record Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507

Dependent rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508Locking and Lock Conflicts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508

Timing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508Pessimistic locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508Lock conflicts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509

27 Programming with Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511The Language of Transactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511

The API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512Starting a Transaction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512

The transaction handle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512

Page 25: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xxiii

The transaction parameter buffer (TPB). . . . . . . . . . . . . . . . . . . . . . . . . . 513Accessing the Transaction ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514

Using the TID in applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514Progress of a Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515Nested Transactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515

User savepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515Exception handling extensions in PSQL . . . . . . . . . . . . . . . . . . . . . . . . . 517

The Logical Context. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517Ending transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518Diagnosing exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520Receiving exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521

Multi-database Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522Limbo transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522Restricting databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523

Pessimistic Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523Table-level locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524Statement-level locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524The “dummy update” hack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524Explicit locking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525

Stored Procedures, Triggers and Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . 528Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528“Savepoints” in PSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529Autonomous Transactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529

Tips for Optimizing Transaction Behaviour. . . . . . . . . . . . . . . . . . . . . . . . . . . . 529

Part VI Programming on the Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531

28 Procedural SQL—PSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533Overview of Server Code Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533

About Stored Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534About Relation Triggers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535About Database Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536About Executable Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536

PSQL Language Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536

Page 26: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xxiv • Contents

Restrictions on PSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538

Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538Elements of procedures and triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539

Statement terminator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539The CREATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540Header elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541Body elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541Language elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542

Programming constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544BEGIN...END blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544Conditional blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544Variables and Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546SELECT...INTO statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552Flow of control statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555Execute Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558

Using Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562The Undeclared Named Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563The Explicit Named Cursor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563

Developing Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567Adding comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567Case-sensitivity, white space and size . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568Managing your code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569Compiling stored procedures and triggers . . . . . . . . . . . . . . . . . . . . . . . 569Altering and dropping modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570Deleting source from modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571

Internals of the Technology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572Effects of changes to modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572

29 Stored Procedures and Executable Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573Styles of Stored Procedure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573Creating a Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574

Header elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574Body elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575

Executable Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577

Page 27: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xxv

Complex processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578Support for “live” client sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578Operations in executable procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578A multi-table procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579Using (calling) executable procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 581Outputs and exits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582Recursive Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582

Selectable Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583Uses for selectable procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584The Technique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585A simple procedure with nested SELECTs . . . . . . . . . . . . . . . . . . . . . . . 587Calling a selectable procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588Nested procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589A procedure with running totals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593Viewing an array through a stored procedure . . . . . . . . . . . . . . . . . . . . . 595

Testing procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596Procedures for combined use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596Using the Internal RDB$DB_KEY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597

About RDB$DB_KEY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597Benefits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597Inserting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599Duration of validity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600RDB$DB_KEY with multi-table sets . . . . . . . . . . . . . . . . . . . . . . . . . . . 601

Changing a Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601Effect on applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601Syntax for changing procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601

Dropping a Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604

Run-time PSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605Coding EXECUTE BLOCK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605Using EXECUTE BLOCK in applications . . . . . . . . . . . . . . . . . . . . . . . 607

30 Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609Classes of Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609

Table-level Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609“Database Triggers” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610DDL Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610

Page 28: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xxvi • Contents

About Table-level Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610Phase and event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611Status Active/Inactive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612

Creating Table-level Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612An alternative syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613Header elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613The trigger body . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614Special PSQL for Table-level Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . 614Table-level triggers at work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615Updating Other Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618Referential Integrity Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621Updating rows in the same table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624Implementing Auto-Incrementing Keys . . . . . . . . . . . . . . . . . . . . . . . . . . 625

Changing Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627ALTER TRIGGER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628CREATE OR ALTER TRIGGER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629RECREATE TRIGGER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629

Higher-level Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629Trigger Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629Creating and Changing the Higher-level Triggers . . . . . . . . . . . . . . . . . . 631

Dropping Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

31 Accessing Other Databases from PSQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633Extensions to EXECUTE STATEMENT. . . . . . . . . . . . . . . . . . . . . . . . . . 633

Autonomous Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633The Optional Extension Clauses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634Transaction Behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635External Queries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637

32 Error Handling and Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639Exceptions in PSQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639

Types of Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639What is an exception?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640Exceptions in Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640

Page 29: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xxvii

Trapping and Handling Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642The WHEN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642Nested exceptions as savepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644Exceptions in triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647Run-time Exception Messaging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648Error Codes Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649

Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649Uses for Events Notification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649Elements of the Events Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650Synchronous listening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651Asynchronous signalling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652Using POST_EVENT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653

Part VII Configuring Firebird . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655

33 Configuring Firebird and Its Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657Default Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657

Finding the Firebird Root Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658

Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659The Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 660

The Firebird Configuration File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662Parameter Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663Editing Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664Version Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664Parameters in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665

Configuring the TCP/IP Port Service. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665How the server sets the listening port. . . . . . . . . . . . . . . . . . . . . . . . . . . . 665Setting up a client to find the service port . . . . . . . . . . . . . . . . . . . . . . . . 667Configuring the services file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669

Embedded Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669

34 Configuration Parameters in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671Settings for All Platforms and Servers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671

AuditTraceConfigFile. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672

Page 30: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xxviii • Contents

CompleteBooleanEvaluation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672ConnectionTimeout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673DatabaseAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673DatabaseGrowthIncrement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673DeadlockTimeout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674DefaultDbCachePages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674DummyPacketInterval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674FileSystemCacheThreshold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675FileSystemCacheSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675GCPolicy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676LegacyHash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676LockAcquireSpins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676LockHashSlots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676LockGrantOrder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677LockMemSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677LockSemCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677LockSignal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678MaxUserTraceLogSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678OldColumnNaming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678OldSetClauseSemantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679RelaxedAliasChecking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679RemoteAuxPort. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679RemoteBindAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680RemoteFileOpenAbility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680RemoteServicePort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680RemoteServiceName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680RootDirectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681TcpRemoteBufferSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681TcpNoNagle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681TempBlockSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681TempCacheLimit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681TempDirectories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682

Settings Applicable to Microsoft Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683CpuAffinityMask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683GuardianOption. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683IpcName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684MaxUnflushedWrites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684MaxUnflushedWriteTime. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684ProcessPriorityLevel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684RemotePipeName. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685UsePriorityScheduler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685

Settings Applicable to POSIX Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685BugCheckAbort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685

Page 31: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xxix

Configuring external locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685UdfAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686ExternalFileAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687

Deprecated Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687OldParameterOrdering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687server_working_size_max. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688server_working_size_min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688CreateInternalWindow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688DeadThreadsCollection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688

35 Configuring and Managing Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689The gfix Tool Set. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689

Using the Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690Shutting Down a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690

Configuration Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693Default Cache Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693Forced Writes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694Access Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695Page Fill Capacity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696Sweep Interval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696SQL Dialect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697Page Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698

Management Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698Garbage collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699Sweeping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699Analysing and Repairing Logical Corruption . . . . . . . . . . . . . . . . . . . 700Transaction recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701Managing Database Shadows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703

Summary of gfix switches and options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704gfix error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706

Part VIII Administering & Securing Firebird . . . . . . . . . . . . . . . . . . . . . . 707

36 Protecting the Server and its Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709Securing the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709

Physical Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709Use Securable Filesystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710

Page 32: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xxx • Contents

Protect Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710Platform-based protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710Wire Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714Web and Other n-Tier Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714Use Dedicated Hosts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714Establish Trustworthiness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714Firewalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715Server Multi-hop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715Denial-of-Service Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715

Managing User Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716The Security Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716Firebird “Native” Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717Platform Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717Privileged Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719Entering User Credentials via SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720The gsec Utility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722

37 Database-Level Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729Default Security and Access. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729

Planning an Access Scheme. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730Metadata Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730

SQL Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731

Native Firebird users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732POSIX users and groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732Windows trusted users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732Users with escalated privileges. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733Database objects as ‘users’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733

Privilege Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733Granting Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734

UPDATE rights on columns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734REFERENCES rights on columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735Privileges needed by objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736Granting the EXECUTE privilege . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736

Privileges on Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737

Page 33: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xxxi

Bundling Multiple Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737Lists of privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737The ALL privilege . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738

Privileges for Multiple Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739Granting the Right to Grant Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740Granting Privileges on Behalf of Another . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741

The GRANTED BY clause. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742The System Role RDB$ADMIN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742

Extending RDB$ADMIN power for Windows Administrators . . . . . . . 742Unintended Effects with Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743Revoking Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744

Using REVOKE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744Security Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747

Creating a script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 748Installing perms directly from a procedure . . . . . . . . . . . . . . . . . . . . . . . 750

A Trick to Beat Idiot Users and Bad Guys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752

38 Monitoring and Logging Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753Monitoring Database Activity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753

How Monitoring Works. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753Using MON$ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754The MON$ Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757

Trace and Audit Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757Modes of Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757Trace Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758Trace Plug-in Facilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763

Collecting Database Statistics—gstat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763gstat command-line tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763

Monitoring Locks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774Locking in Firebird. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774The Lock Manager Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774The Lock Print Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777Lock configuration settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796

Page 34: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xxxii • Contents

39 Backing Up Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799gbak or nBackup? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799The gbak Utility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800

About gbak Backup Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800gbak’s other talents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801Database backup & restore rights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802Running a Backup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803Running a Restore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807Restore switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 809Using gbak with the Firebird Services Manager . . . . . . . . . . . . . . . . . . . . 813gbak Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815

Incremental Backup Tool (nBackup) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818About nBackup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819Making Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 820Restoring from nBackup Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 824Using the Freeze Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825SQL Support for nBackup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 826nBackup command-line options summary . . . . . . . . . . . . . . . . . . . . . . . . 828

Database Shadowing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828Benefits and limitations of shadowing . . . . . . . . . . . . . . . . . . . . . . . . . . . 828Implementing shadowing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 829

Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833“Warm Backups” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833

40 The Services Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835About the Services Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835Accessing the Services Manager API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835

Services Manager Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836The fbsvcmgr Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836

Using fbsvcmgr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836fbsvcmgr specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 838Services API Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 839

Part IX Appendices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 841I Internal and External Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843

Internal Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843

Page 35: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xxxiii

Conditional Logic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843Date and Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844String and Character Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846BLOB Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851Mathematical Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 852Trigonometrical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854Binary Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855Miscellaneous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856

External Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857Conditional Logic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857Mathematical Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858Date and Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 863String and Character Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866BLOB Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871Trigonometrical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 872

Building regular expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 878OR-ing terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879Sub-expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879Escaping special characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879

II Reserved and Non-Reserved Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881

III Context Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 893About Context Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 893

IV Firebird Limits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 895V System Tables and Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899

Metadata Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899System Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 922

Monitoring Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 924VI Character Sets and Collations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933

Implemented and Activated Character Sets . . . . . . . . . . . . . . . . . . . . . . . 933VII Firebird Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 939VIII SQLSTATE Codes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961IX Database Repair How-To . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969

Indications of Possible Corruption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969Preparing for Analysis and Repair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 970

Page 36: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

xxxiv • Contents

Steps for Recovery Using Command-line Tools . . . . . . . . . . . . . . . . . . . . . . . . 971Step 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 971Step 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972Step 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972Step 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972Step 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973Step 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973

Failed Repair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973X Default Disk Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975XI Healthcare for Databases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983

Considerations for a Maintenance Regime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9831 Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9832 Garbage Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9843 Index Statistics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9864 Page Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9905 Disk Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 990

Other Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991Usage Monitoring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991Data Access and Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991

XII Upgrade Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993Security Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993Metadata Repair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 996

XIII Application Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001Application Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001

Dynamic client/server applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001The Firebird Core API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1002Application interfaces using the API. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1002

Designing Databases for Client/Server Systems . . . . . . . . . . . . . . . . . . . . . . . 1004XIV Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009

Free Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009Free help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1010

SQL and Firebird server support. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1010Client interface support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1010

Third-Party Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1011

Page 37: Reverse of Cover - FireBase - O maior portal sobre … issues that prohibit reuse of the legacy InterBase material. Under the Firebird Project umbrella, volunteers also deve lop and

Contents • xxxv

Commercial Help and Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1012

Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i

GLOSSARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii