Android SQLite 加入自訂函數

來源:互聯網
上載者:User

標籤:

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 加入自訂函數

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.