-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathExecuteNonQueryTests.cs
More file actions
44 lines (36 loc) · 1.48 KB
/
Copy pathExecuteNonQueryTests.cs
File metadata and controls
44 lines (36 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
namespace DuckDB.NET.Test;
public class ExecuteNonQueryTests(DuckDBDatabaseFixture db) : DuckDBTestBase(db)
{
[Fact]
public void TableQueryTest()
{
Command.CommandText = "CREATE TABLE users (id INTEGER, name TEXT);";
Command.ExecuteNonQuery();
Command.CommandText = "INSERT INTO users VALUES (1, 'user1'), (2, 'user2'), (3, 'user3'), (4, 'user4');";
var affectedRows = Command.ExecuteNonQuery();
affectedRows.Should().Be(4);
Command.CommandText = "UPDATE users SET name = 'unnamed' WHERE id % 2 = 0;";
affectedRows = Command.ExecuteNonQuery();
affectedRows.Should().Be(2);
}
[Fact]
public void ExecuteQueryWithUnicodeText()
{
var words = new List<string> { "张三", "李四", "王五", "გიორგი" };
Command.CommandText = "CREATE TABLE test(id BIGINT, name STRING); ";
Command.ExecuteNonQuery();
Command.CommandText = $"INSERT INTO test VALUES (1, '{words[0]}'), (3, '{words[1]}'), (5, '{words[2]}'), (4, '{words[3]}')";
Command.ExecuteNonQuery().Should().Be(4);
Command.CommandText = "Select * from test";
using (var reader = Command.ExecuteReader())
{
var results = new List<string>();
while (reader.Read())
{
var text = reader.IsDBNull(1) ? null : reader.GetString(1);
results.Add(text);
}
results.Should().BeEquivalentTo(words);
}
}
}