Esempio n. 1
0
        /// <summary>
        /// This function binds a user-defined functions to a connection.
        /// </summary>
        /// <param name="sqliteBase">
        /// The <see cref="SQLiteBase" /> object instance associated with the
        /// <see cref="SQLiteConnection" /> that the function should be bound to.
        /// </param>
        /// <param name="functionAttribute">
        /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
        /// the metadata for the function to be bound.
        /// </param>
        /// <param name="function">
        /// The <see cref="SQLiteFunction"/> object instance that implements the
        /// function to be bound.
        /// </param>
        /// <param name="flags">
        /// The flags associated with the parent connection object.
        /// </param>
        internal static void BindFunction(
            SQLiteBase sqliteBase,
            SQLiteFunctionAttribute functionAttribute,
            SQLiteFunction function,
            SQLiteConnectionFlags flags
            )
        {
            if (sqliteBase == null)
            {
                throw new ArgumentNullException("sqliteBase");
            }

            if (functionAttribute == null)
            {
                throw new ArgumentNullException("functionAttribute");
            }

            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            FunctionType functionType = functionAttribute.FuncType;

            function._base  = sqliteBase;
            function._flags = flags;

            function._InvokeFunc = (functionType == FunctionType.Scalar) ?
                                   new SQLiteCallback(function.ScalarCallback) : null;

            function._StepFunc = (functionType == FunctionType.Aggregate) ?
                                 new SQLiteCallback(function.StepCallback) : null;

            function._FinalFunc = (functionType == FunctionType.Aggregate) ?
                                  new SQLiteFinalCallback(function.FinalCallback) : null;

            function._CompareFunc = (functionType == FunctionType.Collation) ?
                                    new SQLiteCollation(function.CompareCallback) : null;

            function._CompareFunc16 = (functionType == FunctionType.Collation) ?
                                      new SQLiteCollation(function.CompareCallback16) : null;

            string name = functionAttribute.Name;

            if (functionType != FunctionType.Collation)
            {
                bool needCollSeq = (function is SQLiteFunctionEx);

                sqliteBase.CreateFunction(
                    name, functionAttribute.Arguments, needCollSeq,
                    function._InvokeFunc, function._StepFunc,
                    function._FinalFunc);
            }
            else
            {
                sqliteBase.CreateCollation(
                    name, function._CompareFunc, function._CompareFunc16);
            }
        }
