[Interest] Sqlite3 handler access

Constantin Makshin cmakshin at gmail.com
Tue Aug 14 13:52:29 CEST 2012


Don't use the undocumented QVariant::data() method designed for some
Qt's internal purposes. Use QVariant::value():

sqlite3* handler = v.value<sqlite3*>();

On Mon, Aug 13, 2012 at 10:16 PM, Scott Aron Bloom
<Scott.Bloom at onshorecs.com> wrote:
> I need to add a custom command to my sqlite3 system Im accessing via
> QSqlDatabase..
>
>
>
> Per reading found at sourceforge and qtcentre, I have compiled in the code
> locally from the Qt source area..
>
>
>
> However, on the call to sqlite3_create_function, sqlite is crashing…
>
>
>
> extern "C"
>
> void getMsgID( sqlite3_context * context, int argc, sqlite3_value ** argv )
>
> {
>
>     assert( argc == 2 );
>
>     sqlite3_result_int( context, 0 );
>
> }
>
>
>
> bool loadCustomCommands( QSqlDatabase & db )
>
> {
>
>     QVariant v = db.driver()->handle();
>
>     if ( !v.isValid() || qstrcmp( v.typeName(), "sqlite3*" ) != 0 )
>
>     {
>
>         return false;
>
>     }
>
>
>
>     sqlite3 * handler = *static_cast<sqlite3**>( v.data() );
>
>     if ( !handler )
>
>         return false;
>
>
>
>     sqlite3_create_function( handler, "msgid", 2, SQLITE_ANY, NULL,
> &getMsgID, NULL, NULL );
>
>     return true;
>
> }
>
>
>
> Any thoughts, ideas??
>
>
> Scott



More information about the Interest mailing list