Skip to main content
main-content
Top

About this book

Discover the essential concepts and new iOS 10 SDK and Swift 3 programming language APIs to build iPhone and iPad database driven applications using the defacto standard for data storage for mobile apps, SQLite.
You will learn about SQL operations, such as selecting, inserting, updating and deleting data using various data types like text, numerical types, images and even audio/video data. After working through this book, you will gain an expert view of developing iOS apps using SQlite as a data storage using Objective-C and Swift.

With Build iOS Database Apps with Swift and SQLite you will also gain expert knowledge on how to create databases at runtime, including creating or modifying indexes, triggers, tables, columns, and views. The examples use time-tested code from working applications.


What You'll Learn:Create database and database applications using iOS and Swift
Insert, select, edit, and delete records
Extend SQLite
Work with multi-database apps
Use SQLite with Swift
Backup online SQLite databases and more
Who This Book Is For:
Experienced Apple iOS, Swift programmers and developers.


Table of Contents

Chapter 1. Creating the Objective-C Wrapper

Abstract
Creating a wrapper for a C library is a very easy task with Swift, as the language was designed for interoperability with Objective-C and C, as well as for C++ language. Although this chapter focuses on using the SQLite C API with Swift, you could easily do the reverse and call Swift from these languages. This chapter shows how to create an Objective-C wrapper around the SQLite C API, which can then be interfaced through Swift. This method can be replicated with other C libraries.
Kevin Languedoc

Chapter 2. Creating SQLite Databases

Abstract
SQLite is very flexible in regards to creating databases. You can include a file extension, or not, as all you really need is to pass a file name and path to the sqlite3_open function and the database will be created and opened—although it won’t contain any structure. Unlike other relational databases like MSSQL, SQLite databases are self-contained and portable. A SQLite database file can run without any changes on all supported platforms, including, of course, iOS. SQLite databases are not designed to run a server.
Kevin Languedoc

Chapter 3. Creating Databases During Runtime

Abstract
One of the great features of SQLite is its ability to create databases while the app is running. You can quickly add or modify databases as needed.
Kevin Languedoc

Chapter 4. Altering Databases and Other Features

Abstract
SQLite doesn’t have an extensive API for modifying databases. Nevertheless, it does still offer functions to alter tables, and we can still alter views, triggers, and indexes as well as functions.
Kevin Languedoc

Chapter 5. Inserting Records

Abstract
The SQL Insert statement in SQLite has some interesting features, such as being able to replace an existing record, just like the Upsert statement in Oracle’s PL/SQL. The expression parameter can either be a literal or the return value from a function. We will explore these interesting features together.
Kevin Languedoc

Chapter 6. Selecting Records

Abstract
The SELECT statement is the workhorse of the SQL language no matter what platform you are using, and it is no different with SQLite.
Kevin Languedoc

Chapter 7. Updating Records

Abstract
Updating records in SQLite is very similar to using the UPDATE statement on other platforms like SQL Server or Oracle. However, SQLite offers additional operations for updating records that are similar in nature to the SQLite INSERT statement.
Kevin Languedoc

Chapter 8. Deleting Records

Abstract
In this chapter, we will discuss the DELETE function in SQLite. In contrast to the other CRUD functions in SQLite, the DELETE function API is the same as in other platforms and implements the basic SQL API, except for the LIMIT clause, which allows a developer to set a limit on the number of rows to delete.
Kevin Languedoc

Chapter 9. Searching for Records in SQLite

Abstract
This chapter doesn’t show any new SQLite APIs. Rather, it focuses on how you can use the SQLite APIs to create an iOS iPhone app for searching for records in a SQLite database.
Kevin Languedoc

Chapter 10. Working with Multiple Databases

Abstract
SQLite has a great feature for managing large volumes of data: multi-database apps. In this chapter, you'll see that by creating and attaching multiple databases to the same connection you can improve disk I/O performance and reliability.
Kevin Languedoc

Chapter 11. Backing Up SQLite Databases

Abstract
Copy contents to new database
Kevin Languedoc

Chapter 12. Analyzing SQLite Databases

Abstract
This last chapter will focus on the different tools the SQLite platform provides to help you analyze your app's databases. Except for the ANALYZE statement, which can be executed with the sqlite3_exec command, the other tools are external software programs. Specifically, in this chapter we will discuss and explore, through examples, the following technologies
Kevin Languedoc
Additional information