📜 ⬆️ ⬇️

Full Unicode support in SQLite for iOS. Sample application

Hello. In this article I will describe the process of creating the simplest application for iOS and introducing into it the method I use to ensure correct work with the Russian (and not only) language of such SQLite constructions as UPPER / LOWER, LIKE or ORDER BY.

The described method was used when developing in Xcode 4.2 under control of OS X Lion 10.7.2.

Below is a very detailed instruction with pictures.

To start

You need to download the necessary files:

Creating a new project

Launch XCode, create a new project with a template iOS Application - Single View Application, click "Next":
image
')
Enter the name of the project, remove the checkmarks from all checkboxes, click "Next"
image

Select the directory to save the project. Is done.
image

Adding SQLite Support to a Project

On the left in the Project Navigator, click on the topmost element of the hierarchy to view the information and properties of our project, at the bottom click the button "Add Target"
image

Choose iOS Framework & Library - Cocoa Touch Static Library, click Next
image

Enter the name for the future library. Finish.
image

We take the files that we downloaded at the beginning of the article and drag them into the newly created group (libsqliteunicode) in Project Navigator

In the window that appears, tick both targets (Add to targets). Finish.
image

Again, open the project properties, select the created libsqlunicode from the list of targets, go to the build phases tab, expand the Link Binary with Libraries list and remove Foundation.framework from it.
image

Go to the build settings tab and set the value in the Preprocessor Macros parameter
SQLITE_CORE SQLITE_ENABLE_UNICODE
image

From the list of targets, select sqliteunicode, go to the build phases tab, expand the “Target Dependencies” list and add our libsqliteunicode to it
image

Work with the library.

In order for all this to work as we need, in the header file of the controller of your database you should add the lines
#import "sqlite3.h"
#import "sqlite3_unicode.h"

Before using the database, you need to call
sqlite3_unicode_load();

After finishing work with the base, we call
sqlite3_unicode_free();

Otherwise, we use our library as usual libsqlite3.dylib

A working example demonstrating the connection of the base and search through it using the Search Bar and Search Display Controller: download (4 MB)

UPD:
Option without recompiling SQLite amalgamation:


Working example with a modified version: Download (1.5 MB)

By the way, the size of the resulting .app in the first version is 1,210,597 bytes
In the second - 266 332

Source: https://habr.com/ru/post/136135/


All Articles