Tencent / wcdb

WCDB is a cross-platform database framework developed by WeChat.
Other
10.73k stars 1.4k forks source link

关于 API call with invalid database connection pointer 错误 #716

Closed ElfSundae closed 1 year ago

ElfSundae commented 4 years ago

The language of WCDB

Objective-C

The version of WCDB

1.0.7.5

The platform of WCDB

iOS

The installation of WCDB

Cocoapods

What's the issue?

刚碰到了 "API call with invalid database connection pointer" 这个错误,数据库没创建成功,数据库文件是 0 字节。报错如下:

2020-05-25 11:20:51.267524+0800 PodProject[9381:2416284] RIMDatabaseManager.mm:131 -[RIMDatabaseManager setLoggerTypes:]_block_invoke_2 🚦[Database] SQL: PRAGMA locking_mode
2020-05-25 11:20:51.267614+0800 PodProject[9381:2416284] [logging] API call with invalid database connection pointer
2020-05-25 11:20:51.267645+0800 PodProject[9381:2416284] [logging] misuse at line 125820 of [378230ae7f]
2020-05-25 11:20:51.267805+0800 PodProject[9381:2416284] RIMDatabaseManager.mm:123 -[RIMDatabaseManager setLoggerTypes:]_block_invoke 🚦[Database] ❌ Error: Code:21, Type:SQLite, Msg:not an error, Tag:0, ExtCode:0, SQL:PRAGMA synchronous='NORMAL', Path:/var/mobile/Containers/Data/Application/CC57D5E2-07B9-4E28-93CB-9B2385517762/Library/RIM/15377fcb99d18f2fc05d0221a94142b8/IM.db, Op:4
2020-05-25 11:20:51.268478+0800 PodProject[9381:2416284] RIMDatabaseManager.mm:131 -[RIMDatabaseManager setLoggerTypes:]_block_invoke_2 🚦[Database] SQL: PRAGMA locking_mode
2020-05-25 11:20:51.268531+0800 PodProject[9381:2416284] [logging] API call with invalid database connection pointer
2020-05-25 11:20:51.269041+0800 PodProject[9381:2416284] [logging] misuse at line 125820 of [378230ae7f]
2020-05-25 11:20:51.269201+0800 PodProject[9381:2416284] RIMDatabaseManager.mm:123 -[RIMDatabaseManager setLoggerTypes:]_block_invoke 🚦[Database] ❌ Error: Code:21, Type:SQLite, Msg:not an error, Tag:0, ExtCode:0, SQL:PRAGMA synchronous='NORMAL', Path:/var/mobile/Containers/Data/Application/CC57D5E2-07B9-4E28-93CB-9B2385517762/Library/RIM/15377fcb99d18f2fc05d0221a94142b8/IM.db, Op:4
2020-05-25 11:20:51.272433+0800 PodProject[9381:2416498] RIMDatabaseManager.mm:131 -[RIMDatabaseManager setLoggerTypes:]_block_invoke_2 🚦[Database] SQL: PRAGMA locking_mode
2020-05-25 11:20:51.272506+0800 PodProject[9381:2416498] [logging] API call with invalid database connection pointer
2020-05-25 11:20:51.278517+0800 PodProject[9381:2416498] [logging] misuse at line 125820 of [378230ae7f]
2020-05-25 11:20:51.278655+0800 PodProject[9381:2416498] RIMDatabaseManager.mm:123 -[RIMDatabaseManager setLoggerTypes:]_block_invoke 🚦[Database] ❌ Error: Code:21, Type:SQLite, Msg:not an error, Tag:0, ExtCode:0, SQL:PRAGMA synchronous='NORMAL', Path:/var/mobile/Containers/Data/Application/CC57D5E2-07B9-4E28-93CB-9B2385517762/Library/RIM/15377fcb99d18f2fc05d0221a94142b8/IM.db, Op:4
2020-05-25 11:20:51.289634+0800 PodProject[9381:2416498] RIMDatabaseManager.mm:131 -[RIMDatabaseManager setLoggerTypes:]_block_invoke_2 🚦[Database] SQL: PRAGMA locking_mode
2020-05-25 11:20:51.316685+0800 PodProject[9381:2416498] [logging] API call with invalid database connection pointer
2020-05-25 11:20:51.316762+0800 PodProject[9381:2416498] [logging] misuse at line 125820 of [378230ae7f]
2020-05-25 11:20:51.316946+0800 PodProject[9381:2416498] RIMDatabaseManager.mm:123 -[RIMDatabaseManager setLoggerTypes:]_block_invoke 🚦[Database] ❌ Error: Code:21, Type:SQLite, Msg:not an error, Tag:0, ExtCode:0, SQL:PRAGMA synchronous='NORMAL', Path:/var/mobile/Containers/Data/Application/CC57D5E2-07B9-4E28-93CB-9B2385517762/Library/RIM/15377fcb99d18f2fc05d0221a94142b8/IM.db, Op:4

