简体   繁体   English

如何编写 SQLite3 Objective-C 结果集包装器?

[英]How to write an SQLite3 Objective-C resultset wrapper?

I want to write an SQLite resultset wrapper class for iPhone to dynamically call sqlite3_column_int or sqlite3_column_text .我想为 iPhone 编写一个 SQLite 结果集包装器 class 以动态调用sqlite3_column_intsqlite3_column_text In my fetchAll method I would like without knowing data type to just return the data.在我的fetchAll方法中,我想在不知道数据类型的情况下只返回数据。

I was thinking of using performSelector .我正在考虑使用performSelector How would I design such a class to interact with SQLite?我将如何设计这样的 class 以与 SQLite 交互?

No, you can't use an Objective-C feature to call a C function in that way (performSelector that is). 不,您不能使用Objective-C功能以这种方式(即performSelector)调用C函数。 You can call C code within objective-C. 您可以在Objective-C中调用C代码。 One approach may be to keep function pointers to the C functions you want to call, then implement some logic to choose the appropriate function pointer to reference. 一种方法可能是保留指向要调用的C函数的函数指针,然后实施一些逻辑以选择适当的函数指针进行引用。

I'm not quite sure I understand, but I suppose you might be able to write a few Objective-C methods containing small amounts of pure C and call performSelector on those. 我不太确定我是否理解,但是我想您也许可以编写一些包含少量纯C的Objective-C方法并在其上调用performSelector。 Unfortunately the SQLite3 API for the iPhone kind of sucks. 不幸的是,iPhone的SQLite3 API很烂。

You could take a look at how other wrappers do it. 您可以看看其他包装器是如何做到的。 For example, here's the source of the resultset object from Flying Meat Database: http://code.google.com/p/flycode/source/browse/trunk/fmdb/src/FMResultSet.h http://code.google.com/p/flycode/source/browse/trunk/fmdb/src/FMResultSet.m 例如,以下是Flying Meat数据库中结果集对象的来源: http : //code.google.com/p/flycode/source/browse/trunk/fmdb/src/FMResultSet.h http://code.google。 COM / p / flycode /源/浏览/中继/ FMDB / SRC / FMResultSet.m

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM