コード例 #1
0
        /// <summary>
        /// Constructs a new <c>HsqlCommand</c> instance that
        /// is a copy of the given command object.
        /// </summary>
        /// <param name="srcCommand">The source command.</param>
        private HsqlCommand(HsqlCommand srcCommand) : this()
        {
            m_commandTextHasParameters
                = srcCommand.m_commandTextHasParameters;

            if (srcCommand.m_commandTextHasParameters &&
                (srcCommand.m_tokenList != null))
            {
                m_tokenList = srcCommand.m_tokenList.Clone();
            }

            this.CommandText       = srcCommand.CommandText;
            this.CommandTimeout    = srcCommand.CommandTimeout;
            this.CommandType       = srcCommand.CommandType;
            this.Connection        = srcCommand.Connection;
            this.DesignTimeVisible = srcCommand.DesignTimeVisible;
            this.Transaction       = srcCommand.Transaction; // CHECKME
            this.UpdatedRowSource  = srcCommand.UpdatedRowSource;

            HsqlParameterCollection parameters = this.Parameters;

            foreach (HsqlParameter parameter in srcCommand.Parameters)
            {
                parameters.Add(parameter.Clone());
            }
        }
コード例 #2
0
ファイル: HsqlDataAdapter.cs プロジェクト: svn2github/hsqldb
        /// <summary>
        /// Initializes batching.
        /// </summary>
        protected override void InitializeBatching()
        {
            m_commandSet = new HsqlCommandSet();

            HsqlCommand command = SelectCommand;

            if (command == null)
            {
                command = InsertCommand;

                if (command == null)
                {
                    command = UpdateCommand;

                    if (command == null)
                    {
                        command = DeleteCommand;
                    }
                }
            }

            if (command != null)
            {
                m_commandSet.Connection     = command.Connection;
                m_commandSet.Transaction    = command.Transaction;
                m_commandSet.CommandTimeout = command.CommandTimeout;
            }
        }
コード例 #3
0
        /// <summary>
        /// Determines parameter information for the given <see cref="HsqlCommand"/>
        /// and populates its <c>Parameters</c> collection correspondingly.
        /// </summary>
        /// <param name="command">
        /// The <see cref="HsqlCommand"/> for which the parameter information is
        /// to be derived. The derived parameters are added to its <c>Parameters</c>
        /// collection.
        /// </param>
        public static void DeriveParameters(HsqlCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            command.DeriveParameters();
        }
コード例 #4
0
ファイル: HsqlDataReader.cs プロジェクト: svn2github/hsqldb
 public HsqlDataReader(
     org.hsqldb.Result result,
     CommandBehavior commandBehavior,
     HsqlCommand originatingCommand,
     HsqlConnection originatingConnection)
     : this(result)
 {
     m_commandBehavior       = commandBehavior;
     m_originatingCommand    = originatingCommand;
     m_originatingConnection = originatingConnection;
 }
コード例 #5
0
        /// <summary>
        /// Computes and returns the supported command type given a stipulated command type and command object.
        /// </summary>
        /// <remarks>
        /// If the returned type does not match the stipulated type,
        /// a warning event is raised on the given command object.
        /// </remarks>
        /// <param name="commandType">Type of the command.</param>
        /// <param name="command">The command.</param>
        /// <returns>the supported command type</returns>
        private static CommandType ToSupportedCommandType(CommandType commandType, HsqlCommand command)
        {
            switch (commandType)
            {
            case CommandType.StoredProcedure:
            case CommandType.TableDirect:
            case CommandType.Text:
            {
                return(commandType);
            }

            default:
            {
                ArgumentException ex = new ArgumentException(
                    "commandType", string.Format(
                        "[{0}] is not a valid command type", commandType));
                HsqlDataSourceException hex = new HsqlDataSourceException("Warning.", ex);

                command.OnWarning(new HsqlWarningEventArgs(hex));

                return(CommandType.Text);
            }
            }
        }
コード例 #6
0
 public HsqlDataReader(
     org.hsqldb.Result result,
     CommandBehavior commandBehavior,
     HsqlCommand originatingCommand,
     HsqlConnection originatingConnection)
     : this(result)
 {
     m_commandBehavior = commandBehavior;
     m_originatingCommand = originatingCommand;
     m_originatingConnection = originatingConnection;
 }
コード例 #7
0
ファイル: HsqlDataAdapter.cs プロジェクト: svn2github/hsqldb
 /// <summary>
 /// Initializes a new instance of the <see cref="HsqlDataAdapter"/> class
 /// with an SQL SELECT statement and an <see cref="HsqlConnection"/>.
 /// </summary>
 /// <param name="selectCommandText">
 /// The string representation of the SQL SELECT statement or stored procedure
 /// to be executed by the <see cref="SelectCommand"/> property of this object.
 /// </param>
 /// <param name="selectConnection">The select connection.</param>
 public HsqlDataAdapter(string selectCommandText, HsqlConnection selectConnection)
     : this()
 {
     SelectCommand = new HsqlCommand(selectConnection, selectCommandText);
 }
