> I have created my own function  which uses a global variable for the default
> locale. (see attached)

I guess I received your attachment because you sent this email to me
directly but generally this list doesn't allow attachments - you
should include your code into email.

And about your code: I can't check it all I've never written user
functions for SQLite. But your setLocale function is incorrect because
your copy the characters from zLocale and don't copy zero-termination
of the string.

>>   At application startup you fill this variable with value
>>   from table db_locale or with some default value if there's nothing in
>>   db_locale. Then each time you change your application's variable you
>>   save new value in table db_locale. That's it.
>
> I am struggling with this one, could someone help me out with sample code.
> I figure that the code would go to  openDatabase(..), but that is about all
> I know at the moment.

No, you won't use openDatabase and won't use any internal functions of
SQLite. You will use sqlite3_open, sqlite3_prepare_v2, sqlite3_step
and sqlite3_finalize just like with any regular access to SQLite
database.


Pavel


On Fri, Mar 2, 2012 at 5:51 PM, Grace Simon Batumbya
<grace.batum...@senecacollege.ca> wrote:
>
>   That's a wrong approach. First, you don't need to modify functions in
>   SQLite code, you need to create your own. Your function will convert
>   using locale saved in some variable in your application.
>
> I have created my own function  which uses a global variable for the default
> locale. (see attached)
>
> At application startup you fill this variable with value
>   from table db_locale or with some default value if there's nothing in
>   db_locale. Then each time you change your application's variable you
>   save new value in table db_locale. That's it.
>
> I am struggling with this one, could someone help me out with sample code.
> I figure that the code would go to  openDatabase(..), but that is about all
> I know at the moment.
>
> Thanks.
>
> Regards,
>
> Grace Batumbya
> Research Assistant | Seneca CDOT
> Phone: 416-491-5050 x3548
> cdot.senecac.on.ca
>
> On 3/1/2012 09:48, Pavel Ivanov wrote:
>
> Given that there exists a table db_locale [CREATE TABLE db_locale (locale
> text)],
> what lines of code would be used to query that table from inside this
> function?
>
> That's a wrong approach. First, you don't need to modify functions in
> SQLite code, you need to create your own. Your function will convert
> using locale saved in some variable in your application. At
> application startup you fill this variable with value from table
> db_locale or with some default value if there's nothing in db_locale.
> Then each time you change your application's variable you save new
> value in table db_locale. That's it.
>
>
> Pavel
>
>
> On Thu, Mar 1, 2012 at 9:33 AM, Grace Simon Batumbya
> <grace.batum...@senecacollege.ca> wrote:
>
> I found the function that I would need to modify (see below).
>
> static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value
> **apArg){
>   const UChar *zInput;
>   UChar *zOutput;
>   int nInput;
>   int nOutput;
>
>   UErrorCode status = U_ZERO_ERROR;
>   const char *zLocale = 0;
>
>   assert(nArg==1 || nArg==2);
>   if( nArg==2 ){
>     zLocale = (const char *)sqlite3_value_text(apArg[1]);
>   }
>
>   zInput = sqlite3_value_text16(apArg[0]);
>   if( !zInput ){
>     return;
>   }
>   nInput = sqlite3_value_bytes16(apArg[0]);
>
>   nOutput = nInput * 2 + 2;
>   zOutput = sqlite3_malloc(nOutput);
>   if( !zOutput ){
>     return;
>   }
>
>   if( sqlite3_user_data(p) ){
>     u_strToUpper(zOutput, nOutput/2, zInput, nInput/2, zLocale, &status);
>   }else{
>     u_strToLower(zOutput, nOutput/2, zInput, nInput/2, zLocale, &status);
>   }
>
>   if( !U_SUCCESS(status) ){
>     icuFunctionError(p, "u_strToLower()/u_strToUpper", status);
>     return;
>   }
>
>   sqlite3_result_text16(p, zOutput, -1, xFree);
> }
>
> Given that there exists a table db_locale [CREATE TABLE db_locale (locale
> text)],
> what lines of code would be used to query that table from inside this
> function?
>
> Grace Batumbya
> Research Assistant | Seneca CDOT
> Phone: 416-491-5050 x3548
> cdot.senecac.on.ca
>
> On 3/1/2012 08:56, Grace Batumbya wrote:
>
> Is there an example extension you know that I could look at that does this?
> (i am a novice at SQLite)
> ________________________________________
> From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on
> behalf of Pavel Ivanov [paiva...@gmail.com]
> Sent: March 1, 2012 8:52 AM
> To: General Discussion of SQLite Database
> Subject: Re: [sqlite] Set Locale for upper() and lower() using a pragma
> variable
>
> On Thu, Mar 1, 2012 at 8:50 AM, Grace Batumbya
> <grace.batum...@senecacollege.ca> wrote:
>
> You can simply register your
> own lower/upper with one argument that looks wherever you want to know
> what locale to use.
>
> The part of registering a function to override lower/upper I think I
> understand.
>
> But if I wanted to persist the locale, so that even if I disconnect and
> reconnect it is still set to the last time I set it, how do I go about
> accomplishing this.
>
> Create a special table for that and store your last locale value in
> it. Then after reconnect read the locale value from this table.
>
>
> Pavel
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to