You need to wrap the rankfunc code with code to link back into the engine.  You 
then need to define DLL_EXPORT to whatever (if anything) your platform compiler 
needs to generate an external shared library symbol, and then compile as a 
shared library.  The code basically sets up the linkage necessary to let the 
extension reference the sqlite3 functions.  The sqlite3_extension_init is 
called when you .load the module.  It initializes the linkage then calls the 
function which registers "rankfunc" in the C code as the function "rank" in 
SQLite's SQL engine.

I haven't any experience with MAC OS X do I don't know how you build a dynamic 
library on a mac.  You should be able to look at how the sqlite3 library itself 
is built and duplicate that, however.

#ifdef __cplusplus
extern "C" {
#endif

#ifndef SQLITE_PRIVATE
    #define SQLITE_PRIVATE static
#endif

#ifdef SQLITE_CORE
    #include "sqlite3.h"
#else
    #include "sqlite3ext.h"
    SQLITE_EXTENSION_INIT1
#endif

// (rankfunc code as SQLITE_PRIVATE)

#ifndef SQLITE_CORE
    SQLITE_PRIVATE
#endif
int sqlite3_sqlfunc_init(sqlite3 *db)
{
    int nErr = 0;

    nErr += sqlite3_create_function(db, "rank",         0, SQLITE_ANY,  0,      
        rankfunc,       0, 0);

    return nErr ? SQLITE_ERROR : SQLITE_OK;
}

#ifndef SQLITE_CORE
DLL_EXPORT int sqlite3_extension_init(sqlite3 *db, char **pzErrMsg, const 
sqlite3_api_routines *pApi)
{
    SQLITE_EXTENSION_INIT2(pApi)
    return sqlite3_sqlfunc_init(db);
}
#endif

#ifdef __cplusplus
}
#endif



---
()  ascii ribbon campaign against html e-mail
/\  www.asciiribbon.org


> -----Original Message-----
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of AJ ONeal
> Sent: Saturday, 21 July, 2012 10:43
> To: General Discussion of SQLite Database; d...@sqlite.org
> Subject: Re: [sqlite] How to compile and load the example fts4 rank function?
> 
> That example isn't from a 3rd party. It's the rank function listed here:
> http://www.sqlite.org/fts3.html#appendix_a
> 
> Can you give me a link to documentation for what options to pass to gcc and
> what functions to call to activate such an extension?
> 
> I've never done this before.
> 
> AJ ONeal
> 
> On Sat, Jul 21, 2012 at 10:34 AM, Richard Hipp <d...@sqlite.org> wrote:
> 
> > On Sat, Jul 21, 2012 at 3:36 AM, AJ ONeal <coola...@gmail.com> wrote:
> >
> > > I naively tried
> > >
> > > wget
> > >
> > >
> >
> https://raw.github.com/gist/3154964/d570955d45580c095c99de6eb0c378395d4b076d/
> sqlite3-fts4-rank.c
> > > gcc -c sqlite3-fts4-rank.c -o sqlite3-fts4-rank.o
> > >
> > > sqlite3
> > > .load sqlite3-fts4-rank.o
> > >
> > > But that didn't work.
> > >
> > > Can I get a link to the docs on this? I don't think I was using the right
> > > search terms to find it.
> > >
> >
> > Anything you find on GitHub is put there by a private third-party and is
> > not endorsed or supported by the SQLite core team.  This doesn't mean it is
> > bad or deficient - it might be great software.  It also doesn't mean you
> > cannot get help for it on this mailing list, since lots of people hang out
> > here who might know what you are talking about.  Just understand that what
> > you are working with is not part of the SQLite core and is thus likely to
> > be unknown to a large percentage of the readers of this list, so don't be
> > disappointed if you don't get a quick response.  Also, please don't blame
> > us if it lacks appropriate documentation or doesn't work so well.  Thanks.
> >
> >
> >
> > >
> > > AJ ONeal
> > > _______________________________________________
> > > sqlite-users mailing list
> > > sqlite-users@sqlite.org
> > > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> > >
> >
> >
> >
> > --
> > D. Richard Hipp
> > d...@sqlite.org
> > _______________________________________________
> > sqlite-users mailing list
> > sqlite-users@sqlite.org
> > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> >
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to