コード例 #8
0
ファイル: HsqlDataAdapter.cs プロジェクト: svn2github/hsqldb
        /// <summary>
        /// Initializes a new instance of the <see cref="HsqlDataAdapter"/> class
        /// with an SQL SELECT statement and a connection string.
        /// </summary>
        /// <param name="selectCommandText">
        /// The string representation of the SQL SELECT statement or stored procedure
        /// to be executed by the <see cref="SelectCommand"/> property of this object.
        /// </param>
        /// <param name="selectConnectionString">
        /// The connection string used to obtain the connection object on which the
        /// <see cref="SelectCommand"/> property of this object executes.
        /// </param>
        public HsqlDataAdapter(string selectCommandText, string selectConnectionString)
        {
            HsqlConnection connection = new HsqlConnection(selectConnectionString);

            SelectCommand = new HsqlCommand(connection, selectCommandText);
        }
コード例 #9
0
        /// <summary>
        /// Constructs a new <c>HsqlCommand</c> instance that
        /// is a copy of the given command object.
        /// </summary>
        /// <param name="srcCommand">The source command.</param>
        private HsqlCommand(HsqlCommand srcCommand)
            : this()
        {
            m_commandTextHasParameters
                = srcCommand.m_commandTextHasParameters;

            if (srcCommand.m_commandTextHasParameters &&
                (srcCommand.m_tokenList != null))
            {
                m_tokenList = srcCommand.m_tokenList.Clone();
            }

            this.CommandText = srcCommand.CommandText;
            this.CommandTimeout = srcCommand.CommandTimeout;
            this.CommandType = srcCommand.CommandType;
            this.Connection = srcCommand.Connection;
            this.DesignTimeVisible = srcCommand.DesignTimeVisible;
            this.Transaction = srcCommand.Transaction; // CHECKME
            this.UpdatedRowSource = srcCommand.UpdatedRowSource;

            HsqlParameterCollection parameters = this.Parameters;

            foreach (HsqlParameter parameter in srcCommand.Parameters)
            {
                parameters.Add(parameter.Clone());
            }
        }
コード例 #10
0
ファイル: HsqlDataAdapter.cs プロジェクト: svn2github/hsqldb
 /// <summary>
 /// Initializes a new instance of the <see cref="HsqlDataAdapter"/>
 /// class with a command object representing an SQL SELECT statement.
 /// </summary>
 /// <param name="selectCommand">
 /// An <see cref="HsqlCommand"/> representing the SQL SELECT statement or
 /// stored procedure executed by the <see cref="SelectCommand"/> property
 /// of this object.
 /// </param>
 public HsqlDataAdapter(HsqlCommand selectCommand) : this()
 {
     this.SelectCommand = selectCommand;
 }
