8

I want to use FTS in my iOS project. Through some answers to questions here on SO (like this) and other sources (like this), i understood that i will have to roll out my own built of sqlite3 on iOS, thus replacing the dependency to default libsqlite3.dylib.

But when i directly run the query (in a new project, with just the standard 'libsqlite3.dylib' linked and no custom sqlite build) :

"SELECT rowid FROM pages WHERE textcontent MATCH 'jim';" 

on a table 'pages' created by using query :

"CREATE VIRTUAL TABLE pages USING fts3(textcontent TEXT)", 

I dont get any errors, instead, i get the correct result (rowid of the rows in which the word 'jim' exists) as if the FTS is enabled by defalt in the built-in iOS sqlite library .

So, is this the case? Has apple now enabled FTS in the standard/built-in sqlite library? Or there is something that i am missing here?

Thanks.

PS. I am using FMDB in my project as an sqlite wrapper and here is the code that i use to test the above.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory ,      NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *dbDocumentsPath = [documentsDir stringByAppendingPathComponent:@"1.db"];

FMDatabase *db = [FMDatabase databaseWithPath:dbDocumentsPath];

if (![db open])
    NSLog(@"Could not open db.");

if([db executeUpdate:@"CREATE VIRTUAL TABLE pages USING fts3(textcontent TEXT)"])
    NSLog(@"Virtual Table Created");

if([db executeUpdate:@"INSERT INTO pages(textcontent) VALUES ('Jack')"])
    NSLog(@"First Insert Done");
if([db executeUpdate:@"INSERT INTO pages(textcontent) VALUES ('jim is jam')"])
    NSLog(@"Second Insert Done");

FMResultSet* resultSet1 = [db executeQuery:@"SELECT rowid FROM pages WHERE textcontent MATCH 'jim';"];

while([resultSet1 next])
    NSLog(@"%@",[resultSet1 objectForColumnName:@"rowid"]);
Community
  • 1
  • 1
archeopetrix
  • 151
  • 2
  • 10
  • 1
    Ok, as i said, i did not get any error when trying FTS queries on the apple-compiled libsqlite3.dylib, but when i replace it with our own compiled static sqlite library having FTS manually DISABLED (by removing macro #define SQLITE_ENABLE_FTS3 from sqlite.c), i get the follwing error "Error calling sqlite3_step (1: no such module: fts3) SQLITE_ERROR". And when i again manually enable FTS by adding the macro #define SQLITE_ENABLE_FTS3 from sqlite.c, the error disappears and i get the desired output. This is making me believe even more that apple has enabled FTS by default. Thanks. – archeopetrix Jan 09 '12 at 16:16
  • Which version of iOS are you using? – SK9 Jan 31 '12 at 09:48

2 Answers2

2

This guy confirms your findings by asserting in his second blog update that FTS3 is included in iOS 5's SQLite library. (I have also tested this and came to the same conclusion.)

fumoboy007
  • 5,056
  • 3
  • 27
  • 43
1

I have tested this on my machine and Lion OS and it worked perfectly, however build would not execute FTS on any other machine (all the queries would work except FTS). Same project built with Leopard OS would not result in usable FTS.
But dropping amalgamation source in project (and enabling FTS) results in amalgamation being built and running on any machine.

M Holod
  • 215
  • 4
  • 10