Ah. I’m working off of a pretty heavily modified version of the SQLite library, 
so I couldn’t have offered any such version.

Thanks to you and Andreas for the idea of using a 1-length array.

 — John

On Dec 30, 2013, at 11:45 AM, Isaiah Norton <[email protected]> wrote:

> Thanks for the comments, Isaiah! It never occurred to me that library 
> versions would be an issue here because I had forgotten that this function 
> isn’t always defined unless certain compiler directives are enabled.
> 
> I meant the Julia package versions, for example on SQLite.jl/master there was 
> no "SQLite3" symbol, no "ptr" field of the SQLiteDB type, etc. Are you on 
> 0.2-pinned package versions? Anyway, glad that this helped, albeit indirectly 
> :)
> 
> This works for me now, but I’m not sure how to get access to the integer 
> outputs from this function, which are all passed as pointers. I tried to 
> change the return signature, but I don’t think I understand how to do it 
> correctly.
> 
> For this to work, 
> 
>    notnull = zero(Cint)
> 
> should be
> 
>     notnull = Cint[0]
> 
> and so forth, and also remove the "&" from the signature. I sent an email a 
> couple days ago with a little bit more info on this (and I think some 
> discussion was recently added to the docs).
> 
> HTH,
> -Isaiah
>  
> 
> 
> 
> On Mon, Dec 30, 2013 at 11:25 AM, John Myles White <[email protected]> 
> wrote:
> Thanks for the comments, Isaiah! It never occurred to me that library 
> versions would be an issue here because I had forgotten that this function 
> isn’t always defined unless certain compiler directives are enabled.
> 
> I was using the version being found by the default search strategy for 
> SQLite. I’ve changed to using a custom installation to make sure that the 
> library I’m using has access to the function I want.
> 
> This works for me now, but I’m not sure how to get access to the integer 
> outputs from this function, which are all passed as pointers. I tried to 
> change the return signature, but I don’t think I understand how to do it 
> correctly.
> 
>  — John
> 
> On Dec 30, 2013, at 1:44 AM, Isaiah Norton <[email protected]> wrote:
> 
> > It's unclear what version of various libraries you are using, because I had 
> > to make several changes to get this to run. However, the following works 
> > fine (for me..). You might want to try deleting `SQLite/lib/sqlite3.dylib`, 
> > in case an incompatible version of the shared library is being picked up. 
> > The lib should come from HomeBrew if you are on OS X, as SQLite has a 
> > BinDeps install rule (so I'm not sure what the deal is with the dylib and 
> > .so files).
> >
> > using DBI
> > using SQLite
> >
> > db = SQLite.connect("/tmp/db.sqlite3")
> >
> > dbptr = db.handle   # changed
> > table = "users"
> > column = "id"
> > datatype = Array(Ptr{Uint8}, 1)
> > collseq = Array(Ptr{Uint8}, 1)
> > notnull = zero(Cint)
> > primarykey = zero(Cint)
> > autoinc = zero(Cint)
> >
> > ccall((:sqlite3_table_column_metadata, SQLite.sqlite3_lib),   # changed
> >       Cint,
> >       (Ptr{Void},
> >        Ptr{Uint8}, Ptr{Uint8}, Ptr{Uint8},
> >        Ptr{Ptr{Uint8}}, Ptr{Ptr{Uint8}},
> >        Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
> >       dbptr,
> >       convert(Ptr{Uint8}, C_NULL), table, column,
> >       datatype, collseq,
> >       &notnull, &primarykey, &autoinc)
> >
> >
> >
> >
> >
> > On Mon, Dec 30, 2013 at 12:00 AM, John Myles White 
> > <[email protected]> wrote:
> > I’m trying to use ccall to access the following function from the SQLite3 
> > API:
> >
> > int sqlite3_table_column_metadata(
> >   sqlite3 *db,                /* Connection handle */
> >   const char *zDbName,        /* Database name or NULL */
> >   const char *zTableName,     /* Table name */
> >   const char *zColumnName,    /* Column name */
> >   char const **pzDataType,    /* OUTPUT: Declared data type */
> >   char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
> >   int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists 
> > */
> >   int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
> >   int *pAutoinc               /* OUTPUT: True if column is auto-increment */
> > );
> >
> > My attempt to do so keeps failing, so I suspect that I’m just not using 
> > ccall correctly. I keep trying the following lines and getting segfaults:
> >
> > using DBI
> > using SQLite
> >
> > db = connect(SQLite3, "db/tmp.sqlite3")
> >
> > dbptr = db.ptr
> > table = "users"
> > column = "id"
> > datatype = Array(Ptr{Uint8}, 1)
> > collseq = Array(Ptr{Uint8}, 1)
> > notnull = zero(Cint)
> > primarykey = zero(Cint)
> > autoinc = zero(Cint)
> >
> > ccall((:sqlite3_table_column_metadata, sqlite3_lib),
> >       Cint,
> >       (Ptr{Void},
> >        Ptr{Uint8}, Ptr{Uint8}, Ptr{Uint8},
> >        Ptr{Ptr{Uint8}}, Ptr{Ptr{Uint8}},
> >        Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
> >       dbptr,
> >       convert(Ptr{Uint8}, C_NULL), table, column,
> >       datatype, collseq,
> >       &notnull, &primarykey, &autoinc)
> >
> > Any thoughts?
> >
> >
> 
> 

Reply via email to