Esempio n. 2
0
 static SQLiteFunction()
 {
     try
     {
         Assembly[]   assemblies = AppDomain.CurrentDomain.GetAssemblies();
         int          length     = assemblies.Length;
         AssemblyName name       = Assembly.GetCallingAssembly().GetName();
         for (int i = 0; i < length; i++)
         {
             Type[] types;
             bool   flag = false;
             try
             {
                 AssemblyName[] referencedAssemblies = assemblies[i].GetReferencedAssemblies();
                 int            num3 = referencedAssemblies.Length;
                 for (int k = 0; k < num3; k++)
                 {
                     if (referencedAssemblies[k].Name == name.Name)
                     {
                         flag = true;
                         break;
                     }
                 }
                 if (!flag)
                 {
                     continue;
                 }
                 types = assemblies[i].GetTypes();
             }
             catch (ReflectionTypeLoadException exception)
             {
                 types = exception.Types;
             }
             int num5 = types.Length;
             for (int j = 0; j < num5; j++)
             {
                 if (types[j] != null)
                 {
                     object[] customAttributes = types[j].GetCustomAttributes(typeof(SQLiteFunctionAttribute), false);
                     int      num7             = customAttributes.Length;
                     for (int m = 0; m < num7; m++)
                     {
                         SQLiteFunctionAttribute item = customAttributes[m] as SQLiteFunctionAttribute;
                         if (item != null)
                         {
                             item._instanceType = types[j];
                             _registeredFunctions.Add(item);
                         }
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }
Esempio n. 3
0
        public static void RegisterFunction(Type typ)
        {
            object[] customAttributes = typ.GetCustomAttributes(typeof(SQLiteFunctionAttribute), false);
            int      length           = customAttributes.Length;

            for (int i = 0; i < length; i++)
            {
                SQLiteFunctionAttribute item = customAttributes[i] as SQLiteFunctionAttribute;
                if (item != null)
                {
                    item._instanceType = typ;
                    _registeredFunctions.Add(item);
                }
            }
        }
    ///////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Attempts to bind the specified <see cref="SQLiteFunction" /> object
    /// instance to this connection.
    /// </summary>
    /// <param name="functionAttribute">
    /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
    /// the metadata for the function to be bound.
    /// </param>
    /// <param name="function">
    /// The <see cref="SQLiteFunction"/> object instance that implements the
    /// function to be bound.
    /// </param>
    public void BindFunction(
        SQLiteFunctionAttribute functionAttribute,
        SQLiteFunction function
        )
    {
        CheckDisposed();

        if (_sql == null)
            throw new InvalidOperationException(
                "Database connection not valid for binding functions.");

        _sql.BindFunction(functionAttribute, function, _flags);
    }
 /// <summary>
 /// This function binds a user-defined functions to the connection.
 /// </summary>
 /// <param name="functionAttribute">
 /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
 /// the metadata for the function to be bound.
 /// </param>
 /// <param name="function">
 /// The <see cref="SQLiteFunction"/> object instance that implements the
 /// function to be bound.
 /// </param>
 /// <param name="flags">
 /// The flags associated with the parent connection object.
 /// </param>
 internal abstract void BindFunction(SQLiteFunctionAttribute functionAttribute, SQLiteFunction function, SQLiteConnectionFlags flags);
    /// <summary>
    /// This function binds a user-defined functions to a connection.
    /// </summary>
    /// <param name="sqliteBase">
    /// The <see cref="SQLiteBase" /> object instance associated with the
    /// <see cref="SQLiteConnection" /> that the function should be bound to.
    /// </param>
    /// <param name="functionAttribute">
    /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
    /// the metadata for the function to be bound.
    /// </param>
    /// <param name="function">
    /// The <see cref="SQLiteFunction"/> object instance that implements the
    /// function to be bound.
    /// </param>
    /// <param name="flags">
    /// The flags associated with the parent connection object.
    /// </param>
    internal static void BindFunction(
        SQLiteBase sqliteBase,
        SQLiteFunctionAttribute functionAttribute,
        SQLiteFunction function,
        SQLiteConnectionFlags flags
        )
    {
        if (sqliteBase == null)
            throw new ArgumentNullException("sqliteBase");

        if (functionAttribute == null)
            throw new ArgumentNullException("functionAttribute");

        if (function == null)
            throw new ArgumentNullException("function");

        FunctionType functionType = functionAttribute.FuncType;

        function._base = sqliteBase;
        function._flags = flags;

        function._InvokeFunc = (functionType == FunctionType.Scalar) ?
            new SQLiteCallback(function.ScalarCallback) : null;

        function._StepFunc = (functionType == FunctionType.Aggregate) ?
            new SQLiteCallback(function.StepCallback) : null;

        function._FinalFunc = (functionType == FunctionType.Aggregate) ?
            new SQLiteFinalCallback(function.FinalCallback) : null;

        function._CompareFunc = (functionType == FunctionType.Collation) ?
            new SQLiteCollation(function.CompareCallback) : null;

        function._CompareFunc16 = (functionType == FunctionType.Collation) ?
            new SQLiteCollation(function.CompareCallback16) : null;

        string name = functionAttribute.Name;

        if (functionType != FunctionType.Collation)
        {
            bool needCollSeq = (function is SQLiteFunctionEx);

            sqliteBase.CreateFunction(
                name, functionAttribute.Arguments, needCollSeq,
                function._InvokeFunc, function._StepFunc,
                function._FinalFunc);
        }
        else
        {
            sqliteBase.CreateCollation(
                name, function._CompareFunc, function._CompareFunc16);
        }
    }
Esempio n. 7
0
 /// <summary>
 /// This function binds a user-defined functions to the connection.
 /// </summary>
 /// <param name="functionAttribute">
 /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
 /// the metadata for the function to be bound.
 /// </param>
 /// <param name="function">
 /// The <see cref="SQLiteFunction"/> object instance that implements the
 /// function to be bound.
 /// </param>
 /// <param name="flags">
 /// The flags associated with the parent connection object.
 /// </param>
 internal abstract void BindFunction(SQLiteFunctionAttribute functionAttribute, SQLiteFunction function, SQLiteConnectionFlags flags);
    /// <summary>
    /// This function binds a user-defined function to the connection.
    /// </summary>
    /// <param name="functionAttribute">
    /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
    /// the metadata for the function to be bound.
    /// </param>
    /// <param name="function">
    /// The <see cref="SQLiteFunction"/> object instance that implements the
    /// function to be bound.
    /// </param>
    /// <param name="flags">
    /// The flags associated with the parent connection object.
    /// </param>
    internal override void BindFunction(
        SQLiteFunctionAttribute functionAttribute,
        SQLiteFunction function,
        SQLiteConnectionFlags flags
        )
    {
        SQLiteFunction.BindFunction(this, functionAttribute, function, flags);

        if (_functions == null)
            _functions = new List<SQLiteFunction>();

        _functions.Add(function);
    }
Esempio n. 9
0
 /// <summary>
 /// This function unbinds a user-defined function from the connection.
 /// </summary>
 /// <param name="functionAttribute">
 /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
 /// the metadata for the function to be unbound.
 /// </param>
 /// <param name="flags">
 /// The flags associated with the parent connection object.
 /// </param>
 /// <returns>Non-zero if the function was unbound.</returns>
 internal abstract bool UnbindFunction(SQLiteFunctionAttribute functionAttribute, SQLiteConnectionFlags flags);
Esempio n. 10
0
    /// <summary>
    /// This function binds a user-defined function to the connection.
    /// </summary>
    /// <param name="functionAttribute">
    /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
    /// the metadata for the function to be unbound.
    /// </param>
    /// <param name="flags">
    /// The flags associated with the parent connection object.
    /// </param>
    /// <returns>Non-zero if the function was unbound and removed.</returns>
    internal override bool UnbindFunction(
        SQLiteFunctionAttribute functionAttribute,
        SQLiteConnectionFlags flags
        )
    {
        if (functionAttribute == null)
            throw new ArgumentNullException("functionAttribute");

        if (_functions == null)
            return false;

        SQLiteFunction function;

        if (_functions.TryGetValue(functionAttribute, out function))
        {
            if (SQLiteFunction.UnbindFunction(
                    this, functionAttribute, function, flags) &&
                _functions.Remove(functionAttribute))
            {
                return true;
            }
        }

        return false;
    }
Esempio n. 11
0
    /// <summary>
    /// This function binds a user-defined function to the connection.
    /// </summary>
    /// <param name="functionAttribute">
    /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
    /// the metadata for the function to be bound.
    /// </param>
    /// <param name="function">
    /// The <see cref="SQLiteFunction"/> object instance that implements the
    /// function to be bound.
    /// </param>
    /// <param name="flags">
    /// The flags associated with the parent connection object.
    /// </param>
    internal override void BindFunction(
        SQLiteFunctionAttribute functionAttribute,
        SQLiteFunction function,
        SQLiteConnectionFlags flags
        )
    {
        if (functionAttribute == null)
            throw new ArgumentNullException("functionAttribute");

        if (function == null)
            throw new ArgumentNullException("function");

        SQLiteFunction.BindFunction(this, functionAttribute, function, flags);

        if (_functions == null)
            _functions = new Dictionary<SQLiteFunctionAttribute, SQLiteFunction>();

        _functions[functionAttribute] = function;
    }
Esempio n. 12
0
    /// <summary>
    /// Creates a <see cref="SQLiteFunction" /> instance based on the specified
    /// <see cref="SQLiteFunctionAttribute" />.
    /// </summary>
    /// <param name="functionAttribute">
    /// The <see cref="SQLiteFunctionAttribute" /> containing the metadata about
    /// the function to create.
    /// </param>
    /// <param name="function">
    /// The created function -OR- null if the function could not be created.
    /// </param>
    /// <returns>
    /// Non-zero if the function was created; otherwise, zero.
    /// </returns>
    private static bool CreateFunction(
        SQLiteFunctionAttribute functionAttribute,
        out SQLiteFunction function
        )
    {
        if (functionAttribute == null)
        {
            function = null;
            return false;
        }
        else if ((functionAttribute.Callback1 != null) ||
                (functionAttribute.Callback2 != null))
        {
            function = new SQLiteDelegateFunction(
                functionAttribute.Callback1,
                functionAttribute.Callback2);

            return true;
        }
        else if (functionAttribute.InstanceType != null)
        {
            function = (SQLiteFunction)Activator.CreateInstance(
                functionAttribute.InstanceType);

            return true;
        }
        else
        {
            function = null;
            return false;
        }
    }
Esempio n. 13
0
    /// <summary>
    /// Alternative method of registering a function.  This method
    /// does not require the specified type to be annotated with
    /// <see cref="SQLiteFunctionAttribute" />.
    /// </summary>
    /// <param name="name">
    /// The name of the function to register.
    /// </param>
    /// <param name="argumentCount">
    /// The number of arguments accepted by the function.
    /// </param>
    /// <param name="functionType">
    /// The type of SQLite function being resitered (e.g. scalar,
    /// aggregate, or collating sequence).
    /// </param>
    /// <param name="instanceType">
    /// The <see cref="Type" /> that actually implements the function.
    /// This will only be used if the <paramref name="callback1" />
    /// and <paramref name="callback2" /> parameters are null.
    /// </param>
    /// <param name="callback1">
    /// The <see cref="Delegate" /> to be used for all calls into the
    /// <see cref="SQLiteFunction.Invoke" />,
    /// <see cref="SQLiteFunction.Step" />,
    /// and <see cref="SQLiteFunction.Compare" /> virtual methods.
    /// </param>
    /// <param name="callback2">
    /// The <see cref="Delegate" /> to be used for all calls into the
    /// <see cref="SQLiteFunction.Final" /> virtual method.  This
    /// parameter is only necessary for aggregate functions.
    /// </param>
    public static void RegisterFunction(
        string name,
        int argumentCount,
        FunctionType functionType,
        Type instanceType,
        Delegate callback1,
        Delegate callback2
        )
    {
        SQLiteFunctionAttribute at = new SQLiteFunctionAttribute(
            name, argumentCount, functionType);

        at.InstanceType = instanceType;
        at.Callback1 = callback1;
        at.Callback2 = callback2;

        _registeredFunctions.Add(at, null);
    }
Esempio n. 14
0
    /// <summary>
    /// This function unbinds a user-defined functions from a connection.
    /// </summary>
    /// <param name="sqliteBase">
    /// The <see cref="SQLiteBase" /> object instance associated with the
    /// <see cref="SQLiteConnection" /> that the function should be bound to.
    /// </param>
    /// <param name="functionAttribute">
    /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
    /// the metadata for the function to be bound.
    /// </param>
    /// <param name="function">
    /// The <see cref="SQLiteFunction"/> object instance that implements the
    /// function to be bound.
    /// </param>
    /// <param name="flags">
    /// The flags associated with the parent connection object.
    /// </param>
    /// <returns>Non-zero if the function was unbound.</returns>
    internal static bool UnbindFunction(
        SQLiteBase sqliteBase,
        SQLiteFunctionAttribute functionAttribute,
        SQLiteFunction function,
        SQLiteConnectionFlags flags /* NOT USED */
        )
    {
        if (sqliteBase == null)
            throw new ArgumentNullException("sqliteBase");

        if (functionAttribute == null)
            throw new ArgumentNullException("functionAttribute");

        if (function == null)
            throw new ArgumentNullException("function");

        FunctionType functionType = functionAttribute.FuncType;
        string name = functionAttribute.Name;

        if (functionType != FunctionType.Collation)
        {
            bool needCollSeq = (function is SQLiteFunctionEx);

            return sqliteBase.CreateFunction(
                name, functionAttribute.Arguments, needCollSeq,
                null, null, null, false) == SQLiteErrorCode.Ok;
        }
        else
        {
            return sqliteBase.CreateCollation(
                name, null, null, false) == SQLiteErrorCode.Ok;
        }
    }