コード例 #1
0
        public SqlReaderResult ExecuteReader(string query, params object[] sqlCommandParameters)
        {
            var coloumnNames = GetCommaSeparatedColumnNames(query);

            coloumnNames = CorrectWildcardColumnsIfNecessary(this, query, coloumnNames);

            var result = new SqlReaderResult(coloumnNames);

            using (var connection = new SqlConnection(connectionString))
            {
                var sqlParameterNames = GetParameterNames(query);
                using (var command = new SqlCommand(query, connection))
                {
                    AddParametersToSqlCommand(command, sqlParameterNames.ToArray(), sqlCommandParameters);
                    connection.Open();
                    command.CommandTimeout = CommandTimeout;
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            GetValues(reader, ref result);
                        }
                    }
                }
                connection.Close();
            }
            return(result);
        }
コード例 #2
0
        public static SqlReaderResult GetMockSqlReaderResult_Fix()
        {
            var result = new SqlReaderResult("name,value,type");

            result.AddRow(new object[] { "Név", "0", "Típus" }); // 0
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 1
            result.AddRow(new object[] { "Név", "0", "Típus" }); // 2
            result.AddRow(new object[] { "Név", "0", "Típus" }); // 3
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 4
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 5
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 6
            result.AddRow(new object[] { "Név", "0", "Típus" }); // 7
            result.AddRow(new object[] { "Név", "0", "Típus" }); // 8
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 9
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 10
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 11
            result.AddRow(new object[] { "Név", "0", "Típus" }); // 12
            result.AddRow(new object[] { "Név", "0", "Típus" }); // 13
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 14
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 15
            result.AddRow(new object[] { "Név", "0", "Típus" }); // 16
            result.AddRow(new object[] { "Név", "0", "Típus" }); // 17
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 18
            result.AddRow(new object[] { "Név", "0", "Típus" }); // 19
            result.AddRow(new object[] { "Név", "1", "Típus" }); // 20
            return(result);
        }
コード例 #3
0
        private static void GetValues(IDataRecord reader, ref SqlReaderResult result)
        {
            var values = new object[reader.FieldCount];

            reader.GetValues(values);
            for (var i = 0; i < values.Length; i++)
            {
                if (reader.IsDBNull(i))
                {
                    values[i] = null;
                }
            }
            result.AddRow(values);
        }
コード例 #4
0
        public static SqlReaderResult GetMockSqlReaderResult_AllSame()
        {
            var result = new SqlReaderResult("name,value,type");

            for (var i = 0; i < 100; i++)
            {
                var values = new object[3];
                values[0] = "Név";
                values[1] = "Érték";
                values[2] = "Típus";
                result.AddRow(values);
            }
            return(result);
        }
コード例 #5
0
        public static SqlReaderResult GetMockSqlReaderResult()
        {
            var result = new SqlReaderResult("name,value,type");

            var r = new Random();

            for (var i = 0; i < 100000; i++)
            {
                var values = new object[3];
                values[0] = "Név";
                values[1] = r.Next(0, 2).ToString();
                values[2] = "Típus";
                result.AddRow(values);
            }

            return(result);
        }
コード例 #6
0
        public static SqlReaderResult GetMockSqlReaderResult_Test()
        {
            var result = new SqlReaderResult("name,value,type");

            for (var i = 0; i < 10; i++)
            {
                var values = new object[3];
                values[0] = "Név";
                values[1] = "Érték";
                values[2] = "Típus";
                result.AddRow(values);
            }

            for (var i = 0; i < 10; i++)
            {
                var values = new object[3];
                values[0] = $"Név {i + 1}";
                values[1] = $"Érték {i}";
                values[2] = "Típus";
                result.AddRow(values);
            }

            for (var i = 0; i < 10; i++)
            {
                var values = new object[3];
                if (i % 2 == 0)
                {
                    values[0] = "Név";
                    values[1] = "Érték";
                    values[2] = "Típus";
                }
                else
                {
                    values[0] = "Név_2";
                    values[1] = "Érték_2";
                    values[2] = "Típus_2";
                }
                result.AddRow(values);
            }

            return(result);
        }
コード例 #7
0
        public SqlReaderResult[] ExecuteReaders(string query, params object[] sqlCommandParameters)
        {
            var coloumnNames = GetCommaSeparatedColumnNames(query);

            coloumnNames = CorrectWildcardColumnsIfNecessary(this, query, coloumnNames);

            var result = new List <SqlReaderResult>();

            using (var connection = new SqlConnection(connectionString))
            {
                var sqlParameterNames = GetParameterNames(query);
                using (var command = new SqlCommand(query, connection))
                {
                    AddParametersToSqlCommand(command, sqlParameterNames.ToArray(), sqlCommandParameters);
                    connection.Open();
                    command.CommandTimeout = CommandTimeout;
                    using (var reader = command.ExecuteReader())
                    {
                        do
                        {
                            SqlReaderResult subResult = null;
                            while (reader.Read())
                            {
                                if (subResult == null)
                                {
                                    subResult = new SqlReaderResult(coloumnNames);
                                }
                                GetValues(reader, ref subResult);
                            }
                            if (subResult != null)
                            {
                                result.Add(subResult);
                            }
                        } while (reader.NextResult());
                    }
                }
                connection.Close();
            }
            return(result.ToArray());
        }
コード例 #8
0
        public SqlReaderResult[] ExecuteStoredProcedure(string storedProcedure, params object[] sqlCommandNamesAndParameters)
        {
            object[] sqlCommandParameters = null;
            string[] sqlParameterNames    = null;
            if (sqlCommandNamesAndParameters != null)
            {
                if (sqlCommandNamesAndParameters.Length % 2 != 0)
                {
                    throw new ArgumentException("sqlCommandNamesAndParameters length must be even");
                }

                var length = sqlCommandNamesAndParameters.Length / 2;
                sqlParameterNames    = new string[length];
                sqlCommandParameters = new string[length];
                for (var i = 0; i < sqlCommandNamesAndParameters.Length; i += 2)
                {
                    if (sqlCommandNamesAndParameters[i].GetType() != typeof(string))
                    {
                        throw new ArgumentException("Each even parameter SQL command parameters must be a name with string type");
                    }

                    var j = i / 2;
                    sqlParameterNames[j]    = sqlCommandNamesAndParameters[i].ToString();
                    sqlCommandParameters[j] = sqlCommandNamesAndParameters[i + 1];
                }
            }

            var result = new List <SqlReaderResult>();

            using (var connection = new SqlConnection(connectionString))
            {
                using (var command = new SqlCommand(storedProcedure, connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    AddParametersToSqlCommand(command, sqlParameterNames, sqlCommandParameters);
                    connection.Open();
                    command.CommandTimeout = CommandTimeout;
                    using (var reader = command.ExecuteReader())
                    {
                        do
                        {
                            SqlReaderResult subResult = null;
                            while (reader.Read())
                            {
                                if (subResult == null)
                                {
                                    subResult = new SqlReaderResult();
                                }
                                GetValues(reader, ref subResult);
                            }
                            if (subResult != null)
                            {
                                result.Add(subResult);
                            }
                        }while (reader.NextResult());
                    }
                }
                connection.Close();
            }
            return(result.ToArray());
        }