コード例 #11
0
        /// <summary>
        /// Returns the collection of currently valid initial schema names, 
        /// given the specified context.
        /// </summary>
        /// <param name="context">
        /// An <see cref="ITypeDescriptorContext"></see> whose <c>Instance</c> 
        /// property supplies the <c>HsqlConnectionStringBuilder</c> use to 
        /// connect to a data source to retrieve the currently valid initial 
        /// schema names.
        /// </param>
        /// <returns>
        /// A <see cref="TypeConverter.StandardValuesCollection"/> that holds 
        /// collection of currently valid initial schema names.
        /// </returns>
        public override TypeConverter.StandardValuesCollection GetStandardValues(
            ITypeDescriptorContext context)
        {
            if (!IsStandardValuesSupported(context))
            {
                return null;
            }

            List<string> values = new List<string>();

            try
            {
                HsqlConnectionStringBuilder builder
                    = (HsqlConnectionStringBuilder)context.Instance;

                // TODO:  this is sub-optimal, but is currently the best (only?)
                // solution to the problem of how to avoid creating and/or
                // leaving open embedded database instances.
                if (IsEmbeddedProtocol(builder))
                {
                    builder = new HsqlConnectionStringBuilder(
                        builder.ConnectionString);

                    builder.AutoShutdown = true;
                    builder.IfExists = true;
                }

                using (HsqlConnection connection = new HsqlConnection())
                {
                    connection.ConnectionString = builder.ConnectionString;

                    using (HsqlCommand command = new HsqlCommand(
                        connection,
                        SchemaQuery))
                    {
                        connection.Open();

                        using (HsqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                values.Add(reader.GetString(0));
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
            #if DEBUG
                Debug.WriteLine(exception);
            #endif
            }

            return new TypeConverter.StandardValuesCollection(values);
        }
コード例 #12
0
        /// <summary>
        /// Computes and returns the supported command type given a stipulated command type and command object.
        /// </summary>
        /// <remarks>
        /// If the returned type does not match the stipulated type,
        /// a warning event is raised on the given command object. 
        /// </remarks>
        /// <param name="commandType">Type of the command.</param>
        /// <param name="command">The command.</param>
        /// <returns>the supported command type</returns>
        private static CommandType ToSupportedCommandType(CommandType commandType, HsqlCommand command)
        {
            switch (commandType)
            {
                case CommandType.StoredProcedure:
                case CommandType.TableDirect:
                case CommandType.Text:
                    {
                        return commandType;
                    }
                default:
                    {
                        ArgumentException ex = new ArgumentException(
                            "commandType", string.Format(
                            "[{0}] is not a valid command type", commandType));
                        HsqlDataSourceException hex = new HsqlDataSourceException("Warning.", ex);

                        command.OnWarning(new HsqlWarningEventArgs(hex));

                        return CommandType.Text;
                    }
            }
        }
コード例 #13
0
        /// <summary>
        /// Provides the core logic for the
        /// <see cref="ExecuteReader(CommandBehavior)"/> method.
        /// </summary>
        /// <param name="behavior">The requested behavior.</param>
        /// <returns>
        /// The result generated by executing the query.
        /// </returns>
        internal HsqlDataReader ExecuteReaderInternal(CommandBehavior behavior)
        {
            if (Behavior.IsSchemaOnly(behavior))
            {
                bool wasAlreadyPrepared = IsPrepared;

                if (!wasAlreadyPrepared)
                {
                    Prepare(); // already correctly locked.
                }

                Result         descriptor            = m_statement.ResultDescriptor;
                HsqlCommand    originatingCommand    = this;
                HsqlConnection originatingConnection = m_dbConnection;

                HsqlDataReader reader0 = new HsqlDataReader(descriptor, behavior,
                                                            originatingCommand, originatingConnection);

                if (Behavior.IsKeyInfo(behavior))
                {
                    // Do it now, so that it does not fail later if
                    // originating connection is closed before first
                    // client invocation of reader.GetSchemaTable().
                    reader0.GetSchemaTable();
                }

                if (!wasAlreadyPrepared)
                {
                    UnPrepare();
                }

                return(reader0);
            }

            Result result;

            int maxRows = (Behavior.IsSingleRow(behavior)) ? 1 : 0;

            if (IsPrepared)
            {
                ApplyParameters();

                HsqlSession session = Session;

                session.MaxRows = maxRows;

                result = m_statement.Execute(session);
            }
            else
            {
                HsqlSession session = Session;

                session.MaxRows = maxRows;

                result = session.ExecuteDirect(StaticallyBoundCommandText);
            }

            HsqlDataReader reader = new HsqlDataReader(result, behavior, this,
                                                       this.m_dbConnection);

            if (Behavior.IsKeyInfo(behavior))
            {
                // Do it now, so that it does not fail later if
                // originating connection is closed before first
                // client invocation of reader.GetSchemaTable().
                reader.GetSchemaTable();
            }

            return(reader);
        }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HsqlDataAdapter"/> class
        /// with an SQL SELECT statement and a connection string.
        /// </summary>
        /// <param name="selectCommandText">
        /// The string representation of the SQL SELECT statement or stored procedure
        /// to be executed by the <see cref="SelectCommand"/> property of this object.
        /// </param>
        /// <param name="selectConnectionString">
        /// The connection string used to obtain the connection object on which the
        /// <see cref="SelectCommand"/> property of this object executes.
        /// </param>
        public HsqlDataAdapter(string selectCommandText, string selectConnectionString)        
        {
            HsqlConnection connection = new HsqlConnection(selectConnectionString);
            SelectCommand = new HsqlCommand(connection, selectCommandText);

        }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HsqlDataAdapter"/> class
 /// with an SQL SELECT statement and an <see cref="HsqlConnection"/>.
 /// </summary>
 /// <param name="selectCommandText">
 /// The string representation of the SQL SELECT statement or stored procedure
 /// to be executed by the <see cref="SelectCommand"/> property of this object.
 /// </param>
 /// <param name="selectConnection">The select connection.</param>
 public HsqlDataAdapter(string selectCommandText, HsqlConnection selectConnection)
     : this()
 {
     SelectCommand = new HsqlCommand(selectConnection, selectCommandText);
 }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HsqlDataAdapter"/> 
 /// class with a command object representing an SQL SELECT statement.
 /// </summary>
 /// <param name="selectCommand">
 /// An <see cref="HsqlCommand"/> representing the SQL SELECT statement or
 /// stored procedure executed by the <see cref="SelectCommand"/> property
 /// of this object.
 /// </param>
 public HsqlDataAdapter(HsqlCommand selectCommand) : this()
 {
     this.SelectCommand = selectCommand;
 }
コード例 #17
0
        /// <summary>
        /// Determines parameter information for the given <see cref="HsqlCommand"/>
        /// and populates its <c>Parameters</c> collection correspondingly.
        /// </summary>
        /// <param name="command">
        /// The <see cref="HsqlCommand"/> for which the parameter information is
        /// to be derived. The derived parameters are added to its <c>Parameters</c>
        /// collection.
        /// </param>
        public static void DeriveParameters(HsqlCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            command.DeriveParameters();
        }