Пример #1
0
        public void TestResultTableLoad()
        {
            var table = new ResultTable();

            var selectSql = @"SELECT * FROM TT ;";

            using (var cmd = new MySqlCommand(selectSql, dbConn))
            {
                using (var dbReader = cmd.ExecuteReader())
                {
                    table.Load(dbReader);
                }
            }

            Assert.Equal("a", table.Columns[0].ColumnName);
            Assert.Equal("b", table.Columns[1].ColumnName);
            Assert.Equal("c", table.Columns[2].ColumnName);

            Assert.Equal(typeof(int), table.Columns[0].DataType);
            Assert.Equal(typeof(string), table.Columns[1].DataType);
            Assert.Equal(typeof(double), table.Columns[2].DataType);

            Assert.Equal(100, table.Columns[1].MaxLength);

            Assert.Equal("data", table.Rows[2][1]);
            Assert.Equal(4, table.Rows.Count);
        }
Пример #2
0
        public async Task GetAllUserSecretsAsync(HttpContext Context)
        {
            try
            {
                SqlConnection.Open();
                SqlCommand command = new SqlCommand()
                {
                    Connection  = SqlConnection,
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "[Store].[ReturnAllUserSecrets]"
                };

                if (Context.Request.Query.TryGetValue("StoreUsername", out var StoreUsername))
                {
                    command.Parameters.AddWithValue("@StoreUsername", StoreUsername.ToString());
                }

                SqlDataReader reader = await command.ExecuteReaderAsync().ConfigureAwait(false);

                if (reader.HasRows)
                {
                    ResultTable.Load(reader);
                }

                await reader.CloseAsync().ConfigureAwait(false);

                await reader.DisposeAsync().ConfigureAwait(false);

                await command.DisposeAsync().ConfigureAwait(false);

                await SqlConnection.CloseAsync().ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                if (SqlConnection.State.Equals("Open"))
                {
                    SqlConnection.Close();
                }

                DictionaryLog.Add("Exception", exception.HResult);
                DictionaryLog.Add("Exception Message", exception.Message);
            }
        }
Пример #3
0
        public async Task DeleteStoreSecretAsync(EntryTypes EntryType, HttpContext Context)
        {
            try
            {
                SqlConnection.Open();
                SqlCommand command = new SqlCommand()
                {
                    Connection  = SqlConnection,
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "[Store].[DeleteStoreSecret]"
                };

                command.Parameters.AddWithValue("@EntryType", EntryType.GetHashCode());
                command.Parameters.AddRange(QueryParameters(Context));

                SqlDataReader reader = await command.ExecuteReaderAsync().ConfigureAwait(false);

                if (reader.HasRows)
                {
                    ResultTable.Load(reader);
                }

                await reader.CloseAsync().ConfigureAwait(false);

                await reader.DisposeAsync().ConfigureAwait(false);

                await command.DisposeAsync().ConfigureAwait(false);

                await SqlConnection.CloseAsync().ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                if (SqlConnection.State.Equals("Open"))
                {
                    await SqlConnection.CloseAsync();
                }

                DictionaryLog.Add("Exception", exception.HResult);
                DictionaryLog.Add("Exception Message", exception.Message);
            }
        }