p2 / Redland-ObjC

Objective-C wrapper for the Redland RDF libraries
Other
20 stars 11 forks source link

sqlite storage #11

Closed mro closed 10 years ago

mro commented 10 years ago

currently sqlite isn't available for storage - despite the linked sqlite library indicating such.

To achieve this, it seems to take a couple of steps:

  1. add --with-sqlite=3 to Redland-source/cross-compile-config.py,
  2. patch Redland-source/*/pp-configure.sh to hand on a previously set PKG_CONFIG_PATH,
  3. $ brew install sqlite,
  4. $ export PKG_CONFIG_PATH=/usr/local/Cellar/sqlite/*/lib/pkgconfig/,
  5. check $ grep "Triple stores enabled" Redland-source/build-*/redland-*/config.log to contain sqlite,
  6. use a RedlandStorage *storage = [[RedlandStorage alloc] initWithFactoryName:@"sqlite" identifier:@"foo.sqlite" options:@"new='yes'"];,
  7. the above filename foo.sqlite may have to be an absolute path into e.g. the Documents directory,
  8. what else?
mro commented 10 years ago

see also https://github.com/mro/Redland-ObjC/commit/ae68c8639954be5cd8f89bb9c67a3f5ce657150d

p2 commented 10 years ago

Cool! I haven't used a triple store so far and I will not use one in the near term, but I'm happy to pull in a branch that does. Maybe you can use sqlite3 that ships with OS X so we don't need an extra step to brew it?

mro commented 10 years ago

indeed, that's what I thought as well - but I'm clueless as how to tell pkg-config about it...

p2 commented 10 years ago

That is a good point, there doesn't seem to be a sqlite.pc for the native install. But since homebrew is required to build the C libraries anyway it's not really a problem.

smamessier commented 10 years ago

It was already working with sqlite3 on iOS without any hack

mro commented 10 years ago

interesting - how did you set up and use the storage?

p2 commented 10 years ago

SQLite is a dynamic library on OS X and iOS, apparently it's loaded on demand? @mro , if you can test that this works for you we can close this for good.

smamessier commented 10 years ago

This works well (tested on iphone5 - ios7 device)

NSString *docsDir;
NSArray *dirPaths;
// Get the documents directory to check DB existence
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];

// Build the path to the database file
databasePath = [[NSString alloc] initWithString:[docsDir stringByAppendingPathComponent: @"dbFileName.db"]];

// Creating, opening 
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: databasePath ] == NO)
{   // Database does not exist, we ask redland to create the tables, etc...
    storage = [[RedlandStorage alloc] initWithFactoryName:@"sqlite" identifier:databasePath options:@"new='yes'"];
}
else{ // Redland normal initialization
    storage = [[RedlandStorage alloc] initWithFactoryName:@"sqlite" identifier:databasePath options:@"new='no'"];
}

and then

    model = [[RedlandModel alloc] initWithStorage:storage];
mro commented 10 years ago

odd - the demo at https://github.com/mro/RedlandDemo/commit/d73c597d2f710c2ee37d7e32dfbd312a0c4de93e fails - bot on device and simulator:

2014-05-09 16:52:19.615 RedlandDemo[844:60b] Redland Error 0: {
    facility = 14;
    level = 4;
    locator = "<00000000>";
    message = "storage 'sqlite' not found";
}
2014-05-09 16:52:19.618 RedlandDemo[844:60b] initWithWrappedObject: Cannot wrap NULL object!

Any ideas?

smamessier commented 10 years ago

Did you add the sqlite lib to the frameworks ?

p2 commented 10 years ago

You need to link sqlite3.dylib.

Edit: dammit, too slow. ;)

mro commented 10 years ago

have linked sqlite. Found it works on simulator 'iPhone Retina (4-inch 64-bit)' only. So it must be about .a linking?

Could you have a look at https://github.com/mro/RedlandDemo/commit/d73c597d2f710c2ee37d7e32dfbd312a0c4de93e - maybe you've got an idea (I'm clueless so far).

mro commented 10 years ago
grep -B 1 "Triple stores enabled" Redland-source/build-*/redland-*/config.log

yields no mention of sqlite, so I doubt it's supported. (see also https://github.com/p2/RedlandDemo/commit/4441e8005a740fd548ee73316a22e4a254c98bf2#commitcomment-6347271)

@smamessier can you verify https://github.com/p2/RedlandDemo works with sqlite storage for you?

mro commented 10 years ago

I could get it to run by the following recipe (but causing linker errors on all simulator builds except 'iPhone'):

$ cd Redland-source
$ grep -B 1 "Triple stores enabled" build-*/redland-*/config.log
$ grep -A 1 "checking using sqlite library" build-*/redland-*/config.log
$ pkg-config --exists --print-errors "sqlite3"
$ brew install sqlite3
$ ls -l /usr/local/Cellar/sqlite/*/lib/pkgconfig/
$ export PKG_CONFIG_PATH=/usr/local/Cellar/sqlite/*/lib/pkgconfig/
patch pp-configure.sh to look like this:
$ grep "export PKG_CONFIG_PATH" */pp-configure.sh 
Mac/pp-configure.sh:export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:${PKG_CONFIG_PATH}"
Sim/pp-configure.sh:export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig"
iOS/pp-configure.sh:export PKG_CONFIG_PATH="${SDKROOT}/usr/lib/pkgconfig:${DEVROOT}/usr/lib/pkgconfig:${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}"
$ ./start-over.sh
$ ./cross-compile.py
$ grep -B 1 "Triple stores enabled" build-*/redland-*/config.log

Issue is IMO how to persuade configure to use the shipped sqlite and not taint the PKG_CONFIG_PATH.