Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add get schema table test #94

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -234,10 +234,10 @@ jobs:
sudo dotnet test --logger "console;verbosity=detailed" --collect:"XPlat Code Coverage" --results-directory:./testresults
timeout-minutes: 15

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: always() && (steps.test.outcome == 'failure' || steps.test.outcome == 'cancelled')
with:
name: ${{ runner.os }}-${{ matrix.go }}-log
name: ${{ runner.os }}-${{ matrix.dotnet }}-log
path: /var/log/taos/

- name: get coverage files
@@ -248,8 +248,7 @@ jobs:
echo "files=${COVERAGE_FILES}" >> $GITHUB_OUTPUT

- name: Upload coverage to Codecov
if: ${{ matrix.go }} == '6.0.x'
uses: codecov/codecov-action@v4-beta
uses: codecov/codecov-action@v4
with:
files: ${{ steps.get_coverage_files.outputs.files }}
env:
118 changes: 118 additions & 0 deletions test/Data.Tests/TDengineDataReaderTesting.cs
Original file line number Diff line number Diff line change
@@ -751,5 +751,123 @@ public void WSStatementNano()
Assert.Equal(0, affected);
}
}

[Fact]
public void GetSchemaTable()
{
using (var cmd = _connection.CreateCommand())
{
cmd.CommandText = "drop database if exists test_schema_table";
var affected = cmd.ExecuteNonQuery();
Assert.Equal(0, affected);
cmd.CommandText = "create database test_schema_table";
affected = cmd.ExecuteNonQuery();
Assert.Equal(0, affected);
_connection.ChangeDatabase("test_schema_table");
cmd.CommandText =
"create table if not exists test_types(" +
"ts timestamp, f_int int, f_bigint bigint, f_float float, f_double double, f_binary binary(16), " +
"f_smallint smallint, f_tinyint tinyint, f_bool bool, f_nchar nchar(16), " +
"f_uint int unsigned,f_ubigint bigint unsigned, f_usmallint smallint unsigned,f_utinyint tinyint unsigned)";
affected = cmd.ExecuteNonQuery();
Assert.Equal(0, affected);
cmd.CommandText =
"insert into test_types values(now+1s, null, null, null, null, null, null, null, null, null,null,null,null,null)," +
"(now, 1, 2, 3000000.3, 400000000.4, '5binary', 6, 7, true, '9nchar',10,11,12,13)";
affected = cmd.ExecuteNonQuery();
Assert.Equal(2, affected);
cmd.CommandText =
"select ts, f_int, f_bigint, f_float, f_double, f_binary, f_smallint, f_tinyint, f_bool, f_nchar,f_uint,f_ubigint,f_usmallint,f_utinyint from test_types order by ts desc limit 2";
var reader = cmd.ExecuteReader();
var schemaTable = reader.GetSchemaTable();
Assert.Equal(14, schemaTable.Rows.Count);
Assert.Equal("ts", schemaTable.Rows[0]["ColumnName"]);
Assert.Equal(typeof(DateTime), schemaTable.Rows[0]["DataType"]);
Assert.Equal(0, schemaTable.Rows[0]["ColumnOrdinal"]);
Assert.Equal(8, schemaTable.Rows[0]["ColumnSize"]);
Assert.Equal("TIMESTAMP", schemaTable.Rows[0]["DataTypeName"]);

Assert.Equal("f_int", schemaTable.Rows[1]["ColumnName"]);
Assert.Equal(typeof(int), schemaTable.Rows[1]["DataType"]);
Assert.Equal(1, schemaTable.Rows[1]["ColumnOrdinal"]);
Assert.Equal(4, schemaTable.Rows[1]["ColumnSize"]);
Assert.Equal("INT", schemaTable.Rows[1]["DataTypeName"]);

Assert.Equal("f_bigint", schemaTable.Rows[2]["ColumnName"]);
Assert.Equal(typeof(long), schemaTable.Rows[2]["DataType"]);
Assert.Equal(2, schemaTable.Rows[2]["ColumnOrdinal"]);
Assert.Equal(8, schemaTable.Rows[2]["ColumnSize"]);
Assert.Equal("BIGINT", schemaTable.Rows[2]["DataTypeName"]);

Assert.Equal("f_float", schemaTable.Rows[3]["ColumnName"]);
Assert.Equal(typeof(float), schemaTable.Rows[3]["DataType"]);
Assert.Equal(3, schemaTable.Rows[3]["ColumnOrdinal"]);
Assert.Equal(4, schemaTable.Rows[3]["ColumnSize"]);
Assert.Equal("FLOAT", schemaTable.Rows[3]["DataTypeName"]);

Assert.Equal("f_double", schemaTable.Rows[4]["ColumnName"]);
Assert.Equal(typeof(double), schemaTable.Rows[4]["DataType"]);
Assert.Equal(4, schemaTable.Rows[4]["ColumnOrdinal"]);
Assert.Equal(8, schemaTable.Rows[4]["ColumnSize"]);
Assert.Equal("DOUBLE", schemaTable.Rows[4]["DataTypeName"]);

Assert.Equal("f_binary", schemaTable.Rows[5]["ColumnName"]);
Assert.Equal(typeof(byte[]), schemaTable.Rows[5]["DataType"]);
Assert.Equal(5, schemaTable.Rows[5]["ColumnOrdinal"]);
Assert.Equal(16, schemaTable.Rows[5]["ColumnSize"]);
Assert.Equal("BINARY", schemaTable.Rows[5]["DataTypeName"]);

Assert.Equal("f_smallint", schemaTable.Rows[6]["ColumnName"]);
Assert.Equal(typeof(short), schemaTable.Rows[6]["DataType"]);
Assert.Equal(6, schemaTable.Rows[6]["ColumnOrdinal"]);
Assert.Equal(2, schemaTable.Rows[6]["ColumnSize"]);
Assert.Equal("SMALLINT", schemaTable.Rows[6]["DataTypeName"]);


Assert.Equal("f_tinyint", schemaTable.Rows[7]["ColumnName"]);
Assert.Equal(typeof(sbyte), schemaTable.Rows[7]["DataType"]);
Assert.Equal(7, schemaTable.Rows[7]["ColumnOrdinal"]);
Assert.Equal(1, schemaTable.Rows[7]["ColumnSize"]);
Assert.Equal("TINYINT", schemaTable.Rows[7]["DataTypeName"]);

Assert.Equal("f_bool", schemaTable.Rows[8]["ColumnName"]);
Assert.Equal(typeof(bool), schemaTable.Rows[8]["DataType"]);
Assert.Equal(8, schemaTable.Rows[8]["ColumnOrdinal"]);
Assert.Equal(1, schemaTable.Rows[8]["ColumnSize"]);
Assert.Equal("BOOL", schemaTable.Rows[8]["DataTypeName"]);

Assert.Equal("f_nchar", schemaTable.Rows[9]["ColumnName"]);
Assert.Equal(typeof(string), schemaTable.Rows[9]["DataType"]);
Assert.Equal(9, schemaTable.Rows[9]["ColumnOrdinal"]);
Assert.Equal(16, schemaTable.Rows[9]["ColumnSize"]);
Assert.Equal("NCHAR", schemaTable.Rows[9]["DataTypeName"]);

Assert.Equal("f_uint", schemaTable.Rows[10]["ColumnName"]);
Assert.Equal(typeof(uint), schemaTable.Rows[10]["DataType"]);
Assert.Equal(10, schemaTable.Rows[10]["ColumnOrdinal"]);
Assert.Equal(4, schemaTable.Rows[10]["ColumnSize"]);
Assert.Equal("INT UNSIGNED", schemaTable.Rows[10]["DataTypeName"]);

Assert.Equal("f_ubigint", schemaTable.Rows[11]["ColumnName"]);
Assert.Equal(typeof(ulong), schemaTable.Rows[11]["DataType"]);
Assert.Equal(11, schemaTable.Rows[11]["ColumnOrdinal"]);
Assert.Equal(8, schemaTable.Rows[11]["ColumnSize"]);
Assert.Equal("BIGINT UNSIGNED", schemaTable.Rows[11]["DataTypeName"]);

Assert.Equal("f_usmallint", schemaTable.Rows[12]["ColumnName"]);
Assert.Equal(typeof(ushort), schemaTable.Rows[12]["DataType"]);
Assert.Equal(12, schemaTable.Rows[12]["ColumnOrdinal"]);
Assert.Equal(2, schemaTable.Rows[12]["ColumnSize"]);
Assert.Equal("SMALLINT UNSIGNED", schemaTable.Rows[12]["DataTypeName"]);

Assert.Equal("f_utinyint", schemaTable.Rows[13]["ColumnName"]);
Assert.Equal(typeof(byte), schemaTable.Rows[13]["DataType"]);
Assert.Equal(13, schemaTable.Rows[13]["ColumnOrdinal"]);
Assert.Equal(1, schemaTable.Rows[13]["ColumnSize"]);
Assert.Equal("TINYINT UNSIGNED", schemaTable.Rows[13]["DataTypeName"]);

reader.Close();
}
}
}
}