blob: 6b253c185bc4c6f52883f1c358ea0b6e093d92c3 [file] [log] [blame]
The Android Open Source Project7790ef52009-03-03 19:30:40 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "sqlite3_android"
18
19#include <ctype.h>
20#include <stdlib.h>
21#include <string.h>
22#include <unistd.h>
23
24#include <unicode/ucol.h>
Dmitri Plotnikov3a749622010-03-03 11:29:46 -080025#include <unicode/uiter.h>
The Android Open Source Project7790ef52009-03-03 19:30:40 -080026#include <unicode/ustring.h>
Dmitri Plotnikov3a749622010-03-03 11:29:46 -080027#include <unicode/utypes.h>
The Android Open Source Project7790ef52009-03-03 19:30:40 -080028#include <cutils/log.h>
29
30#include "sqlite3_android.h"
31#include "PhoneNumberUtils.h"
Dmitri Plotnikov3a749622010-03-03 11:29:46 -080032#include "PhonebookIndex.h"
The Android Open Source Project455ed292009-03-13 13:04:22 -070033#include "PhoneticStringUtils.h"
The Android Open Source Project7790ef52009-03-03 19:30:40 -080034
35#define ENABLE_ANDROID_LOG 0
Dmitri Plotnikov3a749622010-03-03 11:29:46 -080036#define SMALL_BUFFER_SIZE 10
The Android Open Source Project7790ef52009-03-03 19:30:40 -080037
38static int collate16(void *p, int n1, const void *v1, int n2, const void *v2)
39{
40 UCollator *coll = (UCollator *) p;
41 UCollationResult result = ucol_strcoll(coll, (const UChar *) v1, n1,
42 (const UChar *) v2, n2);
43
44 if (result == UCOL_LESS) {
45 return -1;
46 } else if (result == UCOL_GREATER) {
47 return 1;
48 } else {
49 return 0;
50 }
51}
52
53static int collate8(void *p, int n1, const void *v1, int n2, const void *v2)
54{
55 UCollator *coll = (UCollator *) p;
56 UCharIterator i1, i2;
57 UErrorCode status = U_ZERO_ERROR;
58
59 uiter_setUTF8(&i1, (const char *) v1, n1);
60 uiter_setUTF8(&i2, (const char *) v2, n2);
61
62 UCollationResult result = ucol_strcollIter(coll, &i1, &i2, &status);
63
64 if (U_FAILURE(status)) {
65// LOGE("Collation iterator error: %d\n", status);
66 }
67
68 if (result == UCOL_LESS) {
69 return -1;
70 } else if (result == UCOL_GREATER) {
71 return 1;
72 } else {
73 return 0;
74 }
75}
76
Dmitri Plotnikov3a749622010-03-03 11:29:46 -080077/**
78 * Obtains the first UNICODE letter from the supplied string, normalizes and returns it.
79 */
80static void get_phonebook_index(
81 sqlite3_context * context, int argc, sqlite3_value ** argv)
82{
83 if (argc != 2) {
84 sqlite3_result_null(context);
85 return;
86 }
87
88 char const * src = (char const *)sqlite3_value_text(argv[0]);
89 char const * locale = (char const *)sqlite3_value_text(argv[1]);
90 if (src == NULL || src[0] == 0 || locale == NULL) {
91 sqlite3_result_null(context);
92 return;
93 }
94
95 UCharIterator iter;
96 uiter_setUTF8(&iter, src, -1);
97
98 UChar index = android::GetPhonebookIndex(&iter, locale);
99 if (index == 0) {
100 sqlite3_result_null(context);
101 return;
102 }
103
104 uint32_t outlen = 0;
105 uint8_t out[SMALL_BUFFER_SIZE];
106 UBool isError = FALSE;
107 U8_APPEND(out, outlen, SMALL_BUFFER_SIZE * sizeof(uint8_t), index, isError);
108 if (isError || outlen == 0) {
109 sqlite3_result_null(context);
110 return;
111 }
112
113 sqlite3_result_text(context, (const char*)out, outlen, SQLITE_TRANSIENT);
114}
115
The Android Open Source Project455ed292009-03-13 13:04:22 -0700116static void get_phonetically_sortable_string(
117 sqlite3_context * context, int argc, sqlite3_value ** argv)
118{
119 if (argc != 1) {
120 sqlite3_result_null(context);
121 return;
122 }
123 char const * src = (char const *)sqlite3_value_text(argv[0]);
124 char * ret;
125 size_t len;
126
127 if (!android::GetPhoneticallySortableString(src, &ret, &len)) {
Daisuke Miyakawa0c45e822009-03-27 19:41:52 -0700128 // Put this text at the end of a list.
129 sqlite3_result_text(context, "\xF0\x9F\xBF\xBD", -1, SQLITE_STATIC);
130 // sqlite3_result_null(context);
The Android Open Source Project455ed292009-03-13 13:04:22 -0700131 } else {
132 sqlite3_result_text(context, ret, len, free);
133 }
134}
135
Daisuke Miyakawad28cdc42009-05-18 14:51:52 +0900136static void get_normalized_string(
137 sqlite3_context * context, int argc, sqlite3_value ** argv)
138{
139 if (argc != 1) {
140 sqlite3_result_null(context);
141 return;
142 }
143 char const * src = (char const *)sqlite3_value_text(argv[0]);
144 char * ret;
145 size_t len;
146
147 if (!android::GetNormalizedString(src, &ret, &len)) {
148 // Probably broken string. Return 0 length string.
149 sqlite3_result_text(context, "", -1, SQLITE_STATIC);
150 } else {
151 sqlite3_result_text(context, ret, len, free);
152 }
153}
154
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800155static void phone_numbers_equal(sqlite3_context * context, int argc, sqlite3_value ** argv)
156{
Daisuke Miyakawa948a1192009-09-19 19:19:53 -0700157 if (argc != 2 && argc != 3) {
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800158 sqlite3_result_int(context, 0);
159 return;
160 }
161
162 char const * num1 = (char const *)sqlite3_value_text(argv[0]);
163 char const * num2 = (char const *)sqlite3_value_text(argv[1]);
164
Daisuke Miyakawa948a1192009-09-19 19:19:53 -0700165 bool use_strict = false;
166 if (argc == 3) {
167 use_strict = (sqlite3_value_int(argv[2]) != 0);
168 }
169
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800170 if (num1 == NULL || num2 == NULL) {
171 sqlite3_result_null(context);
172 return;
173 }
174
Daisuke Miyakawa948a1192009-09-19 19:19:53 -0700175 bool equal =
176 (use_strict ?
177 android::phone_number_compare_strict(num1, num2) :
178 android::phone_number_compare_loose(num1, num2));
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800179
180 if (equal) {
181 sqlite3_result_int(context, 1);
182 } else {
183 sqlite3_result_int(context, 0);
184 }
185}
186
187#if ENABLE_ANDROID_LOG
188static void android_log(sqlite3_context * context, int argc, sqlite3_value ** argv)
189{
190 char const * tag = "sqlite_trigger";
191 char const * msg = "";
192 int msgIndex = 0;
193
194 switch (argc) {
195 case 2:
196 tag = (char const *)sqlite3_value_text(argv[0]);
197 if (tag == NULL) {
198 tag = "sqlite_trigger";
199 }
200 msgIndex = 1;
201 case 1:
202 msg = (char const *)sqlite3_value_text(argv[msgIndex]);
203 if (msg == NULL) {
204 msg = "";
205 }
206 LOG(LOG_INFO, tag, msg);
207 sqlite3_result_int(context, 1);
208 return;
209
210 default:
211 sqlite3_result_int(context, 0);
212 return;
213 }
214}
215#endif
216
217static void delete_file(sqlite3_context * context, int argc, sqlite3_value ** argv)
218{
219 if (argc != 1) {
220 sqlite3_result_int(context, 0);
221 return;
222 }
223
224 char const * path = (char const *)sqlite3_value_text(argv[0]);
225 if (path == NULL) {
226 sqlite3_result_null(context);
227 return;
228 }
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800229
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800230 if (strncmp("/sdcard/", path, 8) != 0) {
231 sqlite3_result_null(context);
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800232 return;
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800233 }
Marco Nelissen2da78c02009-05-06 11:08:08 -0700234 if (strstr(path, "/../") != NULL) {
235 sqlite3_result_null(context);
236 return;
237 }
238
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800239 int err = unlink(path);
240 if (err != -1) {
241 // No error occured, return true
242 sqlite3_result_int(context, 1);
243 } else {
244 // An error occured, return false
245 sqlite3_result_int(context, 0);
246 }
247}
248
249static void tokenize_auxdata_delete(void * data)
250{
251 sqlite3_stmt * statement = (sqlite3_stmt *)data;
252 sqlite3_finalize(statement);
253}
254
255static void base16Encode(char* dest, const char* src, uint32_t size)
256{
257 static const char * BASE16_TABLE = "0123456789abcdef";
258 for (uint32_t i = 0; i < size; i++) {
259 char ch = *src++;
260 *dest++ = BASE16_TABLE[ (ch & 0xf0) >> 4 ];
261 *dest++ = BASE16_TABLE[ (ch & 0x0f) ];
262 }
263}
264
265struct SqliteUserData {
266 sqlite3 * handle;
267 UCollator* collator;
268};
269
270/**
271 * This function is invoked as:
272 *
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100273 * _TOKENIZE('<token_table>', <data_row_id>, <data>, <delimiter>,
274 * <use_token_index>, <data_tag>)
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800275 *
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100276 * If <use_token_index> is omitted, it is treated as 0.
277 * If <data_tag> is omitted, it is treated as NULL.
Bjorn Bringert687f1162009-05-13 22:13:09 +0100278 *
279 * It will split <data> on each instance of <delimiter> and insert each token
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100280 * into <token_table>. The following columns in <token_table> are used:
281 * token TEXT, source INTEGER, token_index INTEGER, tag (any type)
282 * The token_index column is not required if <use_token_index> is 0.
283 * The tag column is not required if <data_tag> is NULL.
Bjorn Bringert687f1162009-05-13 22:13:09 +0100284 *
285 * One row is inserted for each token in <data>.
286 * In each inserted row, 'source' is <data_row_id>.
287 * In the first inserted row, 'token' is the hex collation key of
288 * the entire <data> string, and 'token_index' is 0.
289 * In each row I (where 1 <= I < N, and N is the number of tokens in <data>)
290 * 'token' will be set to the hex collation key of the I:th token (0-based).
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100291 * If <use_token_index> != 0, 'token_index' is set to I.
292 * If <data_tag> is not NULL, 'tag' is set to <data_tag>.
Bjorn Bringert687f1162009-05-13 22:13:09 +0100293 *
294 * In other words, there will be one row for the entire string,
295 * and one row for each token except the first one.
296 *
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800297 * The function returns the number of tokens generated.
298 */
299static void tokenize(sqlite3_context * context, int argc, sqlite3_value ** argv)
300{
301 //LOGD("enter tokenize");
302 int err;
Bjorn Bringert687f1162009-05-13 22:13:09 +0100303 int useTokenIndex = 0;
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100304 int useDataTag = 0;
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800305
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100306 if (!(argc >= 4 || argc <= 6)) {
307 LOGE("Tokenize requires 4 to 6 arguments");
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800308 sqlite3_result_null(context);
309 return;
310 }
311
Bjorn Bringert687f1162009-05-13 22:13:09 +0100312 if (argc > 4) {
313 useTokenIndex = sqlite3_value_int(argv[4]);
314 }
315
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100316 if (argc > 5) {
317 useDataTag = (sqlite3_value_type(argv[5]) != SQLITE_NULL);
318 }
319
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800320 sqlite3 * handle = sqlite3_context_db_handle(context);
321 UCollator* collator = (UCollator*)sqlite3_user_data(context);
322 char const * tokenTable = (char const *)sqlite3_value_text(argv[0]);
323 if (tokenTable == NULL) {
324 LOGE("tokenTable null");
325 sqlite3_result_null(context);
326 return;
327 }
328
329 // Get or create the prepared statement for the insertions
330 sqlite3_stmt * statement = (sqlite3_stmt *)sqlite3_get_auxdata(context, 0);
331 if (!statement) {
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100332 char const * tokenIndexCol = useTokenIndex ? ", token_index" : "";
333 char const * tokenIndexParam = useTokenIndex ? ", ?" : "";
334 char const * dataTagCol = useDataTag ? ", tag" : "";
335 char const * dataTagParam = useDataTag ? ", ?" : "";
336 char * sql = sqlite3_mprintf("INSERT INTO %s (token, source%s%s) VALUES (?, ?%s%s);",
337 tokenTable, tokenIndexCol, dataTagCol, tokenIndexParam, dataTagParam);
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800338 err = sqlite3_prepare_v2(handle, sql, -1, &statement, NULL);
339 sqlite3_free(sql);
340 if (err) {
341 LOGE("prepare failed");
342 sqlite3_result_null(context);
343 return;
344 }
345 // This binds the statement to the table it was compiled against, which is argv[0].
346 // If this function is ever called with a different table the finalizer will be called
347 // and sqlite3_get_auxdata() will return null above, forcing a recompile for the new table.
348 sqlite3_set_auxdata(context, 0, statement, tokenize_auxdata_delete);
349 } else {
350 // Reset the cached statement so that binding the row ID will work properly
351 sqlite3_reset(statement);
352 }
353
354 // Bind the row ID of the source row
355 int64_t rowID = sqlite3_value_int64(argv[1]);
356 err = sqlite3_bind_int64(statement, 2, rowID);
357 if (err != SQLITE_OK) {
358 LOGE("bind failed");
359 sqlite3_result_null(context);
360 return;
361 }
362
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100363 // Bind <data_tag> to the tag column
364 if (useDataTag) {
365 int dataTagParamIndex = useTokenIndex ? 4 : 3;
366 err = sqlite3_bind_value(statement, dataTagParamIndex, argv[5]);
367 if (err != SQLITE_OK) {
368 LOGE("bind failed");
369 sqlite3_result_null(context);
370 return;
371 }
372 }
373
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800374 // Get the raw bytes for the string to tokenize
375 // the string will be modified by following code
376 // however, sqlite did not reuse the string, so it is safe to not dup it
377 UChar * origData = (UChar *)sqlite3_value_text16(argv[2]);
378 if (origData == NULL) {
379 sqlite3_result_null(context);
380 return;
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800381 }
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800382
383 // Get the raw bytes for the delimiter
384 const UChar * delim = (const UChar *)sqlite3_value_text16(argv[3]);
385 if (delim == NULL) {
386 LOGE("can't get delimiter");
387 sqlite3_result_null(context);
388 return;
389 }
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800390
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800391 UChar * token = NULL;
392 UChar *state;
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800393 int numTokens = 0;
394
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800395 do {
396 if (numTokens == 0) {
397 token = origData;
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800398 }
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800399
400 // Reset the program so we can use it to perform the insert
401 sqlite3_reset(statement);
402 UErrorCode status = U_ZERO_ERROR;
403 char keybuf[1024];
404 uint32_t result = ucol_getSortKey(collator, token, -1, (uint8_t*)keybuf, sizeof(keybuf)-1);
405 if (result > sizeof(keybuf)) {
406 // TODO allocate memory for this super big string
407 LOGE("ucol_getSortKey needs bigger buffer %d", result);
408 break;
409 }
410 uint32_t keysize = result-1;
411 uint32_t base16Size = keysize*2;
412 char *base16buf = (char*)malloc(base16Size);
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800413 base16Encode(base16buf, keybuf, keysize);
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800414 err = sqlite3_bind_text(statement, 1, base16buf, base16Size, SQLITE_STATIC);
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800415
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800416 if (err != SQLITE_OK) {
417 LOGE(" sqlite3_bind_text16 error %d", err);
418 free(base16buf);
419 break;
420 }
421
Bjorn Bringert687f1162009-05-13 22:13:09 +0100422 if (useTokenIndex) {
423 err = sqlite3_bind_int(statement, 3, numTokens);
424 if (err != SQLITE_OK) {
425 LOGE(" sqlite3_bind_int error %d", err);
426 free(base16buf);
427 break;
428 }
429 }
430
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800431 err = sqlite3_step(statement);
432 free(base16buf);
433
434 if (err != SQLITE_DONE) {
435 LOGE(" sqlite3_step error %d", err);
436 break;
437 }
438 numTokens++;
439 if (numTokens == 1) {
440 // first call
441 u_strtok_r(origData, delim, &state);
442 }
443 } while ((token = u_strtok_r(NULL, delim, &state)) != NULL);
444 sqlite3_result_int(context, numTokens);
445}
446
447static void localized_collator_dtor(UCollator* collator)
448{
449 ucol_close(collator);
450}
451
452#define LOCALIZED_COLLATOR_NAME "LOCALIZED"
453
454extern "C" int register_localized_collators(sqlite3* handle, const char* systemLocale, int utf16Storage)
455{
456 int err;
457 UErrorCode status = U_ZERO_ERROR;
458 void* icudata;
459
460 UCollator* collator = ucol_open(systemLocale, &status);
461 if (U_FAILURE(status)) {
462 return -1;
463 }
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800464
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800465 ucol_setAttribute(collator, UCOL_STRENGTH, UCOL_PRIMARY, &status);
466 if (U_FAILURE(status)) {
467 return -1;
468 }
469
470 status = U_ZERO_ERROR;
471 char buf[1024];
472 int n = ucol_getShortDefinitionString(collator, NULL, buf, 1024, &status);
473
474 if (utf16Storage) {
475 err = sqlite3_create_collation_v2(handle, LOCALIZED_COLLATOR_NAME, SQLITE_UTF16, collator,
476 collate16, (void(*)(void*))localized_collator_dtor);
477 } else {
478 err = sqlite3_create_collation_v2(handle, LOCALIZED_COLLATOR_NAME, SQLITE_UTF8, collator,
479 collate8, (void(*)(void*))localized_collator_dtor);
480 }
481 if (err != SQLITE_OK) {
482 return err;
483 }
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800484
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800485 // Register the _TOKENIZE function
486 err = sqlite3_create_function(handle, "_TOKENIZE", 4, SQLITE_UTF16, collator, tokenize, NULL, NULL);
487 if (err != SQLITE_OK) {
488 return err;
Bjorn Bringert687f1162009-05-13 22:13:09 +0100489 }
490 err = sqlite3_create_function(handle, "_TOKENIZE", 5, SQLITE_UTF16, collator, tokenize, NULL, NULL);
491 if (err != SQLITE_OK) {
492 return err;
493 }
Bjorn Bringert754d83d2009-05-18 11:21:50 +0100494 err = sqlite3_create_function(handle, "_TOKENIZE", 6, SQLITE_UTF16, collator, tokenize, NULL, NULL);
495 if (err != SQLITE_OK) {
496 return err;
497 }
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800498
499 return SQLITE_OK;
500}
501
502
503extern "C" int register_android_functions(sqlite3 * handle, int utf16Storage)
504{
505 int err;
506 UErrorCode status = U_ZERO_ERROR;
507
508 UCollator * collator = ucol_open(NULL, &status);
509 if (U_FAILURE(status)) {
510 return -1;
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800511 }
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800512
513 if (utf16Storage) {
514 // Note that text should be stored as UTF-16
515 err = sqlite3_exec(handle, "PRAGMA encoding = 'UTF-16'", 0, 0, 0);
516 if (err != SQLITE_OK) {
517 return err;
518 }
519
520 // Register the UNICODE collation
521 err = sqlite3_create_collation_v2(handle, "UNICODE", SQLITE_UTF16, collator, collate16,
522 (void(*)(void*))localized_collator_dtor);
523 } else {
524 err = sqlite3_create_collation_v2(handle, "UNICODE", SQLITE_UTF8, collator, collate8,
525 (void(*)(void*))localized_collator_dtor);
526 }
527
528 if (err != SQLITE_OK) {
529 return err;
530 }
531
532 // Register the PHONE_NUM_EQUALS function
Daisuke Miyakawa948a1192009-09-19 19:19:53 -0700533 err = sqlite3_create_function(
534 handle, "PHONE_NUMBERS_EQUAL", 2,
535 SQLITE_UTF8, NULL, phone_numbers_equal, NULL, NULL);
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800536 if (err != SQLITE_OK) {
537 return err;
538 }
Daisuke Miyakawa948a1192009-09-19 19:19:53 -0700539
540 // Register the PHONE_NUM_EQUALS function with an additional argument "use_strict"
541 err = sqlite3_create_function(
542 handle, "PHONE_NUMBERS_EQUAL", 3,
543 SQLITE_UTF8, NULL, phone_numbers_equal, NULL, NULL);
544 if (err != SQLITE_OK) {
545 return err;
546 }
547
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800548 // Register the _DELETE_FILE function
549 err = sqlite3_create_function(handle, "_DELETE_FILE", 1, SQLITE_UTF8, NULL, delete_file, NULL, NULL);
550 if (err != SQLITE_OK) {
551 return err;
552 }
553
554#if ENABLE_ANDROID_LOG
555 // Register the _LOG function
556 err = sqlite3_create_function(handle, "_LOG", 1, SQLITE_UTF8, NULL, android_log, NULL, NULL);
557 if (err != SQLITE_OK) {
558 return err;
559 }
560#endif
561
The Android Open Source Project455ed292009-03-13 13:04:22 -0700562 // Register the GET_PHONETICALLY_SORTABLE_STRING function
563 err = sqlite3_create_function(handle,
564 "GET_PHONETICALLY_SORTABLE_STRING",
565 1, SQLITE_UTF8, NULL,
566 get_phonetically_sortable_string,
567 NULL, NULL);
568 if (err != SQLITE_OK) {
569 return err;
570 }
571
Daisuke Miyakawad28cdc42009-05-18 14:51:52 +0900572 // Register the GET_NORMALIZED_STRING function
573 err = sqlite3_create_function(handle,
574 "GET_NORMALIZED_STRING",
575 1, SQLITE_UTF8, NULL,
576 get_normalized_string,
577 NULL, NULL);
578 if (err != SQLITE_OK) {
579 return err;
580 }
581
Dmitri Plotnikov3a749622010-03-03 11:29:46 -0800582 // Register the GET_PHONEBOOK_INDEX function
583 err = sqlite3_create_function(handle,
584 "GET_PHONEBOOK_INDEX",
585 2, SQLITE_UTF8, NULL,
586 get_phonebook_index,
587 NULL, NULL);
588 if (err != SQLITE_OK) {
589 return err;
590 }
591
The Android Open Source Project7790ef52009-03-03 19:30:40 -0800592 return SQLITE_OK;
593}