开发者

FMDB SQLite wrapper and user defined/custom functions

I'm using FMDB for an iPhone app at the moment and I'm finding it... okay. It's a great little SQLite wrapper indeed.

FMDB GitHub: https://github.com/ccgus/fmdb

The only problem is I'm needing to use a custom function. In SQLite I can easily do this by using the following syntax:

sqlite3_create_function(database, "custom", 4, SQLITE_UTF8,开发者_运维百科 NULL, &customFunc, NULL, NULL);

Except with FMDB I don't think there's a way to use a custom function?

Correct me if I'm wrong. Any help would be greatly appreciated.


You want FMDatabase's makeFunctionNamed:maximumArguments:withBlock: method:

https://github.com/ccgus/fmdb#making-custom-sqlite-functions-based-on-blocks https://github.com/ccgus/fmdb/blob/master/src/fmdb.m#L1033


FMDB is open source, you could add a wrapper method to wrap up creating a new SQLite function. Shouldn't be difficult. You can use the other wrapper methods as templates for how you should accomplish this.

Maybe you could contribute your additions back to the community?


I know this is an old question, but the following should work:

FMDatabase *database = [FMDatabase databaseWithPath:dbPath];

[database open];

sqlite3_create_function([database sqliteHandle], "distance", 4, SQLITE_UTF8, NULL, &distanceFunc, NULL, NULL);

FMResultSet *results = [database executeQuery:@"SELECT * from stores WHERE distance(latitude, longitude, -37.77023, 148.089688) < 1"];

Obviously, you'd use custom and customFunc (or whatever) in place of distance and distanceFunc but you get the idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