Exemplo n.º 1
0
 internal void CloseServerCursor(int ACursorHandle)
 {
     ClearParameters();
     InternalParameterCreate("@cursor", SqlDbType.Int, ParameterDirection.Input).Value = ACursorHandle;
     FCommand.CommandText = "sp_cursorclose";
     FCommand.ExecuteNonQuery();
 }
Exemplo n.º 2
0
        protected override SQLCursor InternalOpen(SQLCursorType ACursorType, SQLIsolationLevel AIsolationLevel)
        {
            // Prepare the connection
            SQLCursorLocation LLocation = GetCursorLocation();

            if (LLocation == SQLCursorLocation.Server)
            {
                PrepareServerCursorCommand(ACursorType, AIsolationLevel);
            }
            else
            {
                PrepareCommand(false, AIsolationLevel);
            }

            // Set the non-internal parameters
            SetParameters();

            // Open the reader
            IDataReader LCursor = FCommand.ExecuteReader(SQLCommandBehaviorToCommandBehavior(CommandBehavior));

            // Return the appropriate cursor
            if (LLocation == SQLCursorLocation.Server)
            {
                return(new MSSQLServerCursor(this, LCursor));
            }
            else
            {
                return(new DotNetCursor(this, LCursor));
            }
        }
Exemplo n.º 3
0
 internal IDataReader FetchServerCursor(int ACursorHandle)
 {
     ClearParameters();
     InternalParameterCreate("@retval", SqlDbType.Int, ParameterDirection.ReturnValue);
     InternalParameterCreate("@cursor", SqlDbType.Int, ParameterDirection.Input).Value    = ACursorHandle;
     InternalParameterCreate("@fetchtype", SqlDbType.Int, ParameterDirection.Input).Value = 0x0002 /* next */;
     InternalParameterCreate("@rownum", SqlDbType.Int, ParameterDirection.Input).Value    = 0;
     InternalParameterCreate("@nrows", SqlDbType.Int, ParameterDirection.Input).Value     = FetchCount;
     FCommand.CommandText = "sp_cursorfetch";
     return(FCommand.ExecuteReader(SQLCommandBehaviorToCommandBehavior(CommandBehavior)));
 }
Exemplo n.º 4
0
        /// <summary> Creates an internal parameter. </summary>
        /// <remarks> Internal parameters are only part of the provider's parameter space.  They are used as part of the sp_cursor calls. </remarks>
        internal SqlParameter InternalParameterCreate(string AName, SqlDbType AType, ParameterDirection ADirection)
        {
            SqlParameter LParameter = (SqlParameter)FCommand.CreateParameter();

            LParameter.ParameterName = AName;
            LParameter.SqlDbType     = AType;
            LParameter.Direction     = ADirection;
            FCommand.Parameters.Add(LParameter);
            FInternalParameterCount++;
            return(LParameter);
        }
