Monday 15 September 2014

database - How to enable soundex() in iOS SQLite for a searching query? -


Is there any way to use SQLite soundx () in iOS app?

Please guide me to find a way ...

Tried the house but it works on the terminal and I need to run the sound all the time in the terminal. Apart from this, I do not know how the port for iOS APP.

Terminal work

Enter image details here

you sqlite3_create_function Code> Dhvnieks SQL functions:

  #import "see ControllerH #import & lt; Sqlite3.h & gt; Zero soundx (sqlite3_context * context, int argc, sqlite3_value ** argv); @ Implementation View Controller - (zero) viewDidoadload [[Super Viewedload]; [self test]; } - (sqlite3 *) openDatabase {NSString * docsPath = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, Yes) [0]; NSString * path = [docspath stringbapensepantcontent: @ "test.db"] ;; NSFileManager * fileManager = [NSFileManager defaultManager]; If: {NSString * bundlePath = [[NSBundle mainBundle] pathForResource: @ "test" ofType: @ "db"] ([filemanager fileExistsAtPath path]); [File manager copywrite pith: bundlepath topath: path error: zero]; } Sqlite3 * db; Int rc; If ((RC = sqlite3_open_v2 ([path UTF8String], & amp; db, SQLITE_OPEN_READWRITE, zero)) = SQLITE_OK!) {NSLog (@ "% s: failed sqlite3_open_v2:% d", __FUNCTION__, RC) ; } Return DB; } - Create (BOOL) function: (sqlite3 *) db {int rc; If ((RC = sqlite3_create_function (db, "soundex", 1, SQLITE_ANY, zero, Soundex, zero, zero)) = SQLITE_OK!) {NSLog (@ "% s: sqlite3_create_function Error:% s", __FUNCTION__, sqlite3_errmsg ( Db)); } Return RC; } - (zero) test {int rc; Sqlite3 * db = [self-open database]; [Self-generated Process: DB]; Sqlite3_stmt * statement; If (sqlite3_prepare_v2 (db, "select the name of the function where soundex (name) = soundex ( 'GEM')", -1, & amp; statements, zero) = SQLITE_OK!) {NSLog (@ "% s: sqlite3_prepare_v2 error :% S ", __FUNCTION__, sqlite3_errmsg (db)); } While ((rc = sqlite3_step (statement)) == SQLITE_ROW {const unsigned char * name = sqlite3_column_text (statement, 0); If (name) NSLog (@ "name =% s", name); Other NSLog (@ "name = NULL"); } If (RC! = SQLITE_DONE) {NSLog (@ "% s: sqlite3_step error:% s", __FUNCTION__, sqlite3_errmsg (db)); } Sqlite3_finalize (statement); Sqlite3_close (database); } @end zero soundex (sqlite3_context * context, int argc, sqlite3_value ** argv) {const char * str = (const char *) sqlite3_value_text (argv [0]); Const char * in = str; Fixed int code [] = {0,1,2,3,0,1,2,0,0,2,2,4,4,5,5,0,1,2,6,2,3,0 , 1, 0, 2, 2, 2}; / A, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y , Z * / Four f; End end; integer number; Four keys [5]; / * Set the default key, complete with '0s * / strcpy (key, "Z000"); / * Advance to first letter If no one exists, return the default key * while (*!! = '\ 0' & amp;; isalpha (* in)) ++; If (* == '\ 0' in) {sqlite3_result_text (context, key, 4, SQLITE_TRANSIENT); Return; } / * Delete the first letter, uppercase, and set the main loop * / key for [0] = toper (* in); Last = Code [Key [0] - 'A']; ++; / * Scan the rest of the string, close it at the end of the string or when the key is completed / / (calculation = 1; count = 4; Non-alpha, completely ignore the character * / if (isalpha (* in)) {ch = tolower (* in); / * Fold the letters along with the same code * / if (last! = Code [f - 'a']) {end = code [f - 'a']; / * Ignore the code == 0 except for the separator * / if (last! = 0) key [count ++] = '0' + last; }}} Sqlite3_result_text (context, key, 4, SQLITE_TRANSIENT); }    

No comments:

Post a Comment