/// <summary>
        /// Takes the return value from Invoke() and Final() and figures out how to return it to SQLite's context.
        /// </summary>
        /// <param name="context">The context the return value applies to</param>
        /// <param name="returnValue">The parameter to return to SQLite</param>
        void SetReturnValue(IntPtr context, object returnValue)
        {
            if (returnValue == null || returnValue == DBNull.Value)
            {
                _base.ReturnNull(context);
                return;
            }

            Type t = returnValue.GetType();

            if (t == typeof(DateTime))
            {
                _base.ReturnText(context, _base.ToString((DateTime)returnValue));
                return;
            }
            else
            {
                Exception r = returnValue as Exception;

                if (r != null)
                {
                    _base.ReturnError(context, r.Message);
                    return;
                }
            }

            switch (SqliteConvert.TypeToAffinity(t))
            {
            case TypeAffinity.Null:
                _base.ReturnNull(context);
                return;

            case TypeAffinity.Int64:
                _base.ReturnInt64(context, Convert.ToInt64(returnValue, CultureInfo.CurrentCulture));
                return;

            case TypeAffinity.Double:
                _base.ReturnDouble(context, Convert.ToDouble(returnValue, CultureInfo.CurrentCulture));
                return;

            case TypeAffinity.Text:
                _base.ReturnText(context, returnValue.ToString());
                return;

            case TypeAffinity.Blob:
                _base.ReturnBlob(context, (byte[])returnValue);
                return;
            }
        }