標籤:
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 == 1) { char *text = sqlite3_value_text(argv[0]); if (text && text[0]) { char result[2]; result[0] = text[0]; result[1] = ‘\0‘; sqlite3_result_text(context, result, -1, SQLITE_TRANSIENT); return; } } sqlite3_result_null(context);}//Then attach the function to the database.sqlite3_create_function(db, "firstchar", 1, 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://stackoverflow.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
Android SQLite 加入自訂函數