简体   繁体   中英

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.

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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