I think you'll need to define e.g. notnull = zeros(Cint,1) instead of notnull
= zero(Cint) and and remove the &. Then you can access the value by
notnull[1].


2013/12/30 John Myles White <[email protected]>

> 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?
> >
> >
>
>


-- 
Med venlig hilsen

Andreas Noack Jensen

Reply via email to