Slide 29
Slide 29 text
29
設定方法②:DbAccessor の拡張
© 2024 CData Software Inc. — CONFIDENTIAL – DO NOT DUPLICATE OR DISTRIBUTE
switch (dataSource.DataSourceType)
{
case DataSourceType.SQLServer:
conn = dataSourceName.Contains("CData") ?
new SAPGatewayConnection(dataSource.ConnectionString) :
new SqlConnection(dataSource.ConnectionString);
break;
case DataSourceType.PostgreSQL:
conn = new NpgsqlConnection(dataSource.ConnectionString);
break;
case DataSourceType.Oracle:
conn = new OracleConnection(dataSource.ConnectionString);
break;
case DataSourceType.SQLite:
conn = new SQLiteConnection(dataSource.ConnectionString);
break;
default: throw LowCodeException.Create("Invalid data source");
}
public async Task?>
GetCustomTableDefinitionsAsync(string dataSourceName)
{
var conn = GetConnection(dataSourceName);
var columnTable = await conn.GetSchemaAsync("Columns");
var ret = columnTable.Rows.Cast()
.Select(r => new
{
TableName = r["TABLE_NAME"].ToString() ?? "",
ColumnName = r["COLUMN_NAME"].ToString() ?? "",
RawDbTypeName = r["DATA_TYPE"].ToString() ?? "",
IsNullable = (r["IS_NULLABLE"].ToString() ?? "").ToLower() ==
"yes"
}).GroupBy(r => r.TableName)
.Select(g => new DbTableDefinition
{
Name = g.Key,
Columns = g.Select(gg => new DbColumnDefinition
{
Name = gg.ColumnName,
RawDbTypeName = gg.RawDbTypeName,
IsNullable = gg.IsNullable
}).ToList()
}).ToList();
return ret;
}