System.Data.SQLite
Check-in [344a8bd45f]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add an overload of the static Execute method to the SQLiteCommand class that accepts an open connection.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1: 344a8bd45f30e1ba7dfc42cfe5e403b46393d978
User & Date: mistachkin 2020-02-02 04:18:13
Context
2020-02-02
04:18
Add an overload of the static Execute method to the SQLiteCommand class that accepts an open connection. Leaf check-in: 344a8bd45f user: mistachkin tags: trunk
2020-01-26
22:06
Merge all changes from SQLite core library pre-release branch. check-in: 1868813f4f user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLiteCommand.cs.

920
921
922
923
924
925
926




















































































927
928
929
930
931
932
933
            //       always done if the connection was created because
            //       it will be harmless whether or not the data reader
            //       now owns it.
            //
            if (connection != null)
                connection._noDispose = false;
        }





















































































        return null;
    }

    /// <summary>
    /// Overrides the default behavior to return a SQLiteDataReader specialization class
    /// </summary>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
            //       always done if the connection was created because
            //       it will be harmless whether or not the data reader
            //       now owns it.
            //
            if (connection != null)
                connection._noDispose = false;
        }

        return null;
    }

    /// <summary>
    /// This method executes a query using the given execution type and command
    /// behavior and returns the results.
    /// </summary>
    /// <param name="commandText">
    /// The text of the command to be executed.
    /// </param>
    /// <param name="executeType">
    /// The execution type for the command.  This is used to determine which method
    /// of the command object to call, which then determines the type of results
    /// returned, if any.
    /// </param>
    /// <param name="commandBehavior">
    /// The command behavior flags for the command.
    /// </param>
    /// <param name="connection">
    /// The connection used to create and execute the command.
    /// </param>
    /// <param name="args">
    /// The SQL parameter values to be used when building the command object to be
    /// executed, if any.
    /// </param>
    /// <returns>
    /// The results of the query -OR- null if no results were produced from the
    /// given execution type.
    /// </returns>
    public static object Execute(
        string commandText,
        SQLiteExecuteType executeType,
        CommandBehavior commandBehavior,
        SQLiteConnection connection,
        params object[] args
        )
    {
        SQLiteConnection.Check(connection);

        using (SQLiteCommand command = connection.CreateCommand())
        {
            command.CommandText = commandText;

            if (args != null)
            {
                foreach (object arg in args)
                {
                    SQLiteParameter parameter = arg as SQLiteParameter;

                    if (parameter == null)
                    {
                        parameter = command.CreateParameter();
                        parameter.DbType = DbType.Object;
                        parameter.Value = arg;
                    }

                    command.Parameters.Add(parameter);
                }
            }

            switch (executeType)
            {
                case SQLiteExecuteType.None:
                    {
                        //
                        // NOTE: Do nothing.
                        //
                        break;
                    }
                case SQLiteExecuteType.NonQuery:
                    {
                        return command.ExecuteNonQuery(commandBehavior);
                    }
                case SQLiteExecuteType.Scalar:
                    {
                        return command.ExecuteScalar(commandBehavior);
                    }
                case SQLiteExecuteType.Reader:
                    {
                        return command.ExecuteReader(commandBehavior);
                    }
            }
        }

        return null;
    }

    /// <summary>
    /// Overrides the default behavior to return a SQLiteDataReader specialization class
    /// </summary>