@@ -12,31 +12,10 @@ public static class Temp
12
12
{
13
13
public static async Task < SqlServerStorageAreaFactory > Create ( string schema , SqlServerConnectionFactory connectionFactory )
14
14
{
15
- #if NETSTANDARD2_0
16
- using SqlConnection connection = connectionFactory . Create ( ) ;
17
- await connection . OpenAsync ( ) . ConfigureAwait ( false ) ;
18
-
19
- using SqlCommand command = new ( SqlServerStatements . Load ( "SelectSchemaExists" ) ) ;
20
- command . Parameters . Add ( "schema" , SqlDbType . NVarChar ) . Value = schema ;
21
- command . Connection = connection ;
22
-
23
- int schemaExists = ( int ) ( await command . ExecuteScalarAsync ( ) . ConfigureAwait ( false ) ?? throw new Exception ( ) ) ;
24
- if ( schemaExists == 0 )
25
- {
26
- //TODO: Needs to pass a state object to track creation of schema.
27
- return new SqlServerStorageAreaFactory ( new SqlServerSchemaStateManager ( connectionFactory , schema , false ) ) ;
28
- }
29
-
30
- using SqlCommand command2 = new ( SqlServerStatements . Load ( "SelectTableNames" ) ) ;
31
- command2 . Parameters . Add ( new SqlParameter ( "schema" , SqlDbType . NVarChar ) ) . Value = schema ;
32
- command2 . Connection = connection ;
33
-
34
- using SqlDataReader reader = await command2 . ExecuteReaderAsync ( ) . ConfigureAwait ( false ) ;
35
- #else
36
15
await using SqlConnection connection = connectionFactory . Create ( ) ;
37
16
await connection . OpenAsync ( ) . ConfigureAwait ( false ) ;
38
17
39
- await using SqlCommand command = new ( SqlServerStatements . Load ( " SelectSchemaExists" ) ) ;
18
+ await using SqlCommand command = new ( SqlTemplates . SelectSchemaExists ( ) ) ;
40
19
command . Parameters . Add ( "schema" , SqlDbType . NVarChar ) . Value = schema ;
41
20
command . Connection = connection ;
42
21
@@ -48,12 +27,12 @@ public static async Task<SqlServerStorageAreaFactory> Create(string schema, SqlS
48
27
return new SqlServerStorageAreaFactory ( new SqlServerSchemaStateManager ( connectionFactory , schema , false ) ) ;
49
28
}
50
29
51
- await using SqlCommand command2 = new ( SqlServerStatements . Load ( " SelectTableNames" ) ) ;
30
+ await using SqlCommand command2 = new ( SqlTemplates . SelectTableNames ( ) ) ;
52
31
command2 . Parameters . Add ( new SqlParameter ( "schema" , SqlDbType . NVarChar ) ) . Value = schema ;
53
32
command2 . Connection = connection ;
54
33
55
34
await using SqlDataReader reader = await command2 . ExecuteReaderAsync ( ) . ConfigureAwait ( false ) ;
56
- #endif
35
+
57
36
58
37
HashSet < string > names = new ( ) ;
59
38
while ( await reader . ReadAsync ( ) )
@@ -101,20 +80,8 @@ public async Task Ensure()
101
80
102
81
await padlock . WaitAsync ( ) ;
103
82
104
- string commandText = SqlServerStatements . Load ( " CreateSchema" , ( "schema" , SchemaName ) ) ;
83
+ string commandText = SqlTemplates . CreateSchema ( SchemaName ) ;
105
84
106
-
107
- #if NETSTANDARD2_0
108
- using SqlConnection connection = connectionFactory . Create ( ) ;
109
- using SqlCommand command = new SqlCommand ( commandText , connection ) ;
110
- await connection . OpenAsync ( ) . ConfigureAwait ( false ) ;
111
-
112
- using SqlTransaction transaction = connection . BeginTransaction ( IsolationLevel . ReadUncommitted ) ;
113
- command . Connection = connection ;
114
- command . Transaction = transaction ;
115
- await command . ExecuteNonQueryAsync ( ) . ConfigureAwait ( false ) ;
116
- transaction . Commit ( ) ;
117
- #else
118
85
await using SqlConnection connection = connectionFactory . Create ( ) ;
119
86
await using SqlCommand command = new SqlCommand ( commandText , connection ) ;
120
87
await connection . OpenAsync ( ) . ConfigureAwait ( false ) ;
@@ -124,7 +91,6 @@ public async Task Ensure()
124
91
command . Transaction = transaction ;
125
92
await command . ExecuteNonQueryAsync ( ) . ConfigureAwait ( false ) ;
126
93
await transaction . CommitAsync ( ) . ConfigureAwait ( false ) ;
127
- #endif
128
94
129
95
created = true ;
130
96
padlock . Release ( ) ;
@@ -159,15 +125,9 @@ public async Task Ensure()
159
125
if ( created )
160
126
return ;
161
127
162
- Dictionary < string , string > map = new ( ) {
163
- { "schema" , Schema } ,
164
- { "data_table_name" , $ "{ AreaName } .data" } ,
165
- { "log_table_name" , $ "{ AreaName } .log" } ,
166
- { "schema_table_name" , $ "{ AreaName } .schemas" }
167
- } ;
168
- string dataTableCommandText = SqlServerStatements . Load ( "CreateDataTable" , map ) ;
169
- string logTableCommandText = SqlServerStatements . Load ( "CreateLogTable" , map ) ;
170
- string schemaTableCommandText = SqlServerStatements . Load ( "CreateSchemasTable" , map ) ;
128
+ string dataTableCommandText = SqlTemplates . CreateDataTable ( Schema , AreaName ) ; // SqlServerStatements.Load("CreateDataTable", map);
129
+ string logTableCommandText = SqlTemplates . CreateLogTable ( Schema , AreaName ) ; // SqlServerStatements.Load("CreateLogTable", map);
130
+ string schemaTableCommandText = SqlTemplates . CreateSchemasTable ( Schema , AreaName ) ; // SqlServerStatements.Load("CreateSchemasTable", map);
171
131
172
132
//await using SqlConnection connection = connectionFactory.Create();
173
133
using SqlConnection connection = connectionFactory . Create ( ) ;
0 commit comments