Richard,

> Can you please provide more details on how having a dynamic string for
> the pointer type would be helpful?  What is it that you are trying to
> do that string constant will not work?  Please be as specific as
> possible, so that I might better understand your problem.

I maintain a C++ wrapper library for SQLite especially for developers of 
wxWidgets based applications. This wrapper library offers access to almost all 
SQLite features (that make sense for an end-user application) through the use 
of C++ classes. That is, the wrapper classes encapsulate all calls to the 
SQlite C API.

With the release of SQLite 3.20.0 the new pointer-passing interface was 
introduced, and I found it quite useful to support extensions like carray. 
Therefore, I implemented a pointer bind method for the prepared SQL statement 
classs. This method makes internally a call to function sqlite3_bind_pointer. 
The signature and implementation of the method looks like this:

void wxSQLite3Statement::Bind(int paramIndex, void* pointer, const wxString& 
pointerType, void(*DeletePointer)(void*))
{
  CheckStmt();
  const char* localPointerType = m_stmt->MakePointerTypeCopy(pointerType);
  int rc = sqlite3_bind_pointer(m_stmt->m_stmt, paramIndex, pointer, 
localPointerType, DeletePointer);
}

The member variable m_stmt is a reference counted reference object to a 
prepared SQL statement (sqlite3_stmt). This makes it possible to pass around 
the SQL statement object and to clean up the SQLite data structures when the 
last reference to the statement is deleted. This reference object now includes 
a dynamic array holding pointer type string duplicates until the reference 
object itself goes out of scope.

However, in my first implementation I converted the pointer type string 
parameter (wxString object) to a local char* variable. Since this local 
variable was destroyed after leaving the method, the select on the carray table 
failed, since the pointer type string was void.

Now, I create a copy of the pointer type string in a data structure that is 
kept alive until the SQL statement object is deleted. The carray extension now 
works flawlessly in the context of my wrapper.

For a C++ wrapper you could argue that using the SQLite API directly is 
feasible. However, for SQLite wrappers for other languages like Python or Lua, 
this might not work out.

Regards,

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

Reply via email to