The Definitive Guide to Sqlite
Total Page:16
File Type:pdf, Size:1020Kb
The Definitive Guide to SQLite ■■■ Michael Owens The Definitive Guide to SQLite Copyright © 2006 by Michael Owens All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13: 978-1-59059-673-9 ISBN-10: 1-59059-673-0 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editors: Jason Gilmore, Keir Thomas Technical Reviewer: Preston Hagar Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade Project Manager: Beth Christmas Copy Edit Manager: Nicole LeClerc Copy Editor: Liz Welch Assistant Production Director: Kari Brooks-Copony Production Editor: Katie Stence Compositor: Susan Glinert Proofreader: April Eddy Indexer: Toma Mulligan Artist: Kinetic Publishing Services, LLC Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code section. To my family: Gintana, Natalie, and Riley To my parents: Larry and Nancy And to my grandfather: C. R. Clough Contents at a Glance Foreword . xv About the Author . xvii About the Technical Reviewer . xix Acknowledgments . xxi ■CHAPTER 1 Introducing SQLite . 1 ■CHAPTER 2 Getting Started . 17 ■CHAPTER 3 The Relational Model . 47 ■CHAPTER 4 SQL . 73 ■CHAPTER 5 Design and Concepts . 171 ■CHAPTER 6 The Core C API . 205 ■CHAPTER 7 The Extension C API . 255 ■CHAPTER 8 Language Extensions . 301 ■CHAPTER 9 SQLite Internals . 341 ■APPENDIX A SQL Reference . 365 ■APPENDIX B C API Reference . 395 ■APPENDIX C Codd’s 12 Rules . 423 ■INDEX . 425 v Contents Foreword . xv About the Author . xvii About the Technical Reviewer . xix Acknowledgments . xxi ■CHAPTER 1 Introducing SQLite . 1 An Embedded Database . 1 A Developer’s Database . 2 An Administrator’s Database . 3 SQLite History . 3 Who Uses SQLite . 4 Architecture . 5 The Interface . 6 The Compiler . 6 The Virtual Machine . 6 The Back-end . 7 Utilities and Test Code . 8 SQLite’s Features and Philosophy . 8 Zero Configuration . 8 Portability. 8 Compactness. 8 Simplicity . 9 Flexibility . 9 Liberal Licensing. 9 Reliability . 10 Convenience . 10 Performance and Limitations . 11 Who Should Read This Book . 14 How This Book Is Organized . 14 Additional Information . 16 Summary . 16 vii viii ■CONTENTS ■CHAPTER 2 Getting Started . 17 Where to Get SQLite . 17 SQLite on Windows . 18 Getting the Command-Line Program . 18 Getting the SQLite DLL. 20 Compiling the SQLite Source Code on Windows. 21 Building the SQLite DLL with Microsoft Visual C++ . 25 Building a Dynamically Linked SQLite Client with Visual C++ . 28 Building SQLite with MinGW . 29 SQLite on POSIX Systems . 31 Binaries and Packages. 31 Compiling SQLite from Source . 33 Working with SQLite Databases . 34 The CLP in Shell Mode . 34 The CLP in Command-Line Mode . 41 Database Administration . 42 Creating, Backing Up, and Dropping Databases . 42 Getting Database File Information. 43 Other SQLite Tools . 45 Summary . 45 ■CHAPTER 3 The Relational Model . 47 Background . ..