Giter Club home page Giter Club logo

sqlitelib's Introduction

SQLiteLib .xcodeproj

platform: ios | osx | watchos | tvos License MIT Build Status

An Xcode project to easily build a custom SQLite static library for use in OSX and iOS frameworks and apps.

If you need a specific version of SQLite, or specific SQLite compilation options/features, read on.

November 2, 2023: Update SQLite to 3.44.0 (changelog).

Requirements: iOS 8.0+ / OSX 10.9+, Xcode 7.3+

SQLite Included: 3.44.0

==========

Installation:

Manual Installation (ex. into a Framework):

  1. Download a copy of SQLiteLib.
  2. Embed the SQLiteLib.xcodeproj project in your own project.
  3. Add the SQLiteLib.sqlitecustom target in the Target Dependencies section of the Build Phases tab of your application target.
  4. Add libsqlitecustom.a to the Linked Frameworks and Libraries section of the General tab of your target.

That's it! (You'll probably also want to #include "sqlite3.h" somewhere. SQLiteLib copies this generated file to its project directory.)

Using in Swift:

You probably shouldn't be using the raw SQLite C API in Swift. There are a bunch of great libraries available that wrap it.

For example: (GRDB.swift).

Customization:

By default, SQLiteLib builds SQLite with options that match the built-in system version of SQLite on OSX and iOS (as of OSX 10.11.6, iOS 9.3.5), with one exception*.

Specifying Additional SQLite Compilation Options:

By default, SQLiteLib compiles SQLite with options that match the built-in OSX/iOS version of SQLite (as of OSX 10.11, iOS 9.3.5), with one exception*. You only need to follow the steps below if you wish to customize the options.

To specify additional options:

  1. Open SQLiteLib-USER.xcconfig
  2. Modify CUSTOM_SQLLIBRARY_CFLAGS to specify the additional options.

For example, to specify SQLITE_ENABLE_PREUPDATE_HOOK, you would modify it like this:

CUSTOM_SQLLIBRARY_CFLAGS = -DSQLITE_ENABLE_PREUPDATE_HOOK

That's it. There is no need to modify any other files.

NOTE: If SQLiteLib-USER.xcconfig doesn't exist, copy the SQLiteLib-USER.xcconfig.example file and rename it, or build once (which will automatically do this for you). (Reference)

Compiling a Specific Version of SQLite:

SQLiteLib currently ships with the source for a specific version of SQLite (see above).

If you'd like to compile a newer (or older) version, the process is simple:

  1. Download a snapshot of the complete (raw) source tree for SQLite for the version you'd like.
  2. Replace the contents of SQLiteLib's "sqlite" subdirectory with the contents of the SQLite raw source tree snapshot.

IMPORTANT: You must use the complete raw SQLite source. The amalgamation source will NOT work properly.

SQLiteLib internally builds the amalgamation source using the steps specified in (How To Compile SQLite).

Setting compilation options using the SQLite amalgamation is not guaranteed to work:

The versions of the SQLite amalgamation that are supplied on the download page are normally adequate for most users. However, some projects may want or need to build their own amalgamations. A common reason for building a custom amalgamation is in order to use certain compile-time options to customize the SQLite library. Recall that the SQLite amalgamation contains a lot of C-code that is generated by auxiliary programs and scripts. Many of the compile-time options effect this generated code and must be supplied to the code generators before the amalgamation is assembled.

Quick Guide to Using the Latest version of SQLite:

The snapshop of the complete (raw) source tree for the current version of SQLite is available on the (SQLite Download Page) under: Alternative Source Code Formats. You'll want the file named "sqlite-src-version.zip".

Do NOT use the file beginning with "sqlite-preprocessed" - it will not work properly.

Additional Details:

Default Compilation Options:

The built-in OSX/iOS version of SQLite were built with the following compilation options (as of OSX 10.11.6, iOS 9.3.5):

Fetched using PRAGMA compile_options;

  • MacOSX (10.11.6)

    • ENABLE_API_ARMOR
    • ENABLE_FTS3
    • ENABLE_FTS3_PARENTHESIS
    • ENABLE_LOCKING_STYLE=1
    • ENABLE_RTREE
    • ENABLE_UPDATE_DELETE_LIMIT
    • OMIT_AUTORESET
    • OMIT_BUILTIN_TEST
    • OMIT_LOAD_EXTENSION
    • SYSTEM_MALLOC
    • THREADSAFE=2
  • iPhoneOS (9.3.5)

    • ENABLE_API_ARMOR
    • ENABLE_FTS3
    • ENABLE_FTS3_PARENTHESIS
    • ENABLE_LOCKING_STYLE=1
    • ENABLE_RTREE
    • ENABLE_UPDATE_DELETE_LIMIT
    • MAX_MMAP_SIZE=0
    • OMIT_AUTORESET
    • OMIT_BUILTIN_TEST
    • OMIT_LOAD_EXTENSION
    • SYSTEM_MALLOC
    • THREADSAFE=2

