wcdb icon indicating copy to clipboard operation
wcdb copied to clipboard

WCDB.swift doesn't work with Firebase

Open wuyuehyang opened this issue 6 years ago • 15 comments

The language of WCDB

Swift

The version of WCDB

v1.0.7.3 (newest)

The platform of WCDB

iOS

The installation of WCDB

Cocoapods

Environment

Xcode 10, iPhone Simulator / iPhone 5s with iOS 10.3.3

What's the issue?

screen shot 2018-09-18 at 15 56 56

Firebase and WCDB were installed through Cocoapods. Once database object is created, any pragma statement executed by Handle.exec(_ statement: Statement) returns error code 21. I set a symbolic breakpoint as the attachment above, which reveals that the sqlite3_exec is not linked to WCDBOptimizedSQLCipher but libsqlite3.dylib. If Firebase were removed, everything works fine.

Any idea to fix this?

Demo project: WCDBFirebase.zip

wuyuehyang avatar Sep 18 '18 08:09 wuyuehyang

Make WCDBSwift as a separate dynamic framework, but not within Cocoapods.

RingoD avatar Sep 18 '18 08:09 RingoD

Sure a pre-compiled framework will solve the linking problem. I've also tried renaming the sqlite3_exec to sqlite3_exec_wcdb in legacy.c of WCDBOptimizedSQLCipher, which works that around too, but both of them appear to be invasive. I was wondering if sqlite3_exec in WCDBOptimizedSQLCipher will be renamed in future release, or integrate the project of sqlcipher into WCDB, just like it was before.

wuyuehyang avatar Sep 18 '18 09:09 wuyuehyang

Of course NOT. Why should WCDB rename the function name of SQLCipher? This is unreasonable.

RingoD avatar Sep 19 '18 02:09 RingoD

Well resolving a symbolic conflict like this is beyond my current level, renaming is the only idea I came up with. At last we turn back to WCDB version 1.0.6.x, since there's no source code changes in releases after. A pre-compiled framework is also unacceptable, swift runtime libs will take more than 20MB of space which is a totally waste.

For any reference: https://github.com/wuyuehyang/wcdb

wuyuehyang avatar Sep 19 '18 07:09 wuyuehyang

The reason why it failed should be some of the frameworks inside Firebase linking the builtin SQLite. Since WCDBSwift never import or link SQLite explicitly, linker should link the WCDBOptimizedSQLCipher. BUT it not. I don't if it's a bug of linker or not. Maybe I will fix it or try to avoid it sooner or later.

RingoD avatar Sep 19 '18 14:09 RingoD

Note that Swift runtime libs may not be necessary.

RingoD avatar Sep 19 '18 14:09 RingoD

Thanks, It’s glad to hear that you will be working on it. I don’t think it’s a good idea to get rid of those libs. I will have to recompile WCDB every time swift upgrade its ABI, and there will be no compiler errors reminding me if I don’t.

wuyuehyang avatar Sep 19 '18 16:09 wuyuehyang

Upgrade to v1.0.7.5 and try again.

RingoD avatar Sep 21 '18 08:09 RingoD

Thank you for your great work, I tested it in the demo project and now it works like a charm. Anyway it could be perfect if these two warnings could be eliminated 😝 screen shot 2018-09-25 at 11 44 35

wuyuehyang avatar Sep 25 '18 03:09 wuyuehyang

It did not happen on my machine. I'll check it later.

RingoD avatar Sep 25 '18 05:09 RingoD

Much appreciated. It could be reproduced in the demo project of my first post. Tested on macOS 10.14, Xcode 10

wuyuehyang avatar Sep 25 '18 06:09 wuyuehyang

It's fixed. Run pod update for your project to get the latest version. Note that WCDBSwift should be v1.0.7.5 and both SQLiteRepairKit and WCDBOptimizedSQLCipher should be v1.2.1.

RingoD avatar Sep 25 '18 07:09 RingoD

Thanks, it works perfect for me.

wuyuehyang avatar Sep 26 '18 04:09 wuyuehyang

WCDB also have this problem if you enbale generate_multiple_pod_projects in Podfie. could you solve this problem? @RingoD

weiguangmeng avatar Jan 12 '23 09:01 weiguangmeng

I still encounter this problem. Is there any new solution now? @RingoD version: WCDB.swift (2.0.4) WCDBOptimizedSQLCipher (1.4.2)

CJaeson avatar Sep 11 '23 10:09 CJaeson