Beispiel #1
0
        private int ExecuteNonQuery(string method, CommandBehavior behavior, bool createReader)
        {
            int records = 0;

            if (Connection == null)
            {
                throw new InvalidOperationException(string.Format(
                                                        "{0}: Connection is not set.", method));
            }
            if (Connection.State == ConnectionState.Closed)
            {
                throw new InvalidOperationException(string.Format(
                                                        "{0}: Connection state is closed", method));
            }
            if (CommandText.Length == 0)
            {
                throw new InvalidOperationException(string.Format(
                                                        "{0}: CommandText is not set.", method));
            }

            ExecSQL(behavior, createReader, CommandText);

            // .NET documentation says that except for INSERT, UPDATE and
            // DELETE  where the return value is the number of rows affected
            // for the rest of the commands the return value is -1.
            if ((CommandText.ToUpper().IndexOf("UPDATE") != -1) ||
                (CommandText.ToUpper().IndexOf("INSERT") != -1) ||
                (CommandText.ToUpper().IndexOf("DELETE") != -1))
            {
                int numrows = 0;
                libodbc.SQLRowCount(hstmt, ref numrows);
                records = numrows;
            }
            else
            {
                records = -1;
            }

            if (!createReader && !prepared)
            {
                FreeStatement();
            }

            return(records);
        }
Beispiel #2
0
        private int ExecuteNonQuery(bool freeHandle)
        {
            int records = 0;

            if (Connection == null)
            {
                throw new InvalidOperationException("No open connection");
            }
            if (Connection.State == ConnectionState.Closed)
            {
                throw new InvalidOperationException("Connection state is closed");
            }
            // FIXME: a third check is mentioned in .NET docs

            ExecSQL(CommandText);

            // .NET documentation says that except for INSERT, UPDATE and
            // DELETE  where the return value is the number of rows affected
            // for the rest of the commands the return value is -1.
            if ((CommandText.ToUpper().IndexOf("UPDATE") != -1) ||
                (CommandText.ToUpper().IndexOf("INSERT") != -1) ||
                (CommandText.ToUpper().IndexOf("DELETE") != -1))
            {
                int        numrows = 0;
                OdbcReturn ret     = libodbc.SQLRowCount(hstmt, ref numrows);
                records = numrows;
            }
            else
            {
                records = -1;
            }

            if (freeHandle && !prepared)
            {
                FreeStatement();
            }

            return(records);
        }