• 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 == 1) {
            char *text = sqlite3_value_text(argv[0]);
            if (text && text[0]) {
              char result[2]; 
              result[0] = text[0]; result[1] = '';
              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

  • 相关阅读:
    springBoot 与 springMVC的区别
    spring的IOC和AOP
    实现同步的三种方法
    台阶积水问题
    requsets模块和beautifulsoup模块
    爬虫
    rabbitMQ 消息队列
    Django框架
    mysql
    jQuery
  • 原文地址:https://www.cnblogs.com/zhhd/p/5898929.html
Copyright © 2020-2023  润新知