3

I'm hoping to get some help declaring and using a nested struct type with Cython. In the sqlite3.h header file, there is this:

struct sqlite3_index_info {
  int nConstraint;           /* Number of entries in aConstraint */

  struct sqlite3_index_constraint {
     int iColumn;              /* Column on left-hand side of constraint */
     unsigned char op;         /* Constraint operator */
     unsigned char usable;     /* True if this constraint is usable */
     int iTermOffset;          /* Used internally - xBestIndex should ignore */
  } *aConstraint;            /* Table of WHERE clause constraints */
  ... more members ...
}

That is the only place sqlite3_index_constraint is declared.

In an example C library provided by the author of SQLite, these structs are used:

 const struct sqlite3_index_constraint *pConstraint;
 pConstraint = pIdxInfo->aConstraint;

I've tried to declare the "sqlite3_index_constraint" separately, so I have:

const struct sqlite3_index_constraint *pConstraint; 
pConstraint = pIdxInfo->aConstraint;

In my code I try to cdef sqlite3_index_constraint *pConstraint and it cythonizes, but fails to compile with:

error: unknown type name ‘sqlite3_index_constraint’
coleifer
  • 24,887
  • 6
  • 60
  • 75
  • I haven't tested it, but I'd expect it would work if you `cdef`ed `sqlite3_index_constraint` as a normal non-nested struct in Cython (the Cython declaration often doesn't have to match the C one exactly for it to work). Other than that, you might need to post a bit more of your Cython code for anyone to comment. – DavidW Nov 21 '15 at 20:47

0 Answers0