SQLiteLib uses these settings with one exception - on iOS:

The SQLite code uses a deprecated function (gethostuuid()).

D. Richard Hipp (SQLite architect), suggests working around this on iOS using -DSQLITE_ENABLE_LOCKING_STYLE=0:

"The SQLITE_ENABLE_LOCKING_STYLE thing is an apple-only extension that boosts performance when SQLite is used on a network filesystem. This is important on MacOS because some users think it is a good idea to put their home directory on a network filesystem.

I'm guessing this is not really a factor on iOS."

Thus, SQLiteLib uses SQLITE_ENABLE_LOCKING_STYLE=1 on OSX, but on iOS, SQLiteLib compiles with ENABLE_LOCKING_STYLE=0.

This removes the code that uses the deprecated function, but doesn't get rid of the warning that "gethostuuid() is disabled".

To prevent this warning, SQLiteLib separately specifies -Wno-#warnings when building for iOS.

All of these base settings are configured in the SQLiteLib.xcconfig file. It is strongly recommended that you do not edit this file. If you'd like to specify additional compilation options, see the instructions above.

Build Locations:

SQLiteLib generates intermediate files in ${DERIVED_SOURCES_DIR}.

The generated SQLite amalgamation files are copied to:

-${BUILT_PRODUCTS_DIR}/sqlite3.c

-${PROJECT_DIR}/sqlite3.h

Using the SQLite Encryption Extension

You can include the SQLite EncryptionExtension if you have a license to do so.

To include it in the generated amalgamation, locate the SEE files on your system. In your SQLiteLib-USER.xcconfig file, add the following entries:

SQLITE_SEE_CODE = /path/to/your/see-code/see.c

These will then be merged into the generated amalgamation

Notes:

"sqlite3.c" shows as red/missing in Xcode:

Xcode (verified in Version 7.3.1 (7D1014)) will always show "sqlite3.c" as red/missing, even after a build.

This is a UI issue in Xcode - the path is properly set in the project.pbxproj file to be "Relative to Build Products", and the build should succeed.

Xcode displays a warning:

SQLiteLib.xcconfig line 6: Unable to find included file "SQLiteLib-USER.xcconfig"

SQLiteLib's project will automatically generate this from the base template SQLiteLib-USER.xcconfig.example on first build, or you may copy and rename it yourself.

(Future builds will not display the warning. The warning does not affect functionality.)

sqlitelib's People

Contributors

barnettben avatar darrenclark avatar groue avatar swiftlyfalling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sqlitelib's Issues

Can't compile on macOS Sierra

The amalgamation script doesn't work on macOS Sierra for both the simulator and the device.

capture d ecran 2016-09-22 a 17 48 34

Any idea how to fix this ?

return code 77 (permission denied) issue

Got the project embedded, sqlite custom in target and linked .a file. I also downloaded the latest sqlite3 zip and replaced the make and related files in the sqlite3 folder of the project. I get several errors, but the one that sticks like a sore thumb is:
Amalgamation (1 issue)
shell script invocation error
Command /bin/sh failed with exit code 77

Xcode 10 and i386

Hello @swiftlyfalling,

I'm currently unable to build SQLiteLib with Xcode 10 beta, due to the use of i386 in the ARCHS[sdk=macosx*] setting of the amalgamation target.

I find that Xcode is pretty picky, since the mere presence of the architecture creates an error, even when nobody actually builds for i386. Remove i386 from ARCHS, and Xcode becomes happy.

I don't quite know how to solve this trouble. Do you think I should create a radar, according to my above interpretation, hoping Xcode 10 eventually becomes less sensitive? Or do you think SQLiteLib will have to drop support for i386 (here or in a fork dedicated to GRDB)?

Can't build: xcodebuild -scheme sqlitelib -sdk iphoneos

I try to build sqlitelib library via command line and xcodebuild for iphoneos or iphone simulator.

xcodebuild -scheme sqlitelib -sdk iphoneos

configure: error: cannot run C compiled programs.
If you meant to cross compile, use --host'. See config.log' for more details
Command /bin/sh failed with exit code 1

** BUILD FAILED **

If I set the sdk to macosx than everything works fine.

Build-Environment:
MacOSX Sierra 10.12.4
Xcode 8.3.1

How to clear architecture warnings in Xcode 11

After adding this (fantastic!) project to mine in Xcode 11, I received 3 compile warnings like this:

  • Warning: Mapping architecture arm64 to x86_64. Ensure that this target's Architectures and Valid Architectures build settings are configured correctly for the iOS Simulator platform.
  • Warning: Mapping architecture armv7 to i386. Ensure that this target's Architectures and Valid Architectures build settings are configured correctly for the iOS Simulator platform.
  • Warning: Mapping architecture armv7s to i386. Ensure that this target's Architectures and Valid Architectures build settings are configured correctly for the iOS Simulator platform.

