예제 #1
0
 private SQLiteTypeCallbacks(SQLiteBindValueCallback bindValueCallback, SQLiteReadValueCallback readValueCallback, object bindValueUserData, object readValueUserData)
 {
     this.bindValueCallback = bindValueCallback;
     this.readValueCallback = readValueCallback;
     this.bindValueUserData = bindValueUserData;
     this.readValueUserData = readValueUserData;
 }
예제 #2
0
        private void InvokeBindValueCallback(int index, SQLiteParameter parameter, out bool complete)
        {
            SQLiteTypeCallbacks sQLiteTypeCallback;

            complete = false;
            SQLiteConnectionFlags sQLiteConnectionFlag = this._flags;
            SQLiteStatement       sQLiteStatement      = this;

            sQLiteStatement._flags = sQLiteStatement._flags & (SQLiteConnectionFlags.LogPrepare | SQLiteConnectionFlags.LogPreBind | SQLiteConnectionFlags.LogBind | SQLiteConnectionFlags.LogCallbackException | SQLiteConnectionFlags.LogBackup | SQLiteConnectionFlags.NoExtensionFunctions | SQLiteConnectionFlags.BindUInt32AsInt64 | SQLiteConnectionFlags.BindAllAsText | SQLiteConnectionFlags.GetAllAsText | SQLiteConnectionFlags.NoLoadExtension | SQLiteConnectionFlags.NoCreateModule | SQLiteConnectionFlags.NoBindFunctions | SQLiteConnectionFlags.NoLogModule | SQLiteConnectionFlags.LogModuleError | SQLiteConnectionFlags.LogModuleException | SQLiteConnectionFlags.TraceWarning | SQLiteConnectionFlags.ConvertInvariantText | SQLiteConnectionFlags.BindInvariantText | SQLiteConnectionFlags.NoConnectionPool | SQLiteConnectionFlags.UseConnectionPool | SQLiteConnectionFlags.UseConnectionTypes | SQLiteConnectionFlags.NoGlobalTypes | SQLiteConnectionFlags.StickyHasRows | SQLiteConnectionFlags.StrictEnlistment | SQLiteConnectionFlags.MapIsolationLevels | SQLiteConnectionFlags.DetectTextAffinity | SQLiteConnectionFlags.DetectStringType | SQLiteConnectionFlags.NoConvertSettings | SQLiteConnectionFlags.BindDateTimeWithKind | SQLiteConnectionFlags.RollbackOnException | SQLiteConnectionFlags.DenyOnException | SQLiteConnectionFlags.InterruptOnException | SQLiteConnectionFlags.UnbindFunctionsOnClose | SQLiteConnectionFlags.NoVerifyTextAffinity | SQLiteConnectionFlags.UseConnectionReadValueCallbacks | SQLiteConnectionFlags.UseParameterNameForTypeName | SQLiteConnectionFlags.UseParameterDbTypeForTypeName | SQLiteConnectionFlags.NoVerifyTypeAffinity | SQLiteConnectionFlags.AllowNestedTransactions | SQLiteConnectionFlags.BindDecimalAsText | SQLiteConnectionFlags.GetDecimalAsText | SQLiteConnectionFlags.BindInvariantDecimal | SQLiteConnectionFlags.GetInvariantDecimal | SQLiteConnectionFlags.BindAndGetAllAsText | SQLiteConnectionFlags.ConvertAndBindInvariantText | SQLiteConnectionFlags.BindAndGetAllAsInvariantText | SQLiteConnectionFlags.ConvertAndBindAndGetAllAsInvariantText | SQLiteConnectionFlags.UseParameterAnythingForTypeName | SQLiteConnectionFlags.LogAll | SQLiteConnectionFlags.LogDefault | SQLiteConnectionFlags.Default | SQLiteConnectionFlags.DefaultAndLogAll);
            try
            {
                if (parameter != null)
                {
                    SQLiteConnection connection = SQLiteStatement.GetConnection(this);
                    if (connection != null)
                    {
                        string typeName = parameter.TypeName;
                        if (typeName == null && (this._flags & SQLiteConnectionFlags.UseParameterNameForTypeName) == SQLiteConnectionFlags.UseParameterNameForTypeName)
                        {
                            typeName = parameter.ParameterName;
                        }
                        if (typeName == null && (this._flags & SQLiteConnectionFlags.UseParameterDbTypeForTypeName) == SQLiteConnectionFlags.UseParameterDbTypeForTypeName)
                        {
                            typeName = SQLiteConvert.DbTypeToTypeName(connection, parameter.DbType, this._flags);
                        }
                        if (typeName != null)
                        {
                            if (connection.TryGetTypeCallbacks(typeName, out sQLiteTypeCallback) && sQLiteTypeCallback != null)
                            {
                                SQLiteBindValueCallback bindValueCallback = sQLiteTypeCallback.BindValueCallback;
                                if (bindValueCallback != null)
                                {
                                    object bindValueUserData = sQLiteTypeCallback.BindValueUserData;
                                    bindValueCallback(this._sql, this._command, sQLiteConnectionFlag, parameter, typeName, index, bindValueUserData, out complete);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                this._flags |= SQLiteConnectionFlags.UseConnectionBindValueCallbacks;
            }
        }
예제 #3
0
        /// <summary>
        /// Invokes the parameter binding callback configured for the database
        /// type name associated with the specified column.  If no parameter
        /// binding callback is available for the database type name, do
        /// nothing.
        /// </summary>
        /// <param name="index">
        /// The index of the column being read.
        /// </param>
        /// <param name="parameter">
        /// The <see cref="SQLiteParameter" /> instance being bound to the
        /// command.
        /// </param>
        /// <param name="complete">
        /// Non-zero if the default handling for the parameter binding call
        /// should be skipped (i.e. the parameter should not be bound at all).
        /// Great care should be used when setting this to non-zero.
        /// </param>
        private void InvokeBindValueCallback(
            int index,
            SQLiteParameter parameter,
            out bool complete
            )
        {
            complete = false;
            SQLiteConnectionFlags oldFlags = _flags;

            _flags &= ~SQLiteConnectionFlags.UseConnectionBindValueCallbacks;

            try
            {
                if (parameter == null)
                {
                    return;
                }

                SQLiteConnection connection = GetConnection(this);

                if (connection == null)
                {
                    return;
                }

                //
                // NOTE: First, always look for an explicitly set database type
                //       name.
                //
                string typeName = parameter.TypeName;

                if (typeName == null)
                {
                    //
                    // NOTE: Are we allowed to fallback to using the parameter name
                    //       as the basis for looking up the binding callback?
                    //
                    if (HelperMethods.HasFlags(
                            _flags, SQLiteConnectionFlags.UseParameterNameForTypeName))
                    {
                        typeName = parameter.ParameterName;
                    }
                }

                if (typeName == null)
                {
                    //
                    // NOTE: Are we allowed to fallback to using the database type
                    //       name translated from the DbType as the basis for looking
                    //       up the binding callback?
                    //
                    if (HelperMethods.HasFlags(
                            _flags, SQLiteConnectionFlags.UseParameterDbTypeForTypeName))
                    {
                        typeName = SQLiteConvert.DbTypeToTypeName(
                            connection, parameter.DbType, _flags);
                    }
                }

                if (typeName == null)
                {
                    return;
                }

                SQLiteTypeCallbacks callbacks;

                if (!connection.TryGetTypeCallbacks(typeName, out callbacks) ||
                    (callbacks == null))
                {
                    return;
                }

                SQLiteBindValueCallback callback = callbacks.BindValueCallback;

                if (callback == null)
                {
                    return;
                }

                object userData = callbacks.BindValueUserData;

                callback(
                    _sql, _command, oldFlags, parameter, typeName, index,
                    userData, out complete); /* throw */
            }
            finally
            {
                _flags |= SQLiteConnectionFlags.UseConnectionBindValueCallbacks;
            }
        }
예제 #4
0
 public static SQLiteTypeCallbacks Create(SQLiteBindValueCallback bindValueCallback, SQLiteReadValueCallback readValueCallback, object bindValueUserData, object readValueUserData)
 {
     return(new SQLiteTypeCallbacks(bindValueCallback, readValueCallback, bindValueUserData, readValueUserData));
 }