Exemplo n.º 5
0
        public void Execute_MovesRobotOneStepForward(Orientation orientation, int x, int y)
        {
            // Arrange
            IRobot robot = A.Fake <IRobot>();

            robot.LastPosition = Position.Origin;
            robot.Orientation  = orientation;

            FCommand sut = new FCommand(robot);

            // Act
            sut.Execute();

            // Assert
            robot.Orientation.Should().Be(orientation);
            robot.LastPosition.Should().Be(new Position(x, y));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Метод создаёт прогноз по заданному узлу на заданную дату.
        /// </summary>
        /// <param name="connection">строка соединения Сервером Прогнозов</param>
        /// <param name="type">Тип прогноза</param>
        /// <param name="obj">Узел учёта</param>
        /// <param name="date">Дата прогноза</param>
        /// <returns>Возвращает номер документа в виде <c>int</c></returns>
        public int CreateDocument(string connection, string type, string obj, DateTime date)
        {
            FConnection conn = new FConnection(connection);
            FCommand    cmd  = new FCommand(string.Format("{0} {1:yyyy-MM-dd} {2}", obj, date, type), conn);

            conn.Open();
            string result = cmd.Execute();

            conn.Close();

            int r = 0;

            if (!int.TryParse(result, out r))
            {
                throw new Exception(result);
            }
            return(r);
        }
Exemplo n.º 7
0
 protected override void Dispose(bool ADisposing)
 {
     try
     {
         if (FCommand != null)
         {
             try
             {
                 FCommand.SetActiveCursor(null);
                 FCommand.InternalClose();
             }
             finally
             {
                 FCommand = null;
             }
         }
     }
     finally
     {
         base.Dispose(ADisposing);
     }
 }
Exemplo n.º 8
0
        private void btnForecastTest_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                FConnection conn = new FConnection(txtForecastServer.Text);
                FCommand    cmd  = new FCommand("test", conn);
                conn.Open();
                string response = cmd.Execute();
                conn.Close();

                if (response == "done")
                {
                    MessageBox.Show("Соединение с сервером прогнозов успешно установлено.", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Соединение с сервером пронозов установить не удалось.", "Информация", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(string.Format("Возникла ошибка при попытке соединиться с Сервером Прогнозов.\n {0}", exception.Message), "Информация", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 9
0
        protected override void PrepareParameters()
        {
            // Prepare parameters
            SQLParameter LParameter;

            for (int LIndex = 0; LIndex < FParameterIndexes.Length; LIndex++)
            {
                LParameter = Parameters[FParameterIndexes[LIndex]];
                OdbcParameter LODBCParameter = (OdbcParameter)FCommand.CreateParameter();
                LODBCParameter.ParameterName = String.Format("@{0}", LParameter.Name);
                switch (LParameter.Direction)
                {
                case SQLDirection.Out: LODBCParameter.Direction = System.Data.ParameterDirection.Output; break;

                case SQLDirection.InOut: LODBCParameter.Direction = System.Data.ParameterDirection.InputOutput; break;

                case SQLDirection.Result: LODBCParameter.Direction = System.Data.ParameterDirection.ReturnValue; break;

                default: LODBCParameter.Direction = System.Data.ParameterDirection.Input; break;
                }

                if (LParameter.Type is SQLStringType)
                {
                    LODBCParameter.OdbcType = OdbcType.VarChar;
                    LODBCParameter.Size     = ((SQLStringType)LParameter.Type).Length;
                }
                else if (LParameter.Type is SQLBooleanType)
                {
                    LODBCParameter.OdbcType = OdbcType.Bit;
                }
                else if (LParameter.Type is SQLIntegerType)
                {
                    switch (((SQLIntegerType)LParameter.Type).ByteCount)
                    {
                    case 1: LODBCParameter.OdbcType = OdbcType.TinyInt; break;

                    case 2: LODBCParameter.OdbcType = OdbcType.SmallInt; break;

                    case 8: LODBCParameter.OdbcType = OdbcType.BigInt; break;

                    default: LODBCParameter.OdbcType = OdbcType.Int; break;
                    }
                }
                else if (LParameter.Type is SQLNumericType)
                {
                    SQLNumericType LType = (SQLNumericType)LParameter.Type;
                    LODBCParameter.OdbcType  = OdbcType.Int;                    // could not be decimal because of issue with DB2/400
                    LODBCParameter.Scale     = LType.Scale;
                    LODBCParameter.Precision = LType.Precision;
                }
                else if (LParameter.Type is SQLBinaryType)
                {
                    LODBCParameter.OdbcType = OdbcType.Image;
                }
                else if (LParameter.Type is SQLTextType)
                {
                    LODBCParameter.OdbcType = OdbcType.Text;
                }
                else if (LParameter.Type is SQLDateTimeType)
                {
                    LODBCParameter.OdbcType = OdbcType.DateTime;
                }
                else if (LParameter.Type is SQLDateType)
                {
                    LODBCParameter.OdbcType = OdbcType.DateTime;
                }
                else if (LParameter.Type is SQLTimeType)
                {
                    LODBCParameter.OdbcType = OdbcType.DateTime;
                }
                else if (LParameter.Type is SQLGuidType)
                {
                    LODBCParameter.OdbcType = OdbcType.UniqueIdentifier;
                }
                else if (LParameter.Type is SQLMoneyType)
                {
                    LODBCParameter.OdbcType  = OdbcType.Decimal;
                    LODBCParameter.Scale     = 28;
                    LODBCParameter.Precision = 8;
                }
                else
                {
                    throw new ConnectionException(ConnectionException.Codes.UnknownSQLDataType, LParameter.Type.GetType().Name);
                }
                FCommand.Parameters.Add(LODBCParameter);
            }
        }
Exemplo n.º 10
0
        /// <summary> Creates non-internal parameters on the provider. </summary>
        protected override void PrepareParameters()
        {
            // Prepare parameters
            for (int LIndex = 0; LIndex < FParameterIndexes.Length; LIndex++)
            {
                SQLParameter LParameter      = Parameters[FParameterIndexes[LIndex]];
                SqlParameter LMSSQLParameter = (SqlParameter)FCommand.CreateParameter();
                LMSSQLParameter.ParameterName = String.Format("@{0}", ConvertParameterName(LParameter.Name));
                switch (LParameter.Direction)
                {
                case SQLDirection.Out:
                    LMSSQLParameter.Direction = System.Data.ParameterDirection.Output;
                    break;

                case SQLDirection.InOut:
                    LMSSQLParameter.Direction = System.Data.ParameterDirection.InputOutput;
                    break;

                case SQLDirection.Result:
                    LMSSQLParameter.Direction = System.Data.ParameterDirection.ReturnValue;
                    break;

                default:
                    LMSSQLParameter.Direction = System.Data.ParameterDirection.Input;
                    break;
                }

                if (LParameter.Type is SQLStringType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.VarChar;
                    LMSSQLParameter.Size      = ((SQLStringType)LParameter.Type).Length;
                }
                else if (LParameter.Type is SQLBooleanType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.Bit;
                }
                else if (LParameter.Type is SQLByteArrayType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.Binary;
                    LMSSQLParameter.Size      = ((SQLByteArrayType)LParameter.Type).Length;
                }
                else if (LParameter.Type is SQLIntegerType)
                {
                    switch (((SQLIntegerType)LParameter.Type).ByteCount)
                    {
                    case 1:
                        LMSSQLParameter.SqlDbType = SqlDbType.TinyInt;
                        break;

                    case 2:
                        LMSSQLParameter.SqlDbType = SqlDbType.SmallInt;
                        break;

                    case 8:
                        LMSSQLParameter.SqlDbType = SqlDbType.BigInt;
                        break;

                    default:
                        LMSSQLParameter.SqlDbType = SqlDbType.Int;
                        break;
                    }
                }
                else if (LParameter.Type is SQLNumericType)
                {
                    SQLNumericType LType = (SQLNumericType)LParameter.Type;
                    LMSSQLParameter.SqlDbType = SqlDbType.Decimal;
                    LMSSQLParameter.Scale     = LType.Scale;
                    LMSSQLParameter.Precision = LType.Precision;
                }
                else if (LParameter.Type is SQLFloatType)
                {
                    SQLFloatType LType = (SQLFloatType)LParameter.Type;
                    if (LType.Width == 1)
                    {
                        LMSSQLParameter.SqlDbType = SqlDbType.Real;
                    }
                    else
                    {
                        LMSSQLParameter.SqlDbType = SqlDbType.Float;
                    }
                }
                else if (LParameter.Type is SQLBinaryType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.Image;
                }
                else if (LParameter.Type is SQLTextType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.Text;
                }
                else if (LParameter.Type is SQLDateType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.DateTime;
                }
                else if (LParameter.Type is SQLTimeType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.DateTime;
                }
                else if (LParameter.Type is SQLDateTimeType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.DateTime;
                }
                else if (LParameter.Type is SQLGuidType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.UniqueIdentifier;
                }
                else if (LParameter.Type is SQLMoneyType)
                {
                    LMSSQLParameter.SqlDbType = SqlDbType.Money;
                }
                else
                {
                    throw new ConnectionException(ConnectionException.Codes.UnknownSQLDataType, LParameter.Type.GetType().Name);
                }
                FCommand.Parameters.Add(LMSSQLParameter);
            }
        }