Android SQLite 加入自定义函数

SQLite Database 自定义函数实现:

//Here's how to create a function that finds the first character of a string.

static void firstchar(sqlite3_context *context, int argc, sqlite3_value **argv) {
if (argc == ) {
char *text = sqlite3_value_text(argv[]);
if (text && text[]) {
char result[];
result[] = text[]; result[] = '\0';
sqlite3_result_text(context, result, -, SQLITE_TRANSIENT);
return;
}
}
sqlite3_result_null(context);
} //Then attach the function to the database. sqlite3_create_function(db, "firstchar", , SQLITE_UTF8, NULL, &firstchar, NULL, NULL); //Finally, use the function in a sql statement. //SELECT firstchar(textfield) from table

备注:aHR0cCUzQS8vd3d3LmNuYmxvZ3MuY29tL3poaGQv

参考代码:AOSP/external/sqlite/android/sqlite3_android.cpp

参考链接:http://*.com/questions/7867099/how-can-i-create-a-user-defined-function-in-sqlite

参考链接:http://www.cnblogs.com/imouto/archive/2013/06/14/how-to-add-user-defined-functions-for-sqlite.html

上一篇:java反射(转)


下一篇:『无为则无心』Python序列 — 17、Python字符串操作常用API