I was able to silence these after reading this Stack Overflow answer https://stackoverflow.com/a/52392083/19506 by changing my Valid Architectures setting in this project to $(ARCHS_STANDARD) in Build Settings.

This resulted in the following diff:

Screen Shot 2019-11-02 at 10 14 01 am

As not everyone will be using Xcode 11, I'm not suggesting this should be changed in the project file, but I thought it worth logging this issue in case others have the same problem and wish to clear the warnings.

Xcode 11 doesn't seem to resolve "Unable to find ... SQLiteLib-USER.xcconfig"

The current readme states:

https://github.com/swiftlyfalling/SQLiteLib#xcode-displays-a-warning

Xcode displays a warning:

SQLiteLib.xcconfig line 6: Unable to find included file "SQLiteLib-USER.xcconfig"

and that:

Future builds will not display the warning.

Perhaps it was some weird config I had, or an Xcode 11 feature, but this didn't resolve for me. The build just failed every time. However, I was able to fix it locally and for CI by doing the following:

  • copy SQLiteLib-USER.xcconfig.example to SQLiteLib-USER.xcconfig as suggested
  • remove the entry for SQLiteLib-USER.xcconfig at the bottom of the provided .gitignore file (necessary for CI to see the file)

Then everything worked as expected, thanks!

Getting SQLITE_CANTOPEN

I kept getting sporadic I/O errors like shown here. So, I followed the advice of the top voted answer and integrated this library. Now I'm always getting SQLITE_CANTOPEN.

Note: I did the integration in my app, but I'm using SQLite through kean/SwiftSQL. Is this a correct way to integrate while using a library?

Thanks for any help.

Missing libsqlitecustom.a

Where do we find the libsqlitecustom.a? Or should we expect to appear after first build? With me, it doesn't.

Suggestion: Create Swift Package Manager SPM version

It would be nice to get SQLite as an SPM package instead of an Xcode framework. I'm not sure if that's possible with the SPM improvements as of Xcode 11, but it would be nice if possible...

PS: Many thanks again for this great resource!

Errory trying to use sqlite with ICU enabled

I think that I followed all the right steps, but surely I did something wrong because I get these list of errors when I use the compiled library with ICU enabled (CUSTOM_SQLLIBRARY_CFLAGS = -DSQLITE_ENABLE_ICU)

Undefined symbols for architecture arm64: "_u_errorName_73", referenced from: _icuFunctionError in libsqlitecustom.a(sqlite3.o) "_u_foldCase_73", referenced from: _icuOpen in libsqlitecustom.a(sqlite3.o) _icuLikeCompare in libsqlitecustom.a(sqlite3.o) "_u_isspace_73", referenced from: _icuNext in libsqlitecustom.a(sqlite3.o) "_u_strToLower_73", referenced from: _icuCaseFunc16 in libsqlitecustom.a(sqlite3.o) "_u_strToUTF8_73", referenced from: _icuNext in libsqlitecustom.a(sqlite3.o) "_u_strToUpper_73", referenced from: _icuCaseFunc16 in libsqlitecustom.a(sqlite3.o) "_ubrk_close_73", referenced from: _icuClose in libsqlitecustom.a(sqlite3.o) "_ubrk_current_73", referenced from: _icuNext in libsqlitecustom.a(sqlite3.o) "_ubrk_first_73", referenced from: _icuOpen in libsqlitecustom.a(sqlite3.o) "_ubrk_next_73", referenced from: _icuNext in libsqlitecustom.a(sqlite3.o) "_ubrk_open_73", referenced from: _icuOpen in libsqlitecustom.a(sqlite3.o) "_ucol_close_73", referenced from: _icuLoadCollation in libsqlitecustom.a(sqlite3.o) _icuCollationDel in libsqlitecustom.a(sqlite3.o) "_ucol_open_73", referenced from: _icuLoadCollation in libsqlitecustom.a(sqlite3.o) "_ucol_strcoll_73", referenced from: _icuCollationColl in libsqlitecustom.a(sqlite3.o) "_uregex_close_73", referenced from: _icuRegexpDelete in libsqlitecustom.a(sqlite3.o) "_uregex_matches_73", referenced from: _icuRegexpFunc in libsqlitecustom.a(sqlite3.o) "_uregex_open_73", referenced from: _icuRegexpFunc in libsqlitecustom.a(sqlite3.o) "_uregex_setText_73", referenced from: _icuRegexpFunc in libsqlitecustom.a(sqlite3.o)

Someone has any idea what I'm doing wrong?

Sqlite error 14 with a custom sqlite

Hello,

Thanks for this project!

I am trying to use sqlite with FTS5 module.

Here is my configuration:

CUSTOM_SQLLIBRARY_CFLAGS = -DSQLITE_ENABLE_FTS5

When I try this:

sqlite3_open_v2

I get an error 14 (CONNOT_OPEN) with a new database

I have followed the step you recommend without success, do you have any idea of what I've missed?

Thanks in advance for your answer!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.