Example #1
0
        /// <summary>
        /// Converts all results encapsulated by the given
        /// <see cref="HsqlDataReader"/> to a snapshot form
        /// suitable for long term persistence or network
        /// transmission.
        /// </summary>
        /// <remarks>
        /// The returned <c>System.Byte[]</c> can be converted
        /// back into a data reader using <see cref="FromByteArray(Byte[])"/>.
        /// </remarks>
        /// <param name="reader">
        /// To convert to a <c>Byte[]</c> value.
        /// </param>
        /// <returns>
        /// A new <c>System.Byte[]</c>
        /// </returns>
        public static byte[] ToByteArray(HsqlDataReader reader)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                WriteToStream(stream, reader);

                return(stream.ToArray());
            }
        }
        /// <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;
        }
 /// <summary>
 /// Writes all results encapsulated by the given 
 /// <see cref="HsqlDataReader"/> to a snapshot form
 /// suitable for long term persistence or network
 /// transmission.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="reader">The reader.</param>
 public static void WriteToStream(Stream stream, HsqlDataReader reader)
 {
     WriteResult(stream, reader.m_result);
 }
        /// <summary>
        /// Converts all results encapsulated by the given 
        /// <see cref="HsqlDataReader"/> to a snapshot form
        /// suitable for long term persistence or network
        /// transmission.
        /// </summary>
        /// <remarks>
        /// The returned <c>System.Byte[]</c> can be converted
        /// back into a data reader using <see cref="FromByteArray(Byte[])"/>.
        /// </remarks>
        /// <param name="reader">
        /// To convert to a <c>Byte[]</c> value.
        /// </param>
        /// <returns>
        /// A new <c>System.Byte[]</c>
        /// </returns>
        public static byte[] ToByteArray(HsqlDataReader reader)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                WriteToStream(stream, reader);

                return stream.ToArray();
            }
        }
Example #5
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);
        }
Example #6
0
 /// <summary>
 /// Writes all results encapsulated by the given
 /// <see cref="HsqlDataReader"/> to a snapshot form
 /// suitable for long term persistence or network
 /// transmission.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="reader">The reader.</param>
 public static void WriteToStream(Stream stream, HsqlDataReader reader)
 {
     WriteResult(stream, reader.m_result);
 }