Exemplo n.º 1
0
        static async Task Main(string[] args)
        {
            try
            {
                using var connection = new ClickHouseConnection(GetConnectionString(args));

                await connection.ExecuteStatementAsync("CREATE DATABASE IF NOT EXISTS test");

                await connection.ExecuteStatementAsync("TRUNCATE TABLE IF EXISTS test.dotnet_test");

                await connection.ExecuteStatementAsync("CREATE TABLE IF NOT EXISTS test.dotnet_test (`age` Int32, `name` String) Engine = Memory");

                using var command = connection.CreateCommand();
                command.AddParameter("name", "Linus Torvalds");
                command.AddParameter("age", 51);
                command.CommandText = "INSERT INTO test.dotnet_test VALUES({age:Int32}, {name:String})";
                await command.ExecuteNonQueryAsync();

                using var result1 = await connection.ExecuteReaderAsync("SELECT * FROM test.dotnet_test");

                while (result1.Read())
                {
                    var values = new object[result1.FieldCount];
                    result1.GetValues(values);

                    foreach (var row in values)
                    {
                        Console.WriteLine(row);
                    }
                }

                using var result2 = await connection.ExecuteReaderAsync(selectSql);

                while (result2.Read())
                {
                    var values = new object[result2.FieldCount];
                    result2.GetValues(values);

                    foreach (var row in values)
                    {
                        Console.WriteLine(row);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                Environment.ExitCode = 1;
            }
        }
        public async Task ShouldInsertParameterizedArray()
        {
            await connection.ExecuteStatementAsync("TRUNCATE TABLE IF EXISTS test.float_array");

            await connection.ExecuteStatementAsync("CREATE TABLE IF NOT EXISTS test.float_array (arr Array(Float64)) ENGINE Memory");

            var command = connection.CreateCommand();

            command.AddParameter("values", new[] { 1.0, 2.0, 3.0 });
            command.CommandText = "INSERT INTO test.float_array VALUES ({values:Array(Float32)})";
            await command.ExecuteNonQueryAsync();

            var count = await connection.ExecuteScalarAsync("SELECT COUNT(*) FROM test.float_array");

            Assert.AreEqual(1, count);
        }
Exemplo n.º 3
0
        public async Task ShouldExecuteSingleValueInsertViaBulkCopy(string clickHouseType, object insertedValue)
        {
            var targetTable = SanitizeTableName($"test.b_{clickHouseType}");

            await connection.ExecuteStatementAsync($"TRUNCATE TABLE IF EXISTS {targetTable}");

            await connection.ExecuteStatementAsync($"CREATE TABLE IF NOT EXISTS {targetTable} (value {clickHouseType}) ENGINE Memory");

            using var bulkCopy = new ClickHouseBulkCopy(connection)
                  {
                      DestinationTableName = targetTable
                  };

            await bulkCopy.WriteToServerAsync(Enumerable.Repeat(new[] { insertedValue }, 1));

            using var reader = await connection.ExecuteReaderAsync($"SELECT * from {targetTable}");

            Assert.IsTrue(reader.Read(), "Cannot read inserted data");
            reader.AssertHasFieldCount(1);
            var data = reader.GetValue(0);

            Assert.AreEqual(insertedValue, data);
        }
        public async Task Setup()
        {
            await connection.ExecuteStatementAsync($"DROP DATABASE IF EXISTS test");

            await connection.ExecuteStatementAsync($"CREATE DATABASE test");
        }
Exemplo n.º 5
0
        public async Task Setup()
        {
            await connection.ExecuteStatementAsync($"TRUNCATE TABLE IF EXISTS {Table}");

            await connection.ExecuteStatementAsync($"CREATE TABLE IF NOT EXISTS {Table}(id UInt32, params Nested (param_id UInt8, param_val String)) ENGINE = Memory");
        }
Exemplo n.º 6
0
 public Task FixtureSetup() => connection.ExecuteStatementAsync("CREATE DATABASE IF NOT EXISTS temp");