搜索了下 issues, https://github.com/Tencent/wcdb/issues/317 提到加 -all_load flag,试了下可行。 但是我之前的项目没有加过 -all_load 也没出现过这个问题,再检查了下项目设置,发现 Podfile 中设置了 use_frameworks! :linkage => :static ,移除 :linkage => :static 参数后也解决了问题(没添加 -all_load)。 use_frameworks! 参数是 CocoaPods 1.9 加的新特性,我不确定这个问题是 CocoaPods 的问题还是 WCDB 的 podspec 需要额外设置什么。

zebraciam commented 3 years ago

有解决么

ElfSundae commented 3 years ago

上面不是写了么,项目编译参数里加 -all_load 或者 移除 Podfile 中的 :linkage => :static

xiayuanquan commented 2 years ago

这样可以解决,我这边成功了:

-framework "WCDBSwift" -framework "sqliterk" -force_load $(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher

xiayuanquan commented 2 years ago

个人觉得 -all_load太暴力,链接所有的文件,不同的三方库很容易造成符号冲突。duplicate symbol xxx...

ToForgive commented 2 years ago

这样可以解决,我这边成功了:

-framework "WCDBSwift" -framework "sqliterk" -force_load $(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher

实测有效

CJaeson commented 1 year ago

这样可以解决,我这边成功了:

-framework "WCDBSwift" -force_load $(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher

this helped me.

Habit21D commented 9 months ago

直接运行可以,但是打包的时候报错了 Showing All Errors Only Build input file cannot be found: '***(路径)/BuildProductsPath/DailyBuild-iphoneos/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?

CorbinLeeBest commented 6 months ago

同问,XCode没升级之前都正常,升级到15.2之后运行可以,打包会报错。 Build input file cannot be found: '***(路径)/BuildProductsPath/DailyBuild-iphoneos/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher'.

CorbinLeeBest commented 6 months ago

@Habit21D 你好,你的问题解决了吗,怎么能正常打包

Habit21D commented 6 months ago

@Habit21D 你好,你的问题解决了吗,怎么能正常打包

去Build Phases里,找到Run Scipt,往OutPut Files里增加$(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher。就可以打包了。 但是编译的时候会报sqlcipher重复了,所以编译的时候去掉这项,打包的时候加上这项

Annabelle1024 commented 4 months ago

@Habit21D 你好,你的问题解决了吗,怎么能正常打包

去Build Phases里,找到Run Scipt,往OutPut Files里增加$(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher。就可以打包了。 但是编译的时候会报sqlcipher重复了,所以编译的时候去掉这项,打包的时候加上这项

您好, 我这么写了以后, 打包的时候还是报错: error: Cycle inside SHINiPhone; building could produce unreliable results.你有遇到过吗, 解决了吗

Annabelle1024 commented 4 months ago

@Habit21D 你好,你的问题解决了吗,怎么能正常打包

去Build Phases里,找到Run Scipt,往OutPut Files里增加$(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher。就可以打包了。 但是编译的时候会报sqlcipher重复了,所以编译的时候去掉这项,打包的时候加上这项

您好, 我这么写了以后, 打包的时候还是报错: error: Cycle inside SHINiPhone; building could produce unreliable results.�你有遇到过吗, 解决了吗

已经成功解决, 在outputFiles添加了$(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher后, 需要在Build Setting中的Other Linker Flags去除 -force_load $(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher

Annabelle1024 commented 4 months ago

@Habit21D 你好,你的问题解决了吗,怎么能正常打包

去Build Phases里,找到Run Scipt,往OutPut Files里增加$(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher。就可以打包了。 但是编译的时候会报sqlcipher重复了,所以编译的时候去掉这项,打包的时候加上这项

你好, 我用这个方式打包可以成功, 但是打包成功后运行项目时发现数据库存储和查询会不成功, 你有遇到过这个问题吗

Habit21D commented 3 months ago

@Habit21D 你好,你的问题解决了吗,怎么能正常打包

去Build Phases里,找到Run Scipt,往OutPut Files里增加$(BUILT_PRODUCTS_DIR)/WCDBOptimizedSQLCipher/sqlcipher.framework/sqlcipher。就可以打包了。 但是编译的时候会报sqlcipher重复了,所以编译的时候去掉这项,打包的时候加上这项

你好, 我用这个方式打包可以成功, 但是打包成功后运行项目时发现数据库存储和查询会不成功, 你有遇到过这个问题吗

没有遇到,我这可以正常使用