How can I load an extension? #39

Closed
iox opened this Issue Jun 14, 2011 · 4 comments

Projects

None yet

2 participants

@iox
iox commented Jun 14, 2011

I've seen in the Changelog and the commits history some changes to database.c, that enable "load_extension".

But I don't know how to load an extension because I can't find any documentation. Could you please give me a small example or some indications?

Thank you very much.

@kashif
Contributor
kashif commented Jun 14, 2011

to load an extension for a database, you first need to call:

db.enable_load_extension(1)
db.load_extension("/usr/local/lib/extension.dylib")
db.enable_load_extension(0)

hope this helps.

@iox
iox commented Jun 15, 2011

You are a genius! Thank you very much.

We finally managed to make Sqlite work with spanish collation :). We compiled the ICU extension (http://stackoverflow.com/questions/611459/how-to-sort-text-in-sqlite3-with-specified-locale) and then edited the sqlite3 rails adapter: activerecord-2.3.8/lib/active_record/connection_adapters/sqlite3_adapter.rb

  db = SQLite3::Database.new(
    config[:database],
    :results_as_hash => true,
    :type_translation => false
  )
  # HACK: load extension and spanish collation
  db.enable_load_extension(1)
  db.load_extension("/usr/local/lib/libSqliteIcu.so")
  db.enable_load_extension(0)
  db.execute( "SELECT icu_load_collation('es_ES', 'SPANISH')" )
@iox iox closed this Jun 15, 2011
@kashif
Contributor
kashif commented Jun 15, 2011

you dont really need to edit the sqlite adapter in activerecord, but simply get the raw connection from activerecord and enable and load the extension from within your app. perhaps thats easier, especially when you update activerecord etc.

@iox
iox commented Jun 15, 2011

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mmm, interesting, thanks for the tip :)

El 15/06/11 10:35, kashif escribió:

you dont really need to edit the sqlite adapter in activerecord, but simply get the raw connection from activerecord and enable and load the extension from within your app. perhaps thats easier, especially when you update activerecord etc.


Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk34dhAACgkQBPlUJ6RHaORcfwCfX5/XLK7kooDn7sJpTAiQqs1O
abIAn0UCsGgkchaQQIhnr7xf9CF5Uc63
=+pqy
-----END PGP SIGNATURE-----

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment