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