@@ -1124,85 +1124,104 @@ public override void ExitAliased_table_name(MiniSqlParserParser.Aliased_table_na
11241124 , comments ) ) ;
11251125 }
11261126
1127- public override void ExitIndexed_table_name ( MiniSqlParserParser . Indexed_table_nameContext context ) {
1127+ public override void ExitHinted_table_name ( MiniSqlParserParser . Hinted_table_nameContext context ) {
1128+ if ( context . table_hint ( ) == null ) {
1129+ // table_hintが存在しない場合はなにもしない
1130+ return ;
1131+ }
1132+
11281133 var tableNode = ( Table ) _stack . Pop ( ) ;
11291134 var comments = tableNode . Comments ;
11301135 comments . AddRange ( this . GetComments ( context ) ) ;
1131-
1132- Identifier indexServerName = null ;
1133- Identifier indexDatabaseName = null ;
1134- Identifier indexSchemaName = null ;
1135- Identifier indexName = null ;
1136- bool hasNotIndexed = false ;
1137- if ( context . K_NOT ( ) != null ) {
1138- hasNotIndexed = true ;
1139- } else if ( context . K_INDEXED ( ) != null ) {
1140- comments . AddRange ( this . GetComments ( context . index_name ( ) . qualified_schema_name ( ) ) ) ;
1141- comments . AddRange ( this . GetComments ( context . index_name ( ) ) ) ;
1142- if ( context . index_name ( ) . qualified_schema_name ( ) != null ) {
1143- indexServerName = this . GetIdentifier ( context . index_name ( ) . qualified_schema_name ( ) . s ) ;
1144- indexDatabaseName = this . GetIdentifier ( context . index_name ( ) . qualified_schema_name ( ) . d ) ;
1145- indexSchemaName = this . GetIdentifier ( context . index_name ( ) . qualified_schema_name ( ) . n ) ;
1146- }
1147- indexName = this . GetIdentifier ( context . index_name ( ) . identifier ( ) ) ;
1148- }
1136+ comments . AddRange ( this . GetComments ( context . table_hint ( ) ) ) ;
11491137
11501138 // コメントでテーブル別名の指定があれば取得する
11511139 var implicitAliasName = this . GetTableAliasNameFromDocComment ( context ) ;
11521140
1153- _stack . Push ( new Table ( tableNode . ServerName
1154- , tableNode . DataBaseName
1155- , tableNode . SchemaName
1156- , tableNode . Name
1157- , false
1158- , null
1159- , implicitAliasName
1160- , indexServerName
1161- , indexDatabaseName
1162- , indexSchemaName
1163- , indexName
1164- , hasNotIndexed
1165- , comments ) ) ;
1141+ var hinted_table = this . CreateHintedTable ( context . table_hint ( )
1142+ , tableNode
1143+ , implicitAliasName
1144+ , comments ) ;
1145+ _stack . Push ( hinted_table ) ;
11661146 }
11671147
1168- public override void ExitIndexed_aliased_table_name ( MiniSqlParserParser . Indexed_aliased_table_nameContext context ) {
1148+ public override void ExitHinted_aliased_table_name ( MiniSqlParserParser . Hinted_aliased_table_nameContext context ) {
1149+ if ( context . table_hint ( ) == null ) {
1150+ // table_hintが存在しない場合はなにもしない
1151+ return ;
1152+ }
1153+
11691154 var tableNode = ( Table ) _stack . Pop ( ) ;
11701155 var comments = tableNode . Comments ;
11711156 comments . AddRange ( this . GetComments ( context ) ) ;
1157+ comments . AddRange ( this . GetComments ( context . table_hint ( ) ) ) ;
1158+
1159+ var hinted_table = this . CreateHintedTable ( context . table_hint ( )
1160+ , tableNode
1161+ , tableNode . ImplicitAliasName
1162+ , comments ) ;
1163+ _stack . Push ( hinted_table ) ;
1164+ }
11721165
1166+ private Table CreateHintedTable ( MiniSqlParserParser . Table_hintContext table_hintContext
1167+ , Table tableNode
1168+ , string implicitAliasName
1169+ , Comments comments ) {
11731170 Identifier indexServerName = null ;
11741171 Identifier indexDatabaseName = null ;
11751172 Identifier indexSchemaName = null ;
11761173 Identifier indexName = null ;
11771174 bool hasNotIndexed = false ;
1178- if ( context . K_NOT ( ) != null ) {
1175+
1176+ if ( table_hintContext . K_NOT ( ) != null ) {
11791177 hasNotIndexed = true ;
1180- } else if ( context . K_INDEXED ( ) != null ) {
1181- comments . AddRange ( this . GetComments ( context . index_name ( ) . qualified_schema_name ( ) ) ) ;
1182- comments . AddRange ( this . GetComments ( context . index_name ( ) ) ) ;
1183- if ( context . index_name ( ) . qualified_schema_name ( ) != null ) {
1184- indexServerName = this . GetIdentifier ( context . index_name ( ) . qualified_schema_name ( ) . s ) ;
1185- indexDatabaseName = this . GetIdentifier ( context . index_name ( ) . qualified_schema_name ( ) . d ) ;
1186- indexSchemaName = this . GetIdentifier ( context . index_name ( ) . qualified_schema_name ( ) . n ) ;
1178+ } else if ( table_hintContext . K_INDEXED ( ) != null ) {
1179+ comments . AddRange ( this . GetComments ( table_hintContext . index_name ( ) . qualified_schema_name ( ) ) ) ;
1180+ comments . AddRange ( this . GetComments ( table_hintContext . index_name ( ) ) ) ;
1181+ if ( table_hintContext . index_name ( ) . qualified_schema_name ( ) != null ) {
1182+ indexServerName = this . GetIdentifier ( table_hintContext . index_name ( ) . qualified_schema_name ( ) . s ) ;
1183+ indexDatabaseName = this . GetIdentifier ( table_hintContext . index_name ( ) . qualified_schema_name ( ) . d ) ;
1184+ indexSchemaName = this . GetIdentifier ( table_hintContext . index_name ( ) . qualified_schema_name ( ) . n ) ;
11871185 }
1188- indexName = this . GetIdentifier ( context . index_name ( ) . identifier ( ) ) ;
1189- }
1186+ indexName = this . GetIdentifier ( table_hintContext . index_name ( ) . identifier ( ) ) ;
1187+ }
1188+ var msSqlHint = this . ConvToMsSqlHint ( table_hintContext . h ) ;
1189+
1190+ return new Table ( tableNode . ServerName
1191+ , tableNode . DataBaseName
1192+ , tableNode . SchemaName
1193+ , tableNode . Name
1194+ , tableNode . HasAs
1195+ , tableNode . AliasName
1196+ , implicitAliasName
1197+ , indexServerName
1198+ , indexDatabaseName
1199+ , indexSchemaName
1200+ , indexName
1201+ , hasNotIndexed
1202+ , msSqlHint
1203+ , comments ) ;
1204+ }
11901205
1191- _stack . Push ( new Table ( tableNode . ServerName
1192- , tableNode . DataBaseName
1193- , tableNode . SchemaName
1194- , tableNode . Name
1195- , tableNode . HasAs
1196- , tableNode . AliasName
1197- , tableNode . ImplicitAliasName
1198- , indexServerName
1199- , indexDatabaseName
1200- , indexSchemaName
1201- , indexName
1202- , hasNotIndexed
1203- , comments ) ) ;
1206+ private MsSqlHint ConvToMsSqlHint ( IToken msSqlHint ) {
1207+ if ( msSqlHint == null ) {
1208+ return MsSqlHint . None ;
1209+ }
1210+ var hintType = msSqlHint . Type ;
1211+ MsSqlHint hint = MsSqlHint . None ;
1212+ if ( hintType == MiniSqlParserLexer . K_NOLOCK ) {
1213+ hint = MsSqlHint . NoLock ;
1214+ } else if ( hintType == MiniSqlParserLexer . K_READCOMMITTED ) {
1215+ hint = MsSqlHint . ReadCommitted ;
1216+ } else if ( hintType == MiniSqlParserLexer . K_REPEATABLEREAD ) {
1217+ hint = MsSqlHint . RepeatableRead ;
1218+ } else if ( hintType == MiniSqlParserLexer . K_SERIALIZABLE ) {
1219+ hint = MsSqlHint . Serializable ;
1220+ } else {
1221+ throw new CannotBuildASTException ( "Undifined Ms SQL Hint is used" ) ;
1222+ }
1223+ return hint ;
12041224 }
1205-
12061225 }
12071226
12081227}
0 commit comments