> Le 9 avr. 2018 à 08:42, Dr. Mucibirahman İLBUĞA <mucip.ilb...@gmail.com> a 
> écrit :
> 
> 09.04.2018 00:56 tarihinde Simon Slavin yazdı:
>> There is another solution which does not involve full ICU support.  You 
>> could instead make your own external functions for UPPER_TR() and LOWER_TR() 
>> which do just the conversions for Turkish.  Presumably they could use tables 
>> to look up which characters to convert.
> 
> Dear Simon,
> 
> I think I need to create this function UPPER_TR() in SQLite?
> 
> I searched little bit in Google.
> 
> http://etutorials.org/Server+Administration/upgrading+php+5/Chapter+4.+SQLite/4.6+User-Defined+Functions/
> 
> Should I create in PHP or is there other way to do it? May I create it in 
> SQLiteStudio for instance?...

Why not read the excellent and rather complete documentation available on 
www.sqlite.org own website, first?

Start with: https://www.sqlite.org/c3ref/intro.html
Get deeper about installing (at runtime) your own custom SQL functions: 
https://www.sqlite.org/c3ref/create_function.html
And you will find implementation example of simple functions in various files 
of SQLite source code, and indeed possibly elsewhere.

To add a SQL function to SQLite, you will have to code it in C (or eventually 
C++ with a C public interface for your functions).  Though it is not impossible 
that through some bridge programming you could do it in other languages.  If I 
understood correctly from previous posts, you're developing in C++ so this 
should not be challenging.

Is it better / simpler to write your own UPPER/LOWER specialised or to simply 
rebuild SQLite with ICU, I have too few details on your needs / goals to tell.

Here is a sample function (what it does is irrelevant and specific to my 
needs), just publishing it for giving you a head start on writing small simple 
SQL functions which you would configure at application startup through 
sqlite3_create_function_v2().

void sql_now(sqlite3_context* context, int argc, sqlite3_value** argv)
{
        int64_t offset = 0;
        if (argc == 1)
                offset = sqlite3_value_int64(argv[0]);

        time_t local = time(nullptr) - utc_bias * 60 + offset;
        int d = (int)(local / 86400) + 25568;
        int64_t pack = dbi::datetime::pack(d, (int)(local % 86400), utc_bias);

        sqlite3_result_int64(context, pack);
}

Don't be concerned or ask about dbi::datetime or utc_bias, these are completely 
specific to one of my programs.  What is interesting here for you is that this 
function, takes zero or one parameter and does something slightly different in 
both cases.  It then returns an integer.  Reading the documentation, you can 
easily extrapolate handling other parameters or return values.

In my case, sqlite3_create_function_v2 is then used to publish this function as 
SQL 'now'.
We have our own C++ framework around SQLite and use it to declare functions, 
but in the end this one would end up being added through a call like this (hope 
I did not get it wrong by synthesising it from head based on what the framework 
behind would have called):

sqlite3_create_function_v2(db, "now", -1, 0, nullptr, sql_now, nullptr, 
nullptr, nullptr);

-- 
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to