[英]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. 我现在正在将FMDB用于iPhone应用程序,我发现它......好吧。 It's a great little SQLite wrapper indeed. 这确实是一个很棒的SQLite包装器。
FMDB GitHub: https://github.com/ccgus/fmdb 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: 在SQLite中,我可以使用以下语法轻松完成此操作:
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? 除了FMDB我不认为有办法使用自定义功能吗?
Correct me if I'm wrong. 如果我错了纠正我。 Any help would be greatly appreciated. 任何帮助将不胜感激。
You want FMDatabase's makeFunctionNamed:maximumArguments:withBlock: method: 你想要FMDatabase的makeFunctionNamed:maximumArguments:withBlock:方法:
https://github.com/ccgus/fmdb#making-custom-sqlite-functions-based-on-blocks https://github.com/ccgus/fmdb/blob/master/src/fmdb.m#L1033 https://github.com/ccgus/fmdb#making-custom-sqlite-functions-based-on-blocks https://github.com/ccgus/fmdb/blob/master/src/fmdb.m#L1033
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. 显然,您可以使用custom
和customFunc
(或其他)来代替distance
和distanceFunc
但是您可以理解。
FMDB is open source, you could add a wrapper method to wrap up creating a new SQLite function. FMDB是开源的,你可以添加一个包装器方法来包装创建一个新的SQLite函数。 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? 也许你可以将你的补充贡献给社区?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.