Example #1
0
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            string trimmedSql = CommandText.TrimStart(null);

            if (CommandType == CommandType.Text &&
                !trimmedSql.StartsWith("SELECT ", StringComparison.InvariantCultureIgnoreCase) &&
                !trimmedSql.StartsWith("CALL ", StringComparison.InvariantCultureIgnoreCase) &&
                !trimmedSql.StartsWith("EXECUTE ", StringComparison.InvariantCultureIgnoreCase))
            {
#if DEBUG
                System.Diagnostics.Trace.WriteLine("The statement is not a SELECT: redirecting to ExecuteNonQuery");
#endif
                // If the command was already prepared, it will be prepared again, in order to enable the generatingKeys option
                int             count  = ExecuteUpdate(true);
                NuoDbDataReader reader = generatedKeys != null ? generatedKeys : new NuoDbDataReader(connection, -1, null, this, false);
                reader.UpdatedRecords = count;
                return(reader);
            }
#if DEBUG
            System.Diagnostics.Trace.WriteLine("NuoDbCommand.ExecuteDbDataReader(" + CommandText + ", " + behavior + ")");
#endif
            checkConnection();
            EnsureStatement(false);

            EncodedDataStream dataStream = new RemEncodedStream(connection.InternalConnection.protocolVersion);
            if (CommandType == CommandType.StoredProcedure)
            {
                InvokeStoredProcedure(false);
                dataStream.startMessage(Protocol.GetResultSet);
                dataStream.encodeInt(handle);
                connection.InternalConnection.sendAndReceive(dataStream);
                return(createResultSet(dataStream, true));
            }


            bool readColumnNames = true;
            if (isPrepared)
            {
                dataStream.startMessage(Protocol.ExecutePreparedQuery);
                dataStream.encodeInt(handle);
                putParameters(dataStream);

                if (connection.InternalConnection.protocolVersion >= Protocol.PROTOCOL_VERSION8)
                {
                    /* if (columnNames != null)
                     * {
                     *  dataStream.encodeInt(Protocol.SkipColumnNames);
                     *  readColumnNames = false;
                     * }
                     * else */
                    {
                        dataStream.encodeInt(Protocol.SendColumnNames);
                    }
                }
            }
            else
            {
                dataStream.startMessage(Protocol.ExecuteQuery);
                dataStream.encodeInt(handle);
                dataStream.encodeString(CommandText);
            }
            connection.InternalConnection.sendAndReceive(dataStream);
            return(createResultSet(dataStream, readColumnNames));
        }