Book Image

Learning SQLite for iOS

By : Gene Da Rocha
Book Image

Learning SQLite for iOS

By: Gene Da Rocha

Overview of this book

The ability to use SQLite with iOS provides a great opportunity to build amazing apps. Apple's iOS SDK provides native support for SQLite databases. This combination offers the potential to create powerful, data-persistent applications. This book starts with the architecture of SQLite database and introduces you to concepts in SQL . You will find yourself equipped to design your own database system, administer it, and maintain it. Further, you will learn how to operate your SQLite databases smoothly using SQL commands. You will be able to extend the functionality of SQLite by using its vast arsenal of C API calls to build some interesting, exciting, new, and intelligent data-driven applications. Understand how Xcode, HTML5, and Phonegap can be used to build a cross-platform modern app which can benefit from all these technologies - all through creating a complete, customizable application skeleton that you can build on for your own apps.
Table of Contents (15 chapters)
Learning SQLite for iOS
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

The advantages of using SQLite


A few advantages of using SQLite are listed here:

  • SQLite does have a data constraints feature and can edit or drop tables without loading them into memory.

  • SQLite works on the data stored on the disk and is slower compared to Core Data.

  • Core Data, on the other hand, does not have data constraints, and can be implemented using the app's business logic instead.

  • In order to update or drop a table, the entire table has to be loaded up.

  • Core Data is quick to create records/rows but slower to save the data.

  • Core Data does have another advantage where it operates and works in the memory, and the data has to be loaded from the disk to memory.

  • Core Data works with objects based in the memory, or can be accessed using the standard slower disk method.

  • Core Data will work on non-transactional, single user, or single-threaded methods. SQLite's function is to fetch and store data using its file database system. It operates by storing the data on the disk where the data is incrementally or minimally loaded.

  • Effectively, the data can be transactional, multiuse, and thread-safe. It saves data to the disk and is mostly resilient to crashes. It is slower if you have to create hundreds of thousands of rows, but it does have data constraints, such as unique keys.

  • SQLite has bindings to many languages such as Basic, C, C#, C++, Java, JavaScript, Lua, PHP, Objective-C, Python, Ruby, and TCL. Its popularity with the open source community and usage by customers and developers has enabled its growth to continue.

  • This lightweight RDMS can be used on Google Chrome, Firefox, Safari, Opera, and Android browsers and has middleware support using ADO.NET, ODBC, COM (ActiveX), and XULRunner. It also has a support for web application frameworks, such as Django (Python based), Ruby on Rails, and Bugzilla (Mozilla). There are other applications, such as Adobe Photoshop Light and Skype that use SQLite. It is also a part of Windows 8, Symbian OS, Android, and OpenBSD operating systems.

  • Apart from not having the large overheads of other database engines, SQLite has a major enhancement, known as the EXPLAIN keyword, with its manifest typing.

  • For controlling constraint conflicts, the REPLACE and ON CONFLICT statements are used.

  • Within the same query, multiple independent databases can be accessed using the DETACH and ATTACH statements.

  • New SQL functions and collating sequences can be created using the predefined APIs, which offer much more flexibility.

  • As there is no configuration required, SQLite just does the job and works.

  • No lists, such as the REPLACE and ON CONFLICT procedures, are required.

  • There is no need to initialize, stop, restart, or start server processes, and no administrator is required to create the database with proper access controls or security permits.

  • After any failure, no user actions are required to recover the database, since it is self-repairing.

  • SQLite is more advanced than previously thought. Unlike other RDMS, it does not require a server setup via a server to serve up data or incur network traffic costs. There is no TCP/IP calls, nor frequent communication backward or forward.

  • SQLite is direct; the operating system process deals with database access to its file and controls database writes and reads with no middle-man process handshaking.

  • By having no server backend, the process of installation, configuration, or administration is reduced significantly, and access to the database is granted to programs that require this type of data operation. This is an advantage in one way, but it is also a disadvantage for security and protection from data-driven misuse, data concurrency, or data row locking mechanisms.

  • It also allows the database to be accessed several times by different applications at the same time.

  • It supports a form of portability for the cross platform database file that can be located with the database file structure. The database file can be updated on one system and copied to another on either 32 bit or 64 bit with different architectures; this does not make a difference to SQLite.

  • The usage of different architectures and the promises of developers to keep the file system stable and compatible with previous, current, and future developments will allow this database to grow and thrive. SQLite databases do not need to upload old data to new, formatted, and upgraded databases; it just works.

  • By having a single disk file for the database, the information can be copied on a USB and shared or just reused on another device very quickly by keeping all the information intact.

  • Another feature of this portable database, SQLite, is its size, which can start on a single 512-byte page and expand to 2,147,483,646 pages at 65,536 bytes per page, or in bytes 140,737,488,224,256, which equates to about 140 terabytes. Most other RDBMS are much larger, but IBM's Cloudscape is small, with a 2 MB jar file, but still larger than SQLite.

  • The Firebird alternative's client (frontend) library is about 350 KB, whereas the Berkeley Oracle database is around 450 KB, without the SQL support, and with one simple key/value pair's option.

  • This advanced portable database system and its source code is in the public domain. However, there are open source license issues and controls for some test code and documentation.

  • This is great news for developers who might want to code up new extensions or database functionality that works with their programs, which could be made into a "product extension" for SQLite.

  • You cannot have this sort of access to SQL source code around since everything has a patent, limited access, or just no access.

  • There are signed affidavits by developers to disown any copyright interest in the SQLite code. SQLite is different because it is just not governed or ruled by copyright law, which monitors the way a software should really work or be used.

Using the small allocation with variable length records, applications run faster, database access is quicker, manifest typing is used, and the database is small and nimble.

The ease of using this RDBMS makes it easier for most programmers at an intermediate level to create applications using this technology, with its detailed documentation and examples.

Other RDBMS are internally complex, with links to data structures and objects. SQLite comprises a virtual machine language that uses the EXPLAIN reserved word in front of a query.

The virtual machine has increased and benefitted this database engine by providing an excellent process or controlled environment between the backend (where the results are computed and outputted), and frontend (where the SQL is parsed and executed).

The SQL implementation language is comparable to other RDBMS, especially with its lightweight base, and it supports recursive triggers and requires the FOR/EACH ROW behavior. The FOR EACH statement is not currently supported, but functionality cannot be ruled out in the future.

As described so far in this chapter, SQLite is a nimble and easy-to-use database that developers can engage with quickly, use existing skills, and output systems to mobile devices and tablets far easier than ever before. With the help of HTML5 and other JavaScript frameworks, the advancement of SQL and number of SQLite installations will take a quantum leap.