Preface What you need for this book for the IDE of our choice,Eclipse,to run.Download Android SDK from the Android developer's site and Android ADT plugin for Eclipse.Alternatively,you can download the Eclipse ADT bundle that contains Eclipse SDK and the ADT plugin.You can also try An 010 Who this book is for Android SQLite Essentials is a guide book for Android programmers who want to explore SQL te database-based Android a little Conventions In this book,you will find a number of styles of text that distinguish between different kinds of information.Here are some examples of these styles and an explanation of their meaning. Code words in text,database table names,folder names,filenames,file extensions aeieraog0aaeheetemasioms A block of code is set as follows: Contentvalues cv new ContentValues(); ev.put (COL_NAME,"john doe) null,cv) Any command-line input or output is written as follows adb shell SQLite3 version SQLite 3.7.11:API 16-19 8 QLite3.7.4:AP111-15 SQL1te3.6.22:API8-10 SQLite 3.5.9:API 3 -7 【21
Preface [ 2 ] What you need for this book To efficiently use this book, you will require a working system with Windows, Ubuntu, or Mac OS preinstalled. Download and set up the Java environment; we require this for the IDE of our choice, Eclipse, to run. Download Android SDK from the Android developer's site and Android ADT plugin for Eclipse. Alternatively, you can download the Eclipse ADT bundle that contains Eclipse SDK and the ADT plugin. You can also try Android Studio; this IDE, which just moved to beta, is also available on the developer site. Make sure your operating system, JDK, and IDE are all of either 32 bit or 64 bit. Who this book is for Android SQLite Essentials is a guide book for Android programmers who want to explore SQLite database-based Android applications. The reader is expected to have a little bit of hands-on experience of Android fundamental building blocks and the know-how of IDE and Android tools. Conventions In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning. Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To close the Cursor object, the close() method call will be used." A block of code is set as follows: ContentValues cv = new ContentValues(); cv.put(COL_NAME, "john doe"); cv.put(COL_NUMBER, "12345000"); dataBase.insert(TABLE_CONTACTS, null, cv); Any command-line input or output is written as follows: adb shell SQLite3 -version SQLite 3.7.11: API 16 - 19 SQLite 3.7.4: API 11 - 15 SQLite 3.6.22: API 8 - 10 SQLite 3.5.9: API 3 - 7
Preface New terms and important words are shown in bold.Words that you see on the screen,in menus or dialog boxes for example,appear in the text like this:"Go to Android Virtual Device Manager from the Windows menu to start the emulator." [ Warnings or important notes appear in a box like this. [的 Tips and tricks appear like this Reader feedback Feedback from our readers is always welcome.let us know what you think about this book-what you liked or may have disliked.Reader feedback is important for us to develop titles that you really get the most out of. To send us general feedback,simply send an e-mail to feedbackepacktpub.com, and mention the book title via the subject of your message. If there is a topic that you have exp rtise in and you are interested in either writing or contributing to a book,see our author guide on www.packtpub.com/authors. Customer support va number of things Downloading the example code You can download the rchased .packtpub. elsewhere,you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you. 【31
Preface [ 3 ] New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Go to Android Virtual Device Manager from the Windows menu to start the emulator." Warnings or important notes appear in a box like this. Tips and tricks appear like this. Reader feedback Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of. To send us general feedback, simply send an e-mail to feedback@packtpub.com, and mention the book title via the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors. Customer support Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase. Downloading the example code You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you
Preface Errata Although we have taken every care to ensure the accuracy of our content,mistakes do happen.If you find a mistake in one of our books-maybe a mistake in the text or f you find any errata,please ing htt p: www.pack n link and entering the details of your rata.Once rrata are will be accepted and the errata will be uploaded on our website.or added to any list of existing errata,under the Errata section of that title.Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support Piracy T3oe成heo。o6ma8 the protection of our copyright and licenses very seriously.If you add our work rm,on t hP as provid we car pursue ea remedy. Pleas contact us at copyrightpacktpub.com with a link to the suspected ated material. Questions You can contact us at guestion cktpub.com if you are having a problem with any aspect of the book,and we will do our best to address it. 【41
Preface [ 4 ] Errata Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub. com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support. Piracy Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at copyright@packtpub.com with a link to the suspected pirated material. We appreciate your help in protecting our authors, and our ability to bring you valuable content. Questions You can contact us at questions@packtpub.com if you are having a problem with any aspect of the book, and we will do our best to address it
Enter SQLite Dr.Richa on a prope used a datab Before we begin our ould like to inform ey explori you of some n rements and will require little effort from you: You need to ensure that the environment for buildin Android a and Eclipse,our IDE choice,ADT plugins,and Android SDK tools.In case these are not in place,the ADT bundle,which consists of IDE,ADT plugins, Android SDK tools,and platform tools,can be downloaded from/ om/sak/. to dare expl natory.F yo can visit techne work/java/javase
Enter SQLite Dr. Richard Hipp, the architect and primary author of SQLite, explains how it all began in his interview with The Guardian published in June 2007: "I started on May 29 2000. It's just over seven years old," he says. He was working on a project which used a database server, but from time to time the database went offline. "Then my program would give an error message saying that the database isn't working, and I got the blame for this. So I said, this is not a demanding application for the database, why don't I just talk directly to the disk, and build an SQL database engine that way? That was how it started." Before we begin our journey exploring SQLite in the context of Android, we would like to inform you of some prerequisites. The following are very basic requirements and will require little effort from you: • You need to ensure that the environment for building Android applications is in place. When we say "environment," we refer to the combination of JDK and Eclipse, our IDE choice, ADT plugins, and Android SDK tools. In case these are not in place, the ADT bundle, which consists of IDE, ADT plugins, Android SDK tools, and platform tools, can be downloaded from http:// developer.android.com/sdk/index.html. The steps mentioned in the link are pretty self-explanatory. For JDK, you can visit Oracle's website to download the latest version and set it up at http://www.oracle.com/ technetwork/java/javase/downloads/index.html
Enter SQLite You need to have a basic knowledge of Android components and have run more than"Hello World' programs on an Android emulator.If not,a very t up an emu tor.W t yo me fa Pr ast R The d de these are as follows: ong w Emulator:http://developer.android.com/tools/devices/ index.html 。 Android basics:http://developer.android.com/training/ basics/firstapp/index.htm With these things in place,we can now start our foray into SQLite. In this chapter,we will cover the following: ·Why SQLite? The SQLite architecture A quick review of database fundamentals SOLite in Android Why SQLite? SOLite is an embedded SOL database engine.It is used by prominent names such as Adobe in Adobe Integrated Runtime(AIR);Airbus,in their flight software;Python ships with SQLite;PHP;and many more.In the mobile domain,SQLite is a very It is used as an application file format,a database for electronic gadgets,a database website and as an enterprise RDBMS 1 an teresting th se anke any ou look at the e features it so popular Zero-con n such a mann that it ires no ile t requ is no se and it is directly hedded in no administrator is required to create or maintain a DB instance,or set permissions for users.In short,this is a true DBA-less database. [6]
Enter SQLite [ 6 ] • You need to have a basic knowledge of Android components and have run more than "Hello World" programs on an Android emulator. If not, a very apt guide is present on the Android developer site to set up an emulator. We would suggest you become familiar with basic Android components: Intent, Service, Content Providers, and Broadcast Receiver. The Android developer site has good repositories of samples along with documentation. Some of these are as follows: ° Emulator: http://developer.android.com/tools/devices/ index.html ° Android basics: http://developer.android.com/training/ basics/firstapp/index.html With these things in place, we can now start our foray into SQLite. In this chapter, we will cover the following: • Why SQLite? • The SQLite architecture • A quick review of database fundamentals • SQLite in Android Why SQLite? SQLite is an embedded SQL database engine. It is used by prominent names such as Adobe in Adobe Integrated Runtime (AIR); Airbus, in their flight software; Python ships with SQLite; PHP; and many more. In the mobile domain, SQLite is a very popular choice across various platforms because of its lightweight nature. Apple uses it in the iPhone and Google in the Android operating system. It is used as an application file format, a database for electronic gadgets, a database for websites, and as an enterprise RDBMS. What makes SQLite such an interesting choice for these and many other companies? Let's take a closer look at the features of SQLite that make it so popular: • Zero-configuration: SQLite is designed in such a manner that it requires no configuration file. It requires no installation steps or initial setup; it has no server process running and no recovery steps to take even if it crashes. There is no server and it is directly embedded in our application. Furthermore, no administrator is required to create or maintain a DB instance, or set permissions for users. In short, this is a true DBA-less database