The Definitive Guide to Sqlite, Second Edition (Expert's Voice In
Total Page:16
File Type:pdf, Size:1020Kb
BOOKS FOR PROFESSIONALS BY PROFESSIONALS® THE EXPERT’S VOICE® IN OPEN SOURCE Companion eBook Available The Definitive Guide to SQLite The Definitive Dear Reader, Outside of the world of enterprise computing there is one database that enables a huge range of software and hardware to flex relational database capabilities, without the baggage and cost of traditional database management systems. Guide to That database is SQLite—an embeddable database with an amazingly small footprint, yet it can handle databases of enormous size. SQLite comes equipped The Definitive Guide to Grant Allen with an array of powerful features available through a host of programming and development environments. It is supported by languages such as C, Java, Perl, PHP, Python, Ruby, TCL, and more. The Definitive Guide to SQLite, 2nd Edition is devoted to complete cover- age of the latest version of this powerful database. It offers a thorough over- SQLite view of SQLite’s capabilities and APIs. The book also uses SQLite as the basis for helping newcomers make their first foray into database development. In only a short time you can be writing programs as diverse as a server-side browser plug-in or the next great iPhone or Android application! • You’ll learn about SQLite extensions for C, Java, Perl, PHP, Python, Ruby, and Tcl. • You’ll get solid coverage of SQLite internals. SQLite • You’ll explore developing iOS (iPhone) and Android applications with SQLite. Mike Owens SQLite is the solution chosen for thousands of products around the world, from mobile phones and GPS devices to set-top boxes and web browsers. You almost certainly use SQLite every day without even realizing it! Take control of this compact and powerful tool to Sincerely, Grant Allen and Mike Owens embed sophisticated SQL databases within your applications THE APRESS ROADMAP Companion eBook Beginning Database Design Applied Mathematics The Definitive Guide for Database to SQLite SECOND Professionals EDITION See last page for details Beginning SECOND EDITION on $10 eBook version SQL Queries Owens SOURCE CODE ONLINE Allen ISBN 978-1-4302-3225-4 Grant Allen and Mike Owens www.apress.com 54999 US $49.99 Shelve in: Databases User level: 9 781430 232254 Intermediate–Advanced The Definitive Guide to SQLite Second Edition ■ ■ ■ Grant Allen Mike Owens The Definitive Guide to SQLite, Second Edition Copyright © 2010 by Grant Allen and Mike 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 (pbk): 978-1-4302-3225-4 ISBN-13 (electronic): 978-1-4302-3226-1 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Jonathan Gennick Technical Reviewer: Richard Hipp Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Jennifer L. Blackwell Copy Editor: Kim Wimpsett Production Support: Patrick Cunningham Indexer: Julie Grady Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. 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 www.apress.com. To my mother for her endless support of all my crazy ideas Contents at a Glance About the Authors .................................................................................................... xvi About the Technical Reviewer ................................................................................ xvii Acknowledgments ................................................................................................. xviii Introduction ............................................................................................................. xix ■Chapter 1: Introducing SQLite.................................................................................. 1 ■Chapter 2: Getting Started ..................................................................................... 17 ■Chapter 3: SQL for SQLite ...................................................................................... 47 ■Chapter 4: Advanced SQL for SQLite ...................................................................... 87 ■Chapter 5: SQLite Design and Concepts ............................................................... 125 ■Chapter 6: The Core C API .................................................................................... 153 ■Chapter 7: The Extension C API ........................................................................... 195 ■Chapter 8: Language Extensions ......................................................................... 219 ■Chapter 9: iOS Development with SQLite ............................................................. 253 ■Chapter 10: Android Development with SQLite .................................................... 279 ■Chapter 11: SQLite Internals and New Features .................................................. 303 Index ....................................................................................................................... 323 iv Contents About the Authors .................................................................................................... xvi About the Technical Reviewer ................................................................................ xvii Acknowledgments ................................................................................................. xviii Introduction ............................................................................................................. xix ■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 ...........................................................................................................................................