github.com/vedadiyan/sqlparser@v1.0.0/pkg/sqlparser/ast_rewrite.go (about) 1 /* 2 Copyright 2023 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 // Code generated by ASTHelperGen. DO NOT EDIT. 17 18 package sqlparser 19 20 func (a *application) rewriteSQLNode(parent SQLNode, node SQLNode, replacer replacerFunc) bool { 21 if node == nil { 22 return true 23 } 24 switch node := node.(type) { 25 case *AddColumns: 26 return a.rewriteRefOfAddColumns(parent, node, replacer) 27 case *AddConstraintDefinition: 28 return a.rewriteRefOfAddConstraintDefinition(parent, node, replacer) 29 case *AddIndexDefinition: 30 return a.rewriteRefOfAddIndexDefinition(parent, node, replacer) 31 case AlgorithmValue: 32 return a.rewriteAlgorithmValue(parent, node, replacer) 33 case *AliasedExpr: 34 return a.rewriteRefOfAliasedExpr(parent, node, replacer) 35 case *AliasedTableExpr: 36 return a.rewriteRefOfAliasedTableExpr(parent, node, replacer) 37 case *AlterCharset: 38 return a.rewriteRefOfAlterCharset(parent, node, replacer) 39 case *AlterCheck: 40 return a.rewriteRefOfAlterCheck(parent, node, replacer) 41 case *AlterColumn: 42 return a.rewriteRefOfAlterColumn(parent, node, replacer) 43 case *AlterDatabase: 44 return a.rewriteRefOfAlterDatabase(parent, node, replacer) 45 case *AlterIndex: 46 return a.rewriteRefOfAlterIndex(parent, node, replacer) 47 case *AlterMigration: 48 return a.rewriteRefOfAlterMigration(parent, node, replacer) 49 case *AlterTable: 50 return a.rewriteRefOfAlterTable(parent, node, replacer) 51 case *AlterView: 52 return a.rewriteRefOfAlterView(parent, node, replacer) 53 case *AlterVschema: 54 return a.rewriteRefOfAlterVschema(parent, node, replacer) 55 case *AndExpr: 56 return a.rewriteRefOfAndExpr(parent, node, replacer) 57 case Argument: 58 return a.rewriteArgument(parent, node, replacer) 59 case *ArgumentLessWindowExpr: 60 return a.rewriteRefOfArgumentLessWindowExpr(parent, node, replacer) 61 case *AutoIncSpec: 62 return a.rewriteRefOfAutoIncSpec(parent, node, replacer) 63 case *Avg: 64 return a.rewriteRefOfAvg(parent, node, replacer) 65 case *Begin: 66 return a.rewriteRefOfBegin(parent, node, replacer) 67 case *BetweenExpr: 68 return a.rewriteRefOfBetweenExpr(parent, node, replacer) 69 case *BinaryExpr: 70 return a.rewriteRefOfBinaryExpr(parent, node, replacer) 71 case *BitAnd: 72 return a.rewriteRefOfBitAnd(parent, node, replacer) 73 case *BitOr: 74 return a.rewriteRefOfBitOr(parent, node, replacer) 75 case *BitXor: 76 return a.rewriteRefOfBitXor(parent, node, replacer) 77 case BoolVal: 78 return a.rewriteBoolVal(parent, node, replacer) 79 case *CallProc: 80 return a.rewriteRefOfCallProc(parent, node, replacer) 81 case *CaseExpr: 82 return a.rewriteRefOfCaseExpr(parent, node, replacer) 83 case *CastExpr: 84 return a.rewriteRefOfCastExpr(parent, node, replacer) 85 case *ChangeColumn: 86 return a.rewriteRefOfChangeColumn(parent, node, replacer) 87 case *CharExpr: 88 return a.rewriteRefOfCharExpr(parent, node, replacer) 89 case *CheckConstraintDefinition: 90 return a.rewriteRefOfCheckConstraintDefinition(parent, node, replacer) 91 case *ColName: 92 return a.rewriteRefOfColName(parent, node, replacer) 93 case *CollateExpr: 94 return a.rewriteRefOfCollateExpr(parent, node, replacer) 95 case *ColumnDefinition: 96 return a.rewriteRefOfColumnDefinition(parent, node, replacer) 97 case *ColumnType: 98 return a.rewriteRefOfColumnType(parent, node, replacer) 99 case Columns: 100 return a.rewriteColumns(parent, node, replacer) 101 case *CommentOnly: 102 return a.rewriteRefOfCommentOnly(parent, node, replacer) 103 case *Commit: 104 return a.rewriteRefOfCommit(parent, node, replacer) 105 case *CommonTableExpr: 106 return a.rewriteRefOfCommonTableExpr(parent, node, replacer) 107 case *ComparisonExpr: 108 return a.rewriteRefOfComparisonExpr(parent, node, replacer) 109 case *ConstraintDefinition: 110 return a.rewriteRefOfConstraintDefinition(parent, node, replacer) 111 case *ConvertExpr: 112 return a.rewriteRefOfConvertExpr(parent, node, replacer) 113 case *ConvertType: 114 return a.rewriteRefOfConvertType(parent, node, replacer) 115 case *ConvertUsingExpr: 116 return a.rewriteRefOfConvertUsingExpr(parent, node, replacer) 117 case *Count: 118 return a.rewriteRefOfCount(parent, node, replacer) 119 case *CountStar: 120 return a.rewriteRefOfCountStar(parent, node, replacer) 121 case *CreateDatabase: 122 return a.rewriteRefOfCreateDatabase(parent, node, replacer) 123 case *CreateTable: 124 return a.rewriteRefOfCreateTable(parent, node, replacer) 125 case *CreateView: 126 return a.rewriteRefOfCreateView(parent, node, replacer) 127 case *CurTimeFuncExpr: 128 return a.rewriteRefOfCurTimeFuncExpr(parent, node, replacer) 129 case *DeallocateStmt: 130 return a.rewriteRefOfDeallocateStmt(parent, node, replacer) 131 case *Default: 132 return a.rewriteRefOfDefault(parent, node, replacer) 133 case *Definer: 134 return a.rewriteRefOfDefiner(parent, node, replacer) 135 case *Delete: 136 return a.rewriteRefOfDelete(parent, node, replacer) 137 case *DerivedTable: 138 return a.rewriteRefOfDerivedTable(parent, node, replacer) 139 case *DropColumn: 140 return a.rewriteRefOfDropColumn(parent, node, replacer) 141 case *DropDatabase: 142 return a.rewriteRefOfDropDatabase(parent, node, replacer) 143 case *DropKey: 144 return a.rewriteRefOfDropKey(parent, node, replacer) 145 case *DropTable: 146 return a.rewriteRefOfDropTable(parent, node, replacer) 147 case *DropView: 148 return a.rewriteRefOfDropView(parent, node, replacer) 149 case *ExecuteStmt: 150 return a.rewriteRefOfExecuteStmt(parent, node, replacer) 151 case *ExistsExpr: 152 return a.rewriteRefOfExistsExpr(parent, node, replacer) 153 case *ExplainStmt: 154 return a.rewriteRefOfExplainStmt(parent, node, replacer) 155 case *ExplainTab: 156 return a.rewriteRefOfExplainTab(parent, node, replacer) 157 case Exprs: 158 return a.rewriteExprs(parent, node, replacer) 159 case *ExtractFuncExpr: 160 return a.rewriteRefOfExtractFuncExpr(parent, node, replacer) 161 case *ExtractValueExpr: 162 return a.rewriteRefOfExtractValueExpr(parent, node, replacer) 163 case *ExtractedSubquery: 164 return a.rewriteRefOfExtractedSubquery(parent, node, replacer) 165 case *FirstOrLastValueExpr: 166 return a.rewriteRefOfFirstOrLastValueExpr(parent, node, replacer) 167 case *Flush: 168 return a.rewriteRefOfFlush(parent, node, replacer) 169 case *Force: 170 return a.rewriteRefOfForce(parent, node, replacer) 171 case *ForeignKeyDefinition: 172 return a.rewriteRefOfForeignKeyDefinition(parent, node, replacer) 173 case *FrameClause: 174 return a.rewriteRefOfFrameClause(parent, node, replacer) 175 case *FramePoint: 176 return a.rewriteRefOfFramePoint(parent, node, replacer) 177 case *FromFirstLastClause: 178 return a.rewriteRefOfFromFirstLastClause(parent, node, replacer) 179 case *FuncExpr: 180 return a.rewriteRefOfFuncExpr(parent, node, replacer) 181 case *GTIDFuncExpr: 182 return a.rewriteRefOfGTIDFuncExpr(parent, node, replacer) 183 case GroupBy: 184 return a.rewriteGroupBy(parent, node, replacer) 185 case *GroupConcatExpr: 186 return a.rewriteRefOfGroupConcatExpr(parent, node, replacer) 187 case IdentifierCI: 188 return a.rewriteIdentifierCI(parent, node, replacer) 189 case IdentifierCS: 190 return a.rewriteIdentifierCS(parent, node, replacer) 191 case *IndexDefinition: 192 return a.rewriteRefOfIndexDefinition(parent, node, replacer) 193 case *IndexHint: 194 return a.rewriteRefOfIndexHint(parent, node, replacer) 195 case IndexHints: 196 return a.rewriteIndexHints(parent, node, replacer) 197 case *IndexInfo: 198 return a.rewriteRefOfIndexInfo(parent, node, replacer) 199 case *Insert: 200 return a.rewriteRefOfInsert(parent, node, replacer) 201 case *InsertExpr: 202 return a.rewriteRefOfInsertExpr(parent, node, replacer) 203 case *IntervalExpr: 204 return a.rewriteRefOfIntervalExpr(parent, node, replacer) 205 case *IntervalFuncExpr: 206 return a.rewriteRefOfIntervalFuncExpr(parent, node, replacer) 207 case *IntroducerExpr: 208 return a.rewriteRefOfIntroducerExpr(parent, node, replacer) 209 case *IsExpr: 210 return a.rewriteRefOfIsExpr(parent, node, replacer) 211 case *JSONArrayExpr: 212 return a.rewriteRefOfJSONArrayExpr(parent, node, replacer) 213 case *JSONAttributesExpr: 214 return a.rewriteRefOfJSONAttributesExpr(parent, node, replacer) 215 case *JSONContainsExpr: 216 return a.rewriteRefOfJSONContainsExpr(parent, node, replacer) 217 case *JSONContainsPathExpr: 218 return a.rewriteRefOfJSONContainsPathExpr(parent, node, replacer) 219 case *JSONExtractExpr: 220 return a.rewriteRefOfJSONExtractExpr(parent, node, replacer) 221 case *JSONKeysExpr: 222 return a.rewriteRefOfJSONKeysExpr(parent, node, replacer) 223 case *JSONObjectExpr: 224 return a.rewriteRefOfJSONObjectExpr(parent, node, replacer) 225 case *JSONObjectParam: 226 return a.rewriteRefOfJSONObjectParam(parent, node, replacer) 227 case *JSONOverlapsExpr: 228 return a.rewriteRefOfJSONOverlapsExpr(parent, node, replacer) 229 case *JSONPrettyExpr: 230 return a.rewriteRefOfJSONPrettyExpr(parent, node, replacer) 231 case *JSONQuoteExpr: 232 return a.rewriteRefOfJSONQuoteExpr(parent, node, replacer) 233 case *JSONRemoveExpr: 234 return a.rewriteRefOfJSONRemoveExpr(parent, node, replacer) 235 case *JSONSchemaValidFuncExpr: 236 return a.rewriteRefOfJSONSchemaValidFuncExpr(parent, node, replacer) 237 case *JSONSchemaValidationReportFuncExpr: 238 return a.rewriteRefOfJSONSchemaValidationReportFuncExpr(parent, node, replacer) 239 case *JSONSearchExpr: 240 return a.rewriteRefOfJSONSearchExpr(parent, node, replacer) 241 case *JSONStorageFreeExpr: 242 return a.rewriteRefOfJSONStorageFreeExpr(parent, node, replacer) 243 case *JSONStorageSizeExpr: 244 return a.rewriteRefOfJSONStorageSizeExpr(parent, node, replacer) 245 case *JSONTableExpr: 246 return a.rewriteRefOfJSONTableExpr(parent, node, replacer) 247 case *JSONUnquoteExpr: 248 return a.rewriteRefOfJSONUnquoteExpr(parent, node, replacer) 249 case *JSONValueExpr: 250 return a.rewriteRefOfJSONValueExpr(parent, node, replacer) 251 case *JSONValueMergeExpr: 252 return a.rewriteRefOfJSONValueMergeExpr(parent, node, replacer) 253 case *JSONValueModifierExpr: 254 return a.rewriteRefOfJSONValueModifierExpr(parent, node, replacer) 255 case *JoinCondition: 256 return a.rewriteRefOfJoinCondition(parent, node, replacer) 257 case *JoinTableExpr: 258 return a.rewriteRefOfJoinTableExpr(parent, node, replacer) 259 case *JtColumnDefinition: 260 return a.rewriteRefOfJtColumnDefinition(parent, node, replacer) 261 case *JtOnResponse: 262 return a.rewriteRefOfJtOnResponse(parent, node, replacer) 263 case *KeyState: 264 return a.rewriteRefOfKeyState(parent, node, replacer) 265 case *LagLeadExpr: 266 return a.rewriteRefOfLagLeadExpr(parent, node, replacer) 267 case *Limit: 268 return a.rewriteRefOfLimit(parent, node, replacer) 269 case *LineStringExpr: 270 return a.rewriteRefOfLineStringExpr(parent, node, replacer) 271 case ListArg: 272 return a.rewriteListArg(parent, node, replacer) 273 case *Literal: 274 return a.rewriteRefOfLiteral(parent, node, replacer) 275 case *Load: 276 return a.rewriteRefOfLoad(parent, node, replacer) 277 case *LocateExpr: 278 return a.rewriteRefOfLocateExpr(parent, node, replacer) 279 case *LockOption: 280 return a.rewriteRefOfLockOption(parent, node, replacer) 281 case *LockTables: 282 return a.rewriteRefOfLockTables(parent, node, replacer) 283 case *LockingFunc: 284 return a.rewriteRefOfLockingFunc(parent, node, replacer) 285 case MatchAction: 286 return a.rewriteMatchAction(parent, node, replacer) 287 case *MatchExpr: 288 return a.rewriteRefOfMatchExpr(parent, node, replacer) 289 case *Max: 290 return a.rewriteRefOfMax(parent, node, replacer) 291 case *MemberOfExpr: 292 return a.rewriteRefOfMemberOfExpr(parent, node, replacer) 293 case *Min: 294 return a.rewriteRefOfMin(parent, node, replacer) 295 case *ModifyColumn: 296 return a.rewriteRefOfModifyColumn(parent, node, replacer) 297 case *NTHValueExpr: 298 return a.rewriteRefOfNTHValueExpr(parent, node, replacer) 299 case *NamedWindow: 300 return a.rewriteRefOfNamedWindow(parent, node, replacer) 301 case NamedWindows: 302 return a.rewriteNamedWindows(parent, node, replacer) 303 case *Nextval: 304 return a.rewriteRefOfNextval(parent, node, replacer) 305 case *NotExpr: 306 return a.rewriteRefOfNotExpr(parent, node, replacer) 307 case *NtileExpr: 308 return a.rewriteRefOfNtileExpr(parent, node, replacer) 309 case *NullTreatmentClause: 310 return a.rewriteRefOfNullTreatmentClause(parent, node, replacer) 311 case *NullVal: 312 return a.rewriteRefOfNullVal(parent, node, replacer) 313 case *Offset: 314 return a.rewriteRefOfOffset(parent, node, replacer) 315 case OnDup: 316 return a.rewriteOnDup(parent, node, replacer) 317 case *OptLike: 318 return a.rewriteRefOfOptLike(parent, node, replacer) 319 case *OrExpr: 320 return a.rewriteRefOfOrExpr(parent, node, replacer) 321 case *Order: 322 return a.rewriteRefOfOrder(parent, node, replacer) 323 case OrderBy: 324 return a.rewriteOrderBy(parent, node, replacer) 325 case *OrderByOption: 326 return a.rewriteRefOfOrderByOption(parent, node, replacer) 327 case *OtherAdmin: 328 return a.rewriteRefOfOtherAdmin(parent, node, replacer) 329 case *OtherRead: 330 return a.rewriteRefOfOtherRead(parent, node, replacer) 331 case *OverClause: 332 return a.rewriteRefOfOverClause(parent, node, replacer) 333 case *ParenTableExpr: 334 return a.rewriteRefOfParenTableExpr(parent, node, replacer) 335 case *ParsedComments: 336 return a.rewriteRefOfParsedComments(parent, node, replacer) 337 case *PartitionDefinition: 338 return a.rewriteRefOfPartitionDefinition(parent, node, replacer) 339 case *PartitionDefinitionOptions: 340 return a.rewriteRefOfPartitionDefinitionOptions(parent, node, replacer) 341 case *PartitionEngine: 342 return a.rewriteRefOfPartitionEngine(parent, node, replacer) 343 case *PartitionOption: 344 return a.rewriteRefOfPartitionOption(parent, node, replacer) 345 case *PartitionSpec: 346 return a.rewriteRefOfPartitionSpec(parent, node, replacer) 347 case *PartitionValueRange: 348 return a.rewriteRefOfPartitionValueRange(parent, node, replacer) 349 case Partitions: 350 return a.rewritePartitions(parent, node, replacer) 351 case *PerformanceSchemaFuncExpr: 352 return a.rewriteRefOfPerformanceSchemaFuncExpr(parent, node, replacer) 353 case *PointExpr: 354 return a.rewriteRefOfPointExpr(parent, node, replacer) 355 case *PrepareStmt: 356 return a.rewriteRefOfPrepareStmt(parent, node, replacer) 357 case ReferenceAction: 358 return a.rewriteReferenceAction(parent, node, replacer) 359 case *ReferenceDefinition: 360 return a.rewriteRefOfReferenceDefinition(parent, node, replacer) 361 case *RegexpInstrExpr: 362 return a.rewriteRefOfRegexpInstrExpr(parent, node, replacer) 363 case *RegexpLikeExpr: 364 return a.rewriteRefOfRegexpLikeExpr(parent, node, replacer) 365 case *RegexpReplaceExpr: 366 return a.rewriteRefOfRegexpReplaceExpr(parent, node, replacer) 367 case *RegexpSubstrExpr: 368 return a.rewriteRefOfRegexpSubstrExpr(parent, node, replacer) 369 case *Release: 370 return a.rewriteRefOfRelease(parent, node, replacer) 371 case *RenameColumn: 372 return a.rewriteRefOfRenameColumn(parent, node, replacer) 373 case *RenameIndex: 374 return a.rewriteRefOfRenameIndex(parent, node, replacer) 375 case *RenameTable: 376 return a.rewriteRefOfRenameTable(parent, node, replacer) 377 case *RenameTableName: 378 return a.rewriteRefOfRenameTableName(parent, node, replacer) 379 case *RevertMigration: 380 return a.rewriteRefOfRevertMigration(parent, node, replacer) 381 case *Rollback: 382 return a.rewriteRefOfRollback(parent, node, replacer) 383 case RootNode: 384 return a.rewriteRootNode(parent, node, replacer) 385 case *SRollback: 386 return a.rewriteRefOfSRollback(parent, node, replacer) 387 case *Savepoint: 388 return a.rewriteRefOfSavepoint(parent, node, replacer) 389 case *Select: 390 return a.rewriteRefOfSelect(parent, node, replacer) 391 case SelectExprs: 392 return a.rewriteSelectExprs(parent, node, replacer) 393 case *SelectInto: 394 return a.rewriteRefOfSelectInto(parent, node, replacer) 395 case *Set: 396 return a.rewriteRefOfSet(parent, node, replacer) 397 case *SetExpr: 398 return a.rewriteRefOfSetExpr(parent, node, replacer) 399 case SetExprs: 400 return a.rewriteSetExprs(parent, node, replacer) 401 case *Show: 402 return a.rewriteRefOfShow(parent, node, replacer) 403 case *ShowBasic: 404 return a.rewriteRefOfShowBasic(parent, node, replacer) 405 case *ShowCreate: 406 return a.rewriteRefOfShowCreate(parent, node, replacer) 407 case *ShowFilter: 408 return a.rewriteRefOfShowFilter(parent, node, replacer) 409 case *ShowMigrationLogs: 410 return a.rewriteRefOfShowMigrationLogs(parent, node, replacer) 411 case *ShowOther: 412 return a.rewriteRefOfShowOther(parent, node, replacer) 413 case *ShowThrottledApps: 414 return a.rewriteRefOfShowThrottledApps(parent, node, replacer) 415 case *ShowThrottlerStatus: 416 return a.rewriteRefOfShowThrottlerStatus(parent, node, replacer) 417 case *StarExpr: 418 return a.rewriteRefOfStarExpr(parent, node, replacer) 419 case *Std: 420 return a.rewriteRefOfStd(parent, node, replacer) 421 case *StdDev: 422 return a.rewriteRefOfStdDev(parent, node, replacer) 423 case *StdPop: 424 return a.rewriteRefOfStdPop(parent, node, replacer) 425 case *StdSamp: 426 return a.rewriteRefOfStdSamp(parent, node, replacer) 427 case *Stream: 428 return a.rewriteRefOfStream(parent, node, replacer) 429 case *SubPartition: 430 return a.rewriteRefOfSubPartition(parent, node, replacer) 431 case *SubPartitionDefinition: 432 return a.rewriteRefOfSubPartitionDefinition(parent, node, replacer) 433 case *SubPartitionDefinitionOptions: 434 return a.rewriteRefOfSubPartitionDefinitionOptions(parent, node, replacer) 435 case SubPartitionDefinitions: 436 return a.rewriteSubPartitionDefinitions(parent, node, replacer) 437 case *Subquery: 438 return a.rewriteRefOfSubquery(parent, node, replacer) 439 case *SubstrExpr: 440 return a.rewriteRefOfSubstrExpr(parent, node, replacer) 441 case *Sum: 442 return a.rewriteRefOfSum(parent, node, replacer) 443 case TableExprs: 444 return a.rewriteTableExprs(parent, node, replacer) 445 case TableName: 446 return a.rewriteTableName(parent, node, replacer) 447 case TableNames: 448 return a.rewriteTableNames(parent, node, replacer) 449 case TableOptions: 450 return a.rewriteTableOptions(parent, node, replacer) 451 case *TableSpec: 452 return a.rewriteRefOfTableSpec(parent, node, replacer) 453 case *TablespaceOperation: 454 return a.rewriteRefOfTablespaceOperation(parent, node, replacer) 455 case *TimestampFuncExpr: 456 return a.rewriteRefOfTimestampFuncExpr(parent, node, replacer) 457 case *TrimFuncExpr: 458 return a.rewriteRefOfTrimFuncExpr(parent, node, replacer) 459 case *TruncateTable: 460 return a.rewriteRefOfTruncateTable(parent, node, replacer) 461 case *UnaryExpr: 462 return a.rewriteRefOfUnaryExpr(parent, node, replacer) 463 case *Union: 464 return a.rewriteRefOfUnion(parent, node, replacer) 465 case *UnlockTables: 466 return a.rewriteRefOfUnlockTables(parent, node, replacer) 467 case *Update: 468 return a.rewriteRefOfUpdate(parent, node, replacer) 469 case *UpdateExpr: 470 return a.rewriteRefOfUpdateExpr(parent, node, replacer) 471 case UpdateExprs: 472 return a.rewriteUpdateExprs(parent, node, replacer) 473 case *UpdateXMLExpr: 474 return a.rewriteRefOfUpdateXMLExpr(parent, node, replacer) 475 case *Use: 476 return a.rewriteRefOfUse(parent, node, replacer) 477 case *VExplainStmt: 478 return a.rewriteRefOfVExplainStmt(parent, node, replacer) 479 case *VStream: 480 return a.rewriteRefOfVStream(parent, node, replacer) 481 case ValTuple: 482 return a.rewriteValTuple(parent, node, replacer) 483 case *Validation: 484 return a.rewriteRefOfValidation(parent, node, replacer) 485 case Values: 486 return a.rewriteValues(parent, node, replacer) 487 case *ValuesFuncExpr: 488 return a.rewriteRefOfValuesFuncExpr(parent, node, replacer) 489 case *VarPop: 490 return a.rewriteRefOfVarPop(parent, node, replacer) 491 case *VarSamp: 492 return a.rewriteRefOfVarSamp(parent, node, replacer) 493 case *Variable: 494 return a.rewriteRefOfVariable(parent, node, replacer) 495 case *Variance: 496 return a.rewriteRefOfVariance(parent, node, replacer) 497 case VindexParam: 498 return a.rewriteVindexParam(parent, node, replacer) 499 case *VindexSpec: 500 return a.rewriteRefOfVindexSpec(parent, node, replacer) 501 case *WeightStringFuncExpr: 502 return a.rewriteRefOfWeightStringFuncExpr(parent, node, replacer) 503 case *When: 504 return a.rewriteRefOfWhen(parent, node, replacer) 505 case *Where: 506 return a.rewriteRefOfWhere(parent, node, replacer) 507 case *WindowDefinition: 508 return a.rewriteRefOfWindowDefinition(parent, node, replacer) 509 case WindowDefinitions: 510 return a.rewriteWindowDefinitions(parent, node, replacer) 511 case *WindowSpecification: 512 return a.rewriteRefOfWindowSpecification(parent, node, replacer) 513 case *With: 514 return a.rewriteRefOfWith(parent, node, replacer) 515 case *XorExpr: 516 return a.rewriteRefOfXorExpr(parent, node, replacer) 517 default: 518 // this should never happen 519 return true 520 } 521 } 522 func (a *application) rewriteRefOfAddColumns(parent SQLNode, node *AddColumns, replacer replacerFunc) bool { 523 if node == nil { 524 return true 525 } 526 if a.pre != nil { 527 a.cur.replacer = replacer 528 a.cur.parent = parent 529 a.cur.node = node 530 if !a.pre(&a.cur) { 531 return true 532 } 533 } 534 for x, el := range node.Columns { 535 if !a.rewriteRefOfColumnDefinition(node, el, func(idx int) replacerFunc { 536 return func(newNode, parent SQLNode) { 537 parent.(*AddColumns).Columns[idx] = newNode.(*ColumnDefinition) 538 } 539 }(x)) { 540 return false 541 } 542 } 543 if !a.rewriteRefOfColName(node, node.After, func(newNode, parent SQLNode) { 544 parent.(*AddColumns).After = newNode.(*ColName) 545 }) { 546 return false 547 } 548 if a.post != nil { 549 a.cur.replacer = replacer 550 a.cur.parent = parent 551 a.cur.node = node 552 if !a.post(&a.cur) { 553 return false 554 } 555 } 556 return true 557 } 558 func (a *application) rewriteRefOfAddConstraintDefinition(parent SQLNode, node *AddConstraintDefinition, replacer replacerFunc) bool { 559 if node == nil { 560 return true 561 } 562 if a.pre != nil { 563 a.cur.replacer = replacer 564 a.cur.parent = parent 565 a.cur.node = node 566 if !a.pre(&a.cur) { 567 return true 568 } 569 } 570 if !a.rewriteRefOfConstraintDefinition(node, node.ConstraintDefinition, func(newNode, parent SQLNode) { 571 parent.(*AddConstraintDefinition).ConstraintDefinition = newNode.(*ConstraintDefinition) 572 }) { 573 return false 574 } 575 if a.post != nil { 576 a.cur.replacer = replacer 577 a.cur.parent = parent 578 a.cur.node = node 579 if !a.post(&a.cur) { 580 return false 581 } 582 } 583 return true 584 } 585 func (a *application) rewriteRefOfAddIndexDefinition(parent SQLNode, node *AddIndexDefinition, replacer replacerFunc) bool { 586 if node == nil { 587 return true 588 } 589 if a.pre != nil { 590 a.cur.replacer = replacer 591 a.cur.parent = parent 592 a.cur.node = node 593 if !a.pre(&a.cur) { 594 return true 595 } 596 } 597 if !a.rewriteRefOfIndexDefinition(node, node.IndexDefinition, func(newNode, parent SQLNode) { 598 parent.(*AddIndexDefinition).IndexDefinition = newNode.(*IndexDefinition) 599 }) { 600 return false 601 } 602 if a.post != nil { 603 a.cur.replacer = replacer 604 a.cur.parent = parent 605 a.cur.node = node 606 if !a.post(&a.cur) { 607 return false 608 } 609 } 610 return true 611 } 612 func (a *application) rewriteRefOfAliasedExpr(parent SQLNode, node *AliasedExpr, replacer replacerFunc) bool { 613 if node == nil { 614 return true 615 } 616 if a.pre != nil { 617 a.cur.replacer = replacer 618 a.cur.parent = parent 619 a.cur.node = node 620 if !a.pre(&a.cur) { 621 return true 622 } 623 } 624 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 625 parent.(*AliasedExpr).Expr = newNode.(Expr) 626 }) { 627 return false 628 } 629 if !a.rewriteIdentifierCI(node, node.As, func(newNode, parent SQLNode) { 630 parent.(*AliasedExpr).As = newNode.(IdentifierCI) 631 }) { 632 return false 633 } 634 if a.post != nil { 635 a.cur.replacer = replacer 636 a.cur.parent = parent 637 a.cur.node = node 638 if !a.post(&a.cur) { 639 return false 640 } 641 } 642 return true 643 } 644 func (a *application) rewriteRefOfAliasedTableExpr(parent SQLNode, node *AliasedTableExpr, replacer replacerFunc) bool { 645 if node == nil { 646 return true 647 } 648 if a.pre != nil { 649 a.cur.replacer = replacer 650 a.cur.parent = parent 651 a.cur.node = node 652 if !a.pre(&a.cur) { 653 return true 654 } 655 } 656 if !a.rewriteSimpleTableExpr(node, node.Expr, func(newNode, parent SQLNode) { 657 parent.(*AliasedTableExpr).Expr = newNode.(SimpleTableExpr) 658 }) { 659 return false 660 } 661 if !a.rewritePartitions(node, node.Partitions, func(newNode, parent SQLNode) { 662 parent.(*AliasedTableExpr).Partitions = newNode.(Partitions) 663 }) { 664 return false 665 } 666 if !a.rewriteIdentifierCS(node, node.As, func(newNode, parent SQLNode) { 667 parent.(*AliasedTableExpr).As = newNode.(IdentifierCS) 668 }) { 669 return false 670 } 671 if !a.rewriteIndexHints(node, node.Hints, func(newNode, parent SQLNode) { 672 parent.(*AliasedTableExpr).Hints = newNode.(IndexHints) 673 }) { 674 return false 675 } 676 if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { 677 parent.(*AliasedTableExpr).Columns = newNode.(Columns) 678 }) { 679 return false 680 } 681 if a.post != nil { 682 a.cur.replacer = replacer 683 a.cur.parent = parent 684 a.cur.node = node 685 if !a.post(&a.cur) { 686 return false 687 } 688 } 689 return true 690 } 691 func (a *application) rewriteRefOfAlterCharset(parent SQLNode, node *AlterCharset, replacer replacerFunc) bool { 692 if node == nil { 693 return true 694 } 695 if a.pre != nil { 696 a.cur.replacer = replacer 697 a.cur.parent = parent 698 a.cur.node = node 699 if !a.pre(&a.cur) { 700 return true 701 } 702 } 703 if a.post != nil { 704 if a.pre == nil { 705 a.cur.replacer = replacer 706 a.cur.parent = parent 707 a.cur.node = node 708 } 709 if !a.post(&a.cur) { 710 return false 711 } 712 } 713 return true 714 } 715 func (a *application) rewriteRefOfAlterCheck(parent SQLNode, node *AlterCheck, replacer replacerFunc) bool { 716 if node == nil { 717 return true 718 } 719 if a.pre != nil { 720 a.cur.replacer = replacer 721 a.cur.parent = parent 722 a.cur.node = node 723 if !a.pre(&a.cur) { 724 return true 725 } 726 } 727 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 728 parent.(*AlterCheck).Name = newNode.(IdentifierCI) 729 }) { 730 return false 731 } 732 if a.post != nil { 733 a.cur.replacer = replacer 734 a.cur.parent = parent 735 a.cur.node = node 736 if !a.post(&a.cur) { 737 return false 738 } 739 } 740 return true 741 } 742 func (a *application) rewriteRefOfAlterColumn(parent SQLNode, node *AlterColumn, replacer replacerFunc) bool { 743 if node == nil { 744 return true 745 } 746 if a.pre != nil { 747 a.cur.replacer = replacer 748 a.cur.parent = parent 749 a.cur.node = node 750 if !a.pre(&a.cur) { 751 return true 752 } 753 } 754 if !a.rewriteRefOfColName(node, node.Column, func(newNode, parent SQLNode) { 755 parent.(*AlterColumn).Column = newNode.(*ColName) 756 }) { 757 return false 758 } 759 if !a.rewriteExpr(node, node.DefaultVal, func(newNode, parent SQLNode) { 760 parent.(*AlterColumn).DefaultVal = newNode.(Expr) 761 }) { 762 return false 763 } 764 if a.post != nil { 765 a.cur.replacer = replacer 766 a.cur.parent = parent 767 a.cur.node = node 768 if !a.post(&a.cur) { 769 return false 770 } 771 } 772 return true 773 } 774 func (a *application) rewriteRefOfAlterDatabase(parent SQLNode, node *AlterDatabase, replacer replacerFunc) bool { 775 if node == nil { 776 return true 777 } 778 if a.pre != nil { 779 a.cur.replacer = replacer 780 a.cur.parent = parent 781 a.cur.node = node 782 if !a.pre(&a.cur) { 783 return true 784 } 785 } 786 if !a.rewriteIdentifierCS(node, node.DBName, func(newNode, parent SQLNode) { 787 parent.(*AlterDatabase).DBName = newNode.(IdentifierCS) 788 }) { 789 return false 790 } 791 if a.post != nil { 792 a.cur.replacer = replacer 793 a.cur.parent = parent 794 a.cur.node = node 795 if !a.post(&a.cur) { 796 return false 797 } 798 } 799 return true 800 } 801 func (a *application) rewriteRefOfAlterIndex(parent SQLNode, node *AlterIndex, replacer replacerFunc) bool { 802 if node == nil { 803 return true 804 } 805 if a.pre != nil { 806 a.cur.replacer = replacer 807 a.cur.parent = parent 808 a.cur.node = node 809 if !a.pre(&a.cur) { 810 return true 811 } 812 } 813 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 814 parent.(*AlterIndex).Name = newNode.(IdentifierCI) 815 }) { 816 return false 817 } 818 if a.post != nil { 819 a.cur.replacer = replacer 820 a.cur.parent = parent 821 a.cur.node = node 822 if !a.post(&a.cur) { 823 return false 824 } 825 } 826 return true 827 } 828 func (a *application) rewriteRefOfAlterMigration(parent SQLNode, node *AlterMigration, replacer replacerFunc) bool { 829 if node == nil { 830 return true 831 } 832 if a.pre != nil { 833 a.cur.replacer = replacer 834 a.cur.parent = parent 835 a.cur.node = node 836 if !a.pre(&a.cur) { 837 return true 838 } 839 } 840 if !a.rewriteRefOfLiteral(node, node.Ratio, func(newNode, parent SQLNode) { 841 parent.(*AlterMigration).Ratio = newNode.(*Literal) 842 }) { 843 return false 844 } 845 if a.post != nil { 846 a.cur.replacer = replacer 847 a.cur.parent = parent 848 a.cur.node = node 849 if !a.post(&a.cur) { 850 return false 851 } 852 } 853 return true 854 } 855 func (a *application) rewriteRefOfAlterTable(parent SQLNode, node *AlterTable, replacer replacerFunc) bool { 856 if node == nil { 857 return true 858 } 859 if a.pre != nil { 860 a.cur.replacer = replacer 861 a.cur.parent = parent 862 a.cur.node = node 863 if !a.pre(&a.cur) { 864 return true 865 } 866 } 867 if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { 868 parent.(*AlterTable).Table = newNode.(TableName) 869 }) { 870 return false 871 } 872 for x, el := range node.AlterOptions { 873 if !a.rewriteAlterOption(node, el, func(idx int) replacerFunc { 874 return func(newNode, parent SQLNode) { 875 parent.(*AlterTable).AlterOptions[idx] = newNode.(AlterOption) 876 } 877 }(x)) { 878 return false 879 } 880 } 881 if !a.rewriteRefOfPartitionSpec(node, node.PartitionSpec, func(newNode, parent SQLNode) { 882 parent.(*AlterTable).PartitionSpec = newNode.(*PartitionSpec) 883 }) { 884 return false 885 } 886 if !a.rewriteRefOfPartitionOption(node, node.PartitionOption, func(newNode, parent SQLNode) { 887 parent.(*AlterTable).PartitionOption = newNode.(*PartitionOption) 888 }) { 889 return false 890 } 891 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 892 parent.(*AlterTable).Comments = newNode.(*ParsedComments) 893 }) { 894 return false 895 } 896 if a.post != nil { 897 a.cur.replacer = replacer 898 a.cur.parent = parent 899 a.cur.node = node 900 if !a.post(&a.cur) { 901 return false 902 } 903 } 904 return true 905 } 906 func (a *application) rewriteRefOfAlterView(parent SQLNode, node *AlterView, replacer replacerFunc) bool { 907 if node == nil { 908 return true 909 } 910 if a.pre != nil { 911 a.cur.replacer = replacer 912 a.cur.parent = parent 913 a.cur.node = node 914 if !a.pre(&a.cur) { 915 return true 916 } 917 } 918 if !a.rewriteTableName(node, node.ViewName, func(newNode, parent SQLNode) { 919 parent.(*AlterView).ViewName = newNode.(TableName) 920 }) { 921 return false 922 } 923 if !a.rewriteRefOfDefiner(node, node.Definer, func(newNode, parent SQLNode) { 924 parent.(*AlterView).Definer = newNode.(*Definer) 925 }) { 926 return false 927 } 928 if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { 929 parent.(*AlterView).Columns = newNode.(Columns) 930 }) { 931 return false 932 } 933 if !a.rewriteSelectStatement(node, node.Select, func(newNode, parent SQLNode) { 934 parent.(*AlterView).Select = newNode.(SelectStatement) 935 }) { 936 return false 937 } 938 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 939 parent.(*AlterView).Comments = newNode.(*ParsedComments) 940 }) { 941 return false 942 } 943 if a.post != nil { 944 a.cur.replacer = replacer 945 a.cur.parent = parent 946 a.cur.node = node 947 if !a.post(&a.cur) { 948 return false 949 } 950 } 951 return true 952 } 953 func (a *application) rewriteRefOfAlterVschema(parent SQLNode, node *AlterVschema, replacer replacerFunc) bool { 954 if node == nil { 955 return true 956 } 957 if a.pre != nil { 958 a.cur.replacer = replacer 959 a.cur.parent = parent 960 a.cur.node = node 961 if !a.pre(&a.cur) { 962 return true 963 } 964 } 965 if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { 966 parent.(*AlterVschema).Table = newNode.(TableName) 967 }) { 968 return false 969 } 970 if !a.rewriteRefOfVindexSpec(node, node.VindexSpec, func(newNode, parent SQLNode) { 971 parent.(*AlterVschema).VindexSpec = newNode.(*VindexSpec) 972 }) { 973 return false 974 } 975 for x, el := range node.VindexCols { 976 if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { 977 return func(newNode, parent SQLNode) { 978 parent.(*AlterVschema).VindexCols[idx] = newNode.(IdentifierCI) 979 } 980 }(x)) { 981 return false 982 } 983 } 984 if !a.rewriteRefOfAutoIncSpec(node, node.AutoIncSpec, func(newNode, parent SQLNode) { 985 parent.(*AlterVschema).AutoIncSpec = newNode.(*AutoIncSpec) 986 }) { 987 return false 988 } 989 if a.post != nil { 990 a.cur.replacer = replacer 991 a.cur.parent = parent 992 a.cur.node = node 993 if !a.post(&a.cur) { 994 return false 995 } 996 } 997 return true 998 } 999 func (a *application) rewriteRefOfAndExpr(parent SQLNode, node *AndExpr, replacer replacerFunc) bool { 1000 if node == nil { 1001 return true 1002 } 1003 if a.pre != nil { 1004 a.cur.replacer = replacer 1005 a.cur.parent = parent 1006 a.cur.node = node 1007 if !a.pre(&a.cur) { 1008 return true 1009 } 1010 } 1011 if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { 1012 parent.(*AndExpr).Left = newNode.(Expr) 1013 }) { 1014 return false 1015 } 1016 if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { 1017 parent.(*AndExpr).Right = newNode.(Expr) 1018 }) { 1019 return false 1020 } 1021 if a.post != nil { 1022 a.cur.replacer = replacer 1023 a.cur.parent = parent 1024 a.cur.node = node 1025 if !a.post(&a.cur) { 1026 return false 1027 } 1028 } 1029 return true 1030 } 1031 func (a *application) rewriteRefOfArgumentLessWindowExpr(parent SQLNode, node *ArgumentLessWindowExpr, replacer replacerFunc) bool { 1032 if node == nil { 1033 return true 1034 } 1035 if a.pre != nil { 1036 a.cur.replacer = replacer 1037 a.cur.parent = parent 1038 a.cur.node = node 1039 if !a.pre(&a.cur) { 1040 return true 1041 } 1042 } 1043 if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { 1044 parent.(*ArgumentLessWindowExpr).OverClause = newNode.(*OverClause) 1045 }) { 1046 return false 1047 } 1048 if a.post != nil { 1049 a.cur.replacer = replacer 1050 a.cur.parent = parent 1051 a.cur.node = node 1052 if !a.post(&a.cur) { 1053 return false 1054 } 1055 } 1056 return true 1057 } 1058 func (a *application) rewriteRefOfAutoIncSpec(parent SQLNode, node *AutoIncSpec, replacer replacerFunc) bool { 1059 if node == nil { 1060 return true 1061 } 1062 if a.pre != nil { 1063 a.cur.replacer = replacer 1064 a.cur.parent = parent 1065 a.cur.node = node 1066 if !a.pre(&a.cur) { 1067 return true 1068 } 1069 } 1070 if !a.rewriteIdentifierCI(node, node.Column, func(newNode, parent SQLNode) { 1071 parent.(*AutoIncSpec).Column = newNode.(IdentifierCI) 1072 }) { 1073 return false 1074 } 1075 if !a.rewriteTableName(node, node.Sequence, func(newNode, parent SQLNode) { 1076 parent.(*AutoIncSpec).Sequence = newNode.(TableName) 1077 }) { 1078 return false 1079 } 1080 if a.post != nil { 1081 a.cur.replacer = replacer 1082 a.cur.parent = parent 1083 a.cur.node = node 1084 if !a.post(&a.cur) { 1085 return false 1086 } 1087 } 1088 return true 1089 } 1090 func (a *application) rewriteRefOfAvg(parent SQLNode, node *Avg, replacer replacerFunc) bool { 1091 if node == nil { 1092 return true 1093 } 1094 if a.pre != nil { 1095 a.cur.replacer = replacer 1096 a.cur.parent = parent 1097 a.cur.node = node 1098 if !a.pre(&a.cur) { 1099 return true 1100 } 1101 } 1102 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 1103 parent.(*Avg).Arg = newNode.(Expr) 1104 }) { 1105 return false 1106 } 1107 if a.post != nil { 1108 a.cur.replacer = replacer 1109 a.cur.parent = parent 1110 a.cur.node = node 1111 if !a.post(&a.cur) { 1112 return false 1113 } 1114 } 1115 return true 1116 } 1117 func (a *application) rewriteRefOfBegin(parent SQLNode, node *Begin, replacer replacerFunc) bool { 1118 if node == nil { 1119 return true 1120 } 1121 if a.pre != nil { 1122 a.cur.replacer = replacer 1123 a.cur.parent = parent 1124 a.cur.node = node 1125 if !a.pre(&a.cur) { 1126 return true 1127 } 1128 } 1129 if a.post != nil { 1130 if a.pre == nil { 1131 a.cur.replacer = replacer 1132 a.cur.parent = parent 1133 a.cur.node = node 1134 } 1135 if !a.post(&a.cur) { 1136 return false 1137 } 1138 } 1139 return true 1140 } 1141 func (a *application) rewriteRefOfBetweenExpr(parent SQLNode, node *BetweenExpr, replacer replacerFunc) bool { 1142 if node == nil { 1143 return true 1144 } 1145 if a.pre != nil { 1146 a.cur.replacer = replacer 1147 a.cur.parent = parent 1148 a.cur.node = node 1149 if !a.pre(&a.cur) { 1150 return true 1151 } 1152 } 1153 if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { 1154 parent.(*BetweenExpr).Left = newNode.(Expr) 1155 }) { 1156 return false 1157 } 1158 if !a.rewriteExpr(node, node.From, func(newNode, parent SQLNode) { 1159 parent.(*BetweenExpr).From = newNode.(Expr) 1160 }) { 1161 return false 1162 } 1163 if !a.rewriteExpr(node, node.To, func(newNode, parent SQLNode) { 1164 parent.(*BetweenExpr).To = newNode.(Expr) 1165 }) { 1166 return false 1167 } 1168 if a.post != nil { 1169 a.cur.replacer = replacer 1170 a.cur.parent = parent 1171 a.cur.node = node 1172 if !a.post(&a.cur) { 1173 return false 1174 } 1175 } 1176 return true 1177 } 1178 func (a *application) rewriteRefOfBinaryExpr(parent SQLNode, node *BinaryExpr, replacer replacerFunc) bool { 1179 if node == nil { 1180 return true 1181 } 1182 if a.pre != nil { 1183 a.cur.replacer = replacer 1184 a.cur.parent = parent 1185 a.cur.node = node 1186 if !a.pre(&a.cur) { 1187 return true 1188 } 1189 } 1190 if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { 1191 parent.(*BinaryExpr).Left = newNode.(Expr) 1192 }) { 1193 return false 1194 } 1195 if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { 1196 parent.(*BinaryExpr).Right = newNode.(Expr) 1197 }) { 1198 return false 1199 } 1200 if a.post != nil { 1201 a.cur.replacer = replacer 1202 a.cur.parent = parent 1203 a.cur.node = node 1204 if !a.post(&a.cur) { 1205 return false 1206 } 1207 } 1208 return true 1209 } 1210 func (a *application) rewriteRefOfBitAnd(parent SQLNode, node *BitAnd, replacer replacerFunc) bool { 1211 if node == nil { 1212 return true 1213 } 1214 if a.pre != nil { 1215 a.cur.replacer = replacer 1216 a.cur.parent = parent 1217 a.cur.node = node 1218 if !a.pre(&a.cur) { 1219 return true 1220 } 1221 } 1222 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 1223 parent.(*BitAnd).Arg = newNode.(Expr) 1224 }) { 1225 return false 1226 } 1227 if a.post != nil { 1228 a.cur.replacer = replacer 1229 a.cur.parent = parent 1230 a.cur.node = node 1231 if !a.post(&a.cur) { 1232 return false 1233 } 1234 } 1235 return true 1236 } 1237 func (a *application) rewriteRefOfBitOr(parent SQLNode, node *BitOr, replacer replacerFunc) bool { 1238 if node == nil { 1239 return true 1240 } 1241 if a.pre != nil { 1242 a.cur.replacer = replacer 1243 a.cur.parent = parent 1244 a.cur.node = node 1245 if !a.pre(&a.cur) { 1246 return true 1247 } 1248 } 1249 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 1250 parent.(*BitOr).Arg = newNode.(Expr) 1251 }) { 1252 return false 1253 } 1254 if a.post != nil { 1255 a.cur.replacer = replacer 1256 a.cur.parent = parent 1257 a.cur.node = node 1258 if !a.post(&a.cur) { 1259 return false 1260 } 1261 } 1262 return true 1263 } 1264 func (a *application) rewriteRefOfBitXor(parent SQLNode, node *BitXor, replacer replacerFunc) bool { 1265 if node == nil { 1266 return true 1267 } 1268 if a.pre != nil { 1269 a.cur.replacer = replacer 1270 a.cur.parent = parent 1271 a.cur.node = node 1272 if !a.pre(&a.cur) { 1273 return true 1274 } 1275 } 1276 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 1277 parent.(*BitXor).Arg = newNode.(Expr) 1278 }) { 1279 return false 1280 } 1281 if a.post != nil { 1282 a.cur.replacer = replacer 1283 a.cur.parent = parent 1284 a.cur.node = node 1285 if !a.post(&a.cur) { 1286 return false 1287 } 1288 } 1289 return true 1290 } 1291 func (a *application) rewriteRefOfCallProc(parent SQLNode, node *CallProc, replacer replacerFunc) bool { 1292 if node == nil { 1293 return true 1294 } 1295 if a.pre != nil { 1296 a.cur.replacer = replacer 1297 a.cur.parent = parent 1298 a.cur.node = node 1299 if !a.pre(&a.cur) { 1300 return true 1301 } 1302 } 1303 if !a.rewriteTableName(node, node.Name, func(newNode, parent SQLNode) { 1304 parent.(*CallProc).Name = newNode.(TableName) 1305 }) { 1306 return false 1307 } 1308 if !a.rewriteExprs(node, node.Params, func(newNode, parent SQLNode) { 1309 parent.(*CallProc).Params = newNode.(Exprs) 1310 }) { 1311 return false 1312 } 1313 if a.post != nil { 1314 a.cur.replacer = replacer 1315 a.cur.parent = parent 1316 a.cur.node = node 1317 if !a.post(&a.cur) { 1318 return false 1319 } 1320 } 1321 return true 1322 } 1323 func (a *application) rewriteRefOfCaseExpr(parent SQLNode, node *CaseExpr, replacer replacerFunc) bool { 1324 if node == nil { 1325 return true 1326 } 1327 if a.pre != nil { 1328 a.cur.replacer = replacer 1329 a.cur.parent = parent 1330 a.cur.node = node 1331 if !a.pre(&a.cur) { 1332 return true 1333 } 1334 } 1335 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 1336 parent.(*CaseExpr).Expr = newNode.(Expr) 1337 }) { 1338 return false 1339 } 1340 for x, el := range node.Whens { 1341 if !a.rewriteRefOfWhen(node, el, func(idx int) replacerFunc { 1342 return func(newNode, parent SQLNode) { 1343 parent.(*CaseExpr).Whens[idx] = newNode.(*When) 1344 } 1345 }(x)) { 1346 return false 1347 } 1348 } 1349 if !a.rewriteExpr(node, node.Else, func(newNode, parent SQLNode) { 1350 parent.(*CaseExpr).Else = newNode.(Expr) 1351 }) { 1352 return false 1353 } 1354 if a.post != nil { 1355 a.cur.replacer = replacer 1356 a.cur.parent = parent 1357 a.cur.node = node 1358 if !a.post(&a.cur) { 1359 return false 1360 } 1361 } 1362 return true 1363 } 1364 func (a *application) rewriteRefOfCastExpr(parent SQLNode, node *CastExpr, replacer replacerFunc) bool { 1365 if node == nil { 1366 return true 1367 } 1368 if a.pre != nil { 1369 a.cur.replacer = replacer 1370 a.cur.parent = parent 1371 a.cur.node = node 1372 if !a.pre(&a.cur) { 1373 return true 1374 } 1375 } 1376 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 1377 parent.(*CastExpr).Expr = newNode.(Expr) 1378 }) { 1379 return false 1380 } 1381 if !a.rewriteRefOfConvertType(node, node.Type, func(newNode, parent SQLNode) { 1382 parent.(*CastExpr).Type = newNode.(*ConvertType) 1383 }) { 1384 return false 1385 } 1386 if a.post != nil { 1387 a.cur.replacer = replacer 1388 a.cur.parent = parent 1389 a.cur.node = node 1390 if !a.post(&a.cur) { 1391 return false 1392 } 1393 } 1394 return true 1395 } 1396 func (a *application) rewriteRefOfChangeColumn(parent SQLNode, node *ChangeColumn, replacer replacerFunc) bool { 1397 if node == nil { 1398 return true 1399 } 1400 if a.pre != nil { 1401 a.cur.replacer = replacer 1402 a.cur.parent = parent 1403 a.cur.node = node 1404 if !a.pre(&a.cur) { 1405 return true 1406 } 1407 } 1408 if !a.rewriteRefOfColName(node, node.OldColumn, func(newNode, parent SQLNode) { 1409 parent.(*ChangeColumn).OldColumn = newNode.(*ColName) 1410 }) { 1411 return false 1412 } 1413 if !a.rewriteRefOfColumnDefinition(node, node.NewColDefinition, func(newNode, parent SQLNode) { 1414 parent.(*ChangeColumn).NewColDefinition = newNode.(*ColumnDefinition) 1415 }) { 1416 return false 1417 } 1418 if !a.rewriteRefOfColName(node, node.After, func(newNode, parent SQLNode) { 1419 parent.(*ChangeColumn).After = newNode.(*ColName) 1420 }) { 1421 return false 1422 } 1423 if a.post != nil { 1424 a.cur.replacer = replacer 1425 a.cur.parent = parent 1426 a.cur.node = node 1427 if !a.post(&a.cur) { 1428 return false 1429 } 1430 } 1431 return true 1432 } 1433 func (a *application) rewriteRefOfCharExpr(parent SQLNode, node *CharExpr, replacer replacerFunc) bool { 1434 if node == nil { 1435 return true 1436 } 1437 if a.pre != nil { 1438 a.cur.replacer = replacer 1439 a.cur.parent = parent 1440 a.cur.node = node 1441 if !a.pre(&a.cur) { 1442 return true 1443 } 1444 } 1445 if !a.rewriteExprs(node, node.Exprs, func(newNode, parent SQLNode) { 1446 parent.(*CharExpr).Exprs = newNode.(Exprs) 1447 }) { 1448 return false 1449 } 1450 if a.post != nil { 1451 a.cur.replacer = replacer 1452 a.cur.parent = parent 1453 a.cur.node = node 1454 if !a.post(&a.cur) { 1455 return false 1456 } 1457 } 1458 return true 1459 } 1460 func (a *application) rewriteRefOfCheckConstraintDefinition(parent SQLNode, node *CheckConstraintDefinition, replacer replacerFunc) bool { 1461 if node == nil { 1462 return true 1463 } 1464 if a.pre != nil { 1465 a.cur.replacer = replacer 1466 a.cur.parent = parent 1467 a.cur.node = node 1468 if !a.pre(&a.cur) { 1469 return true 1470 } 1471 } 1472 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 1473 parent.(*CheckConstraintDefinition).Expr = newNode.(Expr) 1474 }) { 1475 return false 1476 } 1477 if a.post != nil { 1478 a.cur.replacer = replacer 1479 a.cur.parent = parent 1480 a.cur.node = node 1481 if !a.post(&a.cur) { 1482 return false 1483 } 1484 } 1485 return true 1486 } 1487 func (a *application) rewriteRefOfColName(parent SQLNode, node *ColName, replacer replacerFunc) bool { 1488 if node == nil { 1489 return true 1490 } 1491 if a.pre != nil { 1492 a.cur.replacer = replacer 1493 a.cur.parent = parent 1494 a.cur.node = node 1495 if !a.pre(&a.cur) { 1496 return true 1497 } 1498 } 1499 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 1500 parent.(*ColName).Name = newNode.(IdentifierCI) 1501 }) { 1502 return false 1503 } 1504 if !a.rewriteTableName(node, node.Qualifier, func(newNode, parent SQLNode) { 1505 parent.(*ColName).Qualifier = newNode.(TableName) 1506 }) { 1507 return false 1508 } 1509 if a.post != nil { 1510 a.cur.replacer = replacer 1511 a.cur.parent = parent 1512 a.cur.node = node 1513 if !a.post(&a.cur) { 1514 return false 1515 } 1516 } 1517 return true 1518 } 1519 func (a *application) rewriteRefOfCollateExpr(parent SQLNode, node *CollateExpr, replacer replacerFunc) bool { 1520 if node == nil { 1521 return true 1522 } 1523 if a.pre != nil { 1524 a.cur.replacer = replacer 1525 a.cur.parent = parent 1526 a.cur.node = node 1527 if !a.pre(&a.cur) { 1528 return true 1529 } 1530 } 1531 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 1532 parent.(*CollateExpr).Expr = newNode.(Expr) 1533 }) { 1534 return false 1535 } 1536 if a.post != nil { 1537 a.cur.replacer = replacer 1538 a.cur.parent = parent 1539 a.cur.node = node 1540 if !a.post(&a.cur) { 1541 return false 1542 } 1543 } 1544 return true 1545 } 1546 func (a *application) rewriteRefOfColumnDefinition(parent SQLNode, node *ColumnDefinition, replacer replacerFunc) bool { 1547 if node == nil { 1548 return true 1549 } 1550 if a.pre != nil { 1551 a.cur.replacer = replacer 1552 a.cur.parent = parent 1553 a.cur.node = node 1554 if !a.pre(&a.cur) { 1555 return true 1556 } 1557 } 1558 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 1559 parent.(*ColumnDefinition).Name = newNode.(IdentifierCI) 1560 }) { 1561 return false 1562 } 1563 if !a.rewriteRefOfColumnType(node, node.Type, func(newNode, parent SQLNode) { 1564 parent.(*ColumnDefinition).Type = newNode.(*ColumnType) 1565 }) { 1566 return false 1567 } 1568 if a.post != nil { 1569 a.cur.replacer = replacer 1570 a.cur.parent = parent 1571 a.cur.node = node 1572 if !a.post(&a.cur) { 1573 return false 1574 } 1575 } 1576 return true 1577 } 1578 func (a *application) rewriteRefOfColumnType(parent SQLNode, node *ColumnType, replacer replacerFunc) bool { 1579 if node == nil { 1580 return true 1581 } 1582 if a.pre != nil { 1583 a.cur.replacer = replacer 1584 a.cur.parent = parent 1585 a.cur.node = node 1586 if !a.pre(&a.cur) { 1587 return true 1588 } 1589 } 1590 if !a.rewriteRefOfLiteral(node, node.Length, func(newNode, parent SQLNode) { 1591 parent.(*ColumnType).Length = newNode.(*Literal) 1592 }) { 1593 return false 1594 } 1595 if !a.rewriteRefOfLiteral(node, node.Scale, func(newNode, parent SQLNode) { 1596 parent.(*ColumnType).Scale = newNode.(*Literal) 1597 }) { 1598 return false 1599 } 1600 if a.post != nil { 1601 a.cur.replacer = replacer 1602 a.cur.parent = parent 1603 a.cur.node = node 1604 if !a.post(&a.cur) { 1605 return false 1606 } 1607 } 1608 return true 1609 } 1610 func (a *application) rewriteColumns(parent SQLNode, node Columns, replacer replacerFunc) bool { 1611 if node == nil { 1612 return true 1613 } 1614 if a.pre != nil { 1615 a.cur.replacer = replacer 1616 a.cur.parent = parent 1617 a.cur.node = node 1618 kontinue := !a.pre(&a.cur) 1619 if a.cur.revisit { 1620 node = a.cur.node.(Columns) 1621 a.cur.revisit = false 1622 return a.rewriteColumns(parent, node, replacer) 1623 } 1624 if kontinue { 1625 return true 1626 } 1627 } 1628 for x, el := range node { 1629 if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { 1630 return func(newNode, parent SQLNode) { 1631 parent.(Columns)[idx] = newNode.(IdentifierCI) 1632 } 1633 }(x)) { 1634 return false 1635 } 1636 } 1637 if a.post != nil { 1638 a.cur.replacer = replacer 1639 a.cur.parent = parent 1640 a.cur.node = node 1641 if !a.post(&a.cur) { 1642 return false 1643 } 1644 } 1645 return true 1646 } 1647 func (a *application) rewriteRefOfCommentOnly(parent SQLNode, node *CommentOnly, replacer replacerFunc) bool { 1648 if node == nil { 1649 return true 1650 } 1651 if a.pre != nil { 1652 a.cur.replacer = replacer 1653 a.cur.parent = parent 1654 a.cur.node = node 1655 if !a.pre(&a.cur) { 1656 return true 1657 } 1658 } 1659 if a.post != nil { 1660 if a.pre == nil { 1661 a.cur.replacer = replacer 1662 a.cur.parent = parent 1663 a.cur.node = node 1664 } 1665 if !a.post(&a.cur) { 1666 return false 1667 } 1668 } 1669 return true 1670 } 1671 func (a *application) rewriteRefOfCommit(parent SQLNode, node *Commit, replacer replacerFunc) bool { 1672 if node == nil { 1673 return true 1674 } 1675 if a.pre != nil { 1676 a.cur.replacer = replacer 1677 a.cur.parent = parent 1678 a.cur.node = node 1679 if !a.pre(&a.cur) { 1680 return true 1681 } 1682 } 1683 if a.post != nil { 1684 if a.pre == nil { 1685 a.cur.replacer = replacer 1686 a.cur.parent = parent 1687 a.cur.node = node 1688 } 1689 if !a.post(&a.cur) { 1690 return false 1691 } 1692 } 1693 return true 1694 } 1695 func (a *application) rewriteRefOfCommonTableExpr(parent SQLNode, node *CommonTableExpr, replacer replacerFunc) bool { 1696 if node == nil { 1697 return true 1698 } 1699 if a.pre != nil { 1700 a.cur.replacer = replacer 1701 a.cur.parent = parent 1702 a.cur.node = node 1703 if !a.pre(&a.cur) { 1704 return true 1705 } 1706 } 1707 if !a.rewriteIdentifierCS(node, node.ID, func(newNode, parent SQLNode) { 1708 parent.(*CommonTableExpr).ID = newNode.(IdentifierCS) 1709 }) { 1710 return false 1711 } 1712 if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { 1713 parent.(*CommonTableExpr).Columns = newNode.(Columns) 1714 }) { 1715 return false 1716 } 1717 if !a.rewriteRefOfSubquery(node, node.Subquery, func(newNode, parent SQLNode) { 1718 parent.(*CommonTableExpr).Subquery = newNode.(*Subquery) 1719 }) { 1720 return false 1721 } 1722 if a.post != nil { 1723 a.cur.replacer = replacer 1724 a.cur.parent = parent 1725 a.cur.node = node 1726 if !a.post(&a.cur) { 1727 return false 1728 } 1729 } 1730 return true 1731 } 1732 func (a *application) rewriteRefOfComparisonExpr(parent SQLNode, node *ComparisonExpr, replacer replacerFunc) bool { 1733 if node == nil { 1734 return true 1735 } 1736 if a.pre != nil { 1737 a.cur.replacer = replacer 1738 a.cur.parent = parent 1739 a.cur.node = node 1740 if !a.pre(&a.cur) { 1741 return true 1742 } 1743 } 1744 if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { 1745 parent.(*ComparisonExpr).Left = newNode.(Expr) 1746 }) { 1747 return false 1748 } 1749 if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { 1750 parent.(*ComparisonExpr).Right = newNode.(Expr) 1751 }) { 1752 return false 1753 } 1754 if !a.rewriteExpr(node, node.Escape, func(newNode, parent SQLNode) { 1755 parent.(*ComparisonExpr).Escape = newNode.(Expr) 1756 }) { 1757 return false 1758 } 1759 if a.post != nil { 1760 a.cur.replacer = replacer 1761 a.cur.parent = parent 1762 a.cur.node = node 1763 if !a.post(&a.cur) { 1764 return false 1765 } 1766 } 1767 return true 1768 } 1769 func (a *application) rewriteRefOfConstraintDefinition(parent SQLNode, node *ConstraintDefinition, replacer replacerFunc) bool { 1770 if node == nil { 1771 return true 1772 } 1773 if a.pre != nil { 1774 a.cur.replacer = replacer 1775 a.cur.parent = parent 1776 a.cur.node = node 1777 if !a.pre(&a.cur) { 1778 return true 1779 } 1780 } 1781 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 1782 parent.(*ConstraintDefinition).Name = newNode.(IdentifierCI) 1783 }) { 1784 return false 1785 } 1786 if !a.rewriteConstraintInfo(node, node.Details, func(newNode, parent SQLNode) { 1787 parent.(*ConstraintDefinition).Details = newNode.(ConstraintInfo) 1788 }) { 1789 return false 1790 } 1791 if a.post != nil { 1792 a.cur.replacer = replacer 1793 a.cur.parent = parent 1794 a.cur.node = node 1795 if !a.post(&a.cur) { 1796 return false 1797 } 1798 } 1799 return true 1800 } 1801 func (a *application) rewriteRefOfConvertExpr(parent SQLNode, node *ConvertExpr, replacer replacerFunc) bool { 1802 if node == nil { 1803 return true 1804 } 1805 if a.pre != nil { 1806 a.cur.replacer = replacer 1807 a.cur.parent = parent 1808 a.cur.node = node 1809 if !a.pre(&a.cur) { 1810 return true 1811 } 1812 } 1813 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 1814 parent.(*ConvertExpr).Expr = newNode.(Expr) 1815 }) { 1816 return false 1817 } 1818 if !a.rewriteRefOfConvertType(node, node.Type, func(newNode, parent SQLNode) { 1819 parent.(*ConvertExpr).Type = newNode.(*ConvertType) 1820 }) { 1821 return false 1822 } 1823 if a.post != nil { 1824 a.cur.replacer = replacer 1825 a.cur.parent = parent 1826 a.cur.node = node 1827 if !a.post(&a.cur) { 1828 return false 1829 } 1830 } 1831 return true 1832 } 1833 func (a *application) rewriteRefOfConvertType(parent SQLNode, node *ConvertType, replacer replacerFunc) bool { 1834 if node == nil { 1835 return true 1836 } 1837 if a.pre != nil { 1838 a.cur.replacer = replacer 1839 a.cur.parent = parent 1840 a.cur.node = node 1841 if !a.pre(&a.cur) { 1842 return true 1843 } 1844 } 1845 if !a.rewriteRefOfLiteral(node, node.Length, func(newNode, parent SQLNode) { 1846 parent.(*ConvertType).Length = newNode.(*Literal) 1847 }) { 1848 return false 1849 } 1850 if !a.rewriteRefOfLiteral(node, node.Scale, func(newNode, parent SQLNode) { 1851 parent.(*ConvertType).Scale = newNode.(*Literal) 1852 }) { 1853 return false 1854 } 1855 if a.post != nil { 1856 a.cur.replacer = replacer 1857 a.cur.parent = parent 1858 a.cur.node = node 1859 if !a.post(&a.cur) { 1860 return false 1861 } 1862 } 1863 return true 1864 } 1865 func (a *application) rewriteRefOfConvertUsingExpr(parent SQLNode, node *ConvertUsingExpr, replacer replacerFunc) bool { 1866 if node == nil { 1867 return true 1868 } 1869 if a.pre != nil { 1870 a.cur.replacer = replacer 1871 a.cur.parent = parent 1872 a.cur.node = node 1873 if !a.pre(&a.cur) { 1874 return true 1875 } 1876 } 1877 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 1878 parent.(*ConvertUsingExpr).Expr = newNode.(Expr) 1879 }) { 1880 return false 1881 } 1882 if a.post != nil { 1883 a.cur.replacer = replacer 1884 a.cur.parent = parent 1885 a.cur.node = node 1886 if !a.post(&a.cur) { 1887 return false 1888 } 1889 } 1890 return true 1891 } 1892 func (a *application) rewriteRefOfCount(parent SQLNode, node *Count, replacer replacerFunc) bool { 1893 if node == nil { 1894 return true 1895 } 1896 if a.pre != nil { 1897 a.cur.replacer = replacer 1898 a.cur.parent = parent 1899 a.cur.node = node 1900 if !a.pre(&a.cur) { 1901 return true 1902 } 1903 } 1904 if !a.rewriteExprs(node, node.Args, func(newNode, parent SQLNode) { 1905 parent.(*Count).Args = newNode.(Exprs) 1906 }) { 1907 return false 1908 } 1909 if a.post != nil { 1910 a.cur.replacer = replacer 1911 a.cur.parent = parent 1912 a.cur.node = node 1913 if !a.post(&a.cur) { 1914 return false 1915 } 1916 } 1917 return true 1918 } 1919 func (a *application) rewriteRefOfCountStar(parent SQLNode, node *CountStar, replacer replacerFunc) bool { 1920 if node == nil { 1921 return true 1922 } 1923 if a.pre != nil { 1924 a.cur.replacer = replacer 1925 a.cur.parent = parent 1926 a.cur.node = node 1927 if !a.pre(&a.cur) { 1928 return true 1929 } 1930 } 1931 if a.post != nil { 1932 if a.pre == nil { 1933 a.cur.replacer = replacer 1934 a.cur.parent = parent 1935 a.cur.node = node 1936 } 1937 if !a.post(&a.cur) { 1938 return false 1939 } 1940 } 1941 return true 1942 } 1943 func (a *application) rewriteRefOfCreateDatabase(parent SQLNode, node *CreateDatabase, replacer replacerFunc) bool { 1944 if node == nil { 1945 return true 1946 } 1947 if a.pre != nil { 1948 a.cur.replacer = replacer 1949 a.cur.parent = parent 1950 a.cur.node = node 1951 if !a.pre(&a.cur) { 1952 return true 1953 } 1954 } 1955 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 1956 parent.(*CreateDatabase).Comments = newNode.(*ParsedComments) 1957 }) { 1958 return false 1959 } 1960 if !a.rewriteIdentifierCS(node, node.DBName, func(newNode, parent SQLNode) { 1961 parent.(*CreateDatabase).DBName = newNode.(IdentifierCS) 1962 }) { 1963 return false 1964 } 1965 if a.post != nil { 1966 a.cur.replacer = replacer 1967 a.cur.parent = parent 1968 a.cur.node = node 1969 if !a.post(&a.cur) { 1970 return false 1971 } 1972 } 1973 return true 1974 } 1975 func (a *application) rewriteRefOfCreateTable(parent SQLNode, node *CreateTable, replacer replacerFunc) bool { 1976 if node == nil { 1977 return true 1978 } 1979 if a.pre != nil { 1980 a.cur.replacer = replacer 1981 a.cur.parent = parent 1982 a.cur.node = node 1983 if !a.pre(&a.cur) { 1984 return true 1985 } 1986 } 1987 if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { 1988 parent.(*CreateTable).Table = newNode.(TableName) 1989 }) { 1990 return false 1991 } 1992 if !a.rewriteRefOfTableSpec(node, node.TableSpec, func(newNode, parent SQLNode) { 1993 parent.(*CreateTable).TableSpec = newNode.(*TableSpec) 1994 }) { 1995 return false 1996 } 1997 if !a.rewriteRefOfOptLike(node, node.OptLike, func(newNode, parent SQLNode) { 1998 parent.(*CreateTable).OptLike = newNode.(*OptLike) 1999 }) { 2000 return false 2001 } 2002 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 2003 parent.(*CreateTable).Comments = newNode.(*ParsedComments) 2004 }) { 2005 return false 2006 } 2007 if a.post != nil { 2008 a.cur.replacer = replacer 2009 a.cur.parent = parent 2010 a.cur.node = node 2011 if !a.post(&a.cur) { 2012 return false 2013 } 2014 } 2015 return true 2016 } 2017 func (a *application) rewriteRefOfCreateView(parent SQLNode, node *CreateView, replacer replacerFunc) bool { 2018 if node == nil { 2019 return true 2020 } 2021 if a.pre != nil { 2022 a.cur.replacer = replacer 2023 a.cur.parent = parent 2024 a.cur.node = node 2025 if !a.pre(&a.cur) { 2026 return true 2027 } 2028 } 2029 if !a.rewriteTableName(node, node.ViewName, func(newNode, parent SQLNode) { 2030 parent.(*CreateView).ViewName = newNode.(TableName) 2031 }) { 2032 return false 2033 } 2034 if !a.rewriteRefOfDefiner(node, node.Definer, func(newNode, parent SQLNode) { 2035 parent.(*CreateView).Definer = newNode.(*Definer) 2036 }) { 2037 return false 2038 } 2039 if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { 2040 parent.(*CreateView).Columns = newNode.(Columns) 2041 }) { 2042 return false 2043 } 2044 if !a.rewriteSelectStatement(node, node.Select, func(newNode, parent SQLNode) { 2045 parent.(*CreateView).Select = newNode.(SelectStatement) 2046 }) { 2047 return false 2048 } 2049 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 2050 parent.(*CreateView).Comments = newNode.(*ParsedComments) 2051 }) { 2052 return false 2053 } 2054 if a.post != nil { 2055 a.cur.replacer = replacer 2056 a.cur.parent = parent 2057 a.cur.node = node 2058 if !a.post(&a.cur) { 2059 return false 2060 } 2061 } 2062 return true 2063 } 2064 func (a *application) rewriteRefOfCurTimeFuncExpr(parent SQLNode, node *CurTimeFuncExpr, replacer replacerFunc) bool { 2065 if node == nil { 2066 return true 2067 } 2068 if a.pre != nil { 2069 a.cur.replacer = replacer 2070 a.cur.parent = parent 2071 a.cur.node = node 2072 if !a.pre(&a.cur) { 2073 return true 2074 } 2075 } 2076 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 2077 parent.(*CurTimeFuncExpr).Name = newNode.(IdentifierCI) 2078 }) { 2079 return false 2080 } 2081 if !a.rewriteExpr(node, node.Fsp, func(newNode, parent SQLNode) { 2082 parent.(*CurTimeFuncExpr).Fsp = newNode.(Expr) 2083 }) { 2084 return false 2085 } 2086 if a.post != nil { 2087 a.cur.replacer = replacer 2088 a.cur.parent = parent 2089 a.cur.node = node 2090 if !a.post(&a.cur) { 2091 return false 2092 } 2093 } 2094 return true 2095 } 2096 func (a *application) rewriteRefOfDeallocateStmt(parent SQLNode, node *DeallocateStmt, replacer replacerFunc) bool { 2097 if node == nil { 2098 return true 2099 } 2100 if a.pre != nil { 2101 a.cur.replacer = replacer 2102 a.cur.parent = parent 2103 a.cur.node = node 2104 if !a.pre(&a.cur) { 2105 return true 2106 } 2107 } 2108 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 2109 parent.(*DeallocateStmt).Comments = newNode.(*ParsedComments) 2110 }) { 2111 return false 2112 } 2113 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 2114 parent.(*DeallocateStmt).Name = newNode.(IdentifierCI) 2115 }) { 2116 return false 2117 } 2118 if a.post != nil { 2119 a.cur.replacer = replacer 2120 a.cur.parent = parent 2121 a.cur.node = node 2122 if !a.post(&a.cur) { 2123 return false 2124 } 2125 } 2126 return true 2127 } 2128 func (a *application) rewriteRefOfDefault(parent SQLNode, node *Default, replacer replacerFunc) bool { 2129 if node == nil { 2130 return true 2131 } 2132 if a.pre != nil { 2133 a.cur.replacer = replacer 2134 a.cur.parent = parent 2135 a.cur.node = node 2136 if !a.pre(&a.cur) { 2137 return true 2138 } 2139 } 2140 if a.post != nil { 2141 if a.pre == nil { 2142 a.cur.replacer = replacer 2143 a.cur.parent = parent 2144 a.cur.node = node 2145 } 2146 if !a.post(&a.cur) { 2147 return false 2148 } 2149 } 2150 return true 2151 } 2152 func (a *application) rewriteRefOfDefiner(parent SQLNode, node *Definer, replacer replacerFunc) bool { 2153 if node == nil { 2154 return true 2155 } 2156 if a.pre != nil { 2157 a.cur.replacer = replacer 2158 a.cur.parent = parent 2159 a.cur.node = node 2160 if !a.pre(&a.cur) { 2161 return true 2162 } 2163 } 2164 if a.post != nil { 2165 if a.pre == nil { 2166 a.cur.replacer = replacer 2167 a.cur.parent = parent 2168 a.cur.node = node 2169 } 2170 if !a.post(&a.cur) { 2171 return false 2172 } 2173 } 2174 return true 2175 } 2176 func (a *application) rewriteRefOfDelete(parent SQLNode, node *Delete, replacer replacerFunc) bool { 2177 if node == nil { 2178 return true 2179 } 2180 if a.pre != nil { 2181 a.cur.replacer = replacer 2182 a.cur.parent = parent 2183 a.cur.node = node 2184 if !a.pre(&a.cur) { 2185 return true 2186 } 2187 } 2188 if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { 2189 parent.(*Delete).With = newNode.(*With) 2190 }) { 2191 return false 2192 } 2193 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 2194 parent.(*Delete).Comments = newNode.(*ParsedComments) 2195 }) { 2196 return false 2197 } 2198 if !a.rewriteTableNames(node, node.Targets, func(newNode, parent SQLNode) { 2199 parent.(*Delete).Targets = newNode.(TableNames) 2200 }) { 2201 return false 2202 } 2203 if !a.rewriteTableExprs(node, node.TableExprs, func(newNode, parent SQLNode) { 2204 parent.(*Delete).TableExprs = newNode.(TableExprs) 2205 }) { 2206 return false 2207 } 2208 if !a.rewritePartitions(node, node.Partitions, func(newNode, parent SQLNode) { 2209 parent.(*Delete).Partitions = newNode.(Partitions) 2210 }) { 2211 return false 2212 } 2213 if !a.rewriteRefOfWhere(node, node.Where, func(newNode, parent SQLNode) { 2214 parent.(*Delete).Where = newNode.(*Where) 2215 }) { 2216 return false 2217 } 2218 if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { 2219 parent.(*Delete).OrderBy = newNode.(OrderBy) 2220 }) { 2221 return false 2222 } 2223 if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { 2224 parent.(*Delete).Limit = newNode.(*Limit) 2225 }) { 2226 return false 2227 } 2228 if a.post != nil { 2229 a.cur.replacer = replacer 2230 a.cur.parent = parent 2231 a.cur.node = node 2232 if !a.post(&a.cur) { 2233 return false 2234 } 2235 } 2236 return true 2237 } 2238 func (a *application) rewriteRefOfDerivedTable(parent SQLNode, node *DerivedTable, replacer replacerFunc) bool { 2239 if node == nil { 2240 return true 2241 } 2242 if a.pre != nil { 2243 a.cur.replacer = replacer 2244 a.cur.parent = parent 2245 a.cur.node = node 2246 if !a.pre(&a.cur) { 2247 return true 2248 } 2249 } 2250 if !a.rewriteSelectStatement(node, node.Select, func(newNode, parent SQLNode) { 2251 parent.(*DerivedTable).Select = newNode.(SelectStatement) 2252 }) { 2253 return false 2254 } 2255 if a.post != nil { 2256 a.cur.replacer = replacer 2257 a.cur.parent = parent 2258 a.cur.node = node 2259 if !a.post(&a.cur) { 2260 return false 2261 } 2262 } 2263 return true 2264 } 2265 func (a *application) rewriteRefOfDropColumn(parent SQLNode, node *DropColumn, replacer replacerFunc) bool { 2266 if node == nil { 2267 return true 2268 } 2269 if a.pre != nil { 2270 a.cur.replacer = replacer 2271 a.cur.parent = parent 2272 a.cur.node = node 2273 if !a.pre(&a.cur) { 2274 return true 2275 } 2276 } 2277 if !a.rewriteRefOfColName(node, node.Name, func(newNode, parent SQLNode) { 2278 parent.(*DropColumn).Name = newNode.(*ColName) 2279 }) { 2280 return false 2281 } 2282 if a.post != nil { 2283 a.cur.replacer = replacer 2284 a.cur.parent = parent 2285 a.cur.node = node 2286 if !a.post(&a.cur) { 2287 return false 2288 } 2289 } 2290 return true 2291 } 2292 func (a *application) rewriteRefOfDropDatabase(parent SQLNode, node *DropDatabase, replacer replacerFunc) bool { 2293 if node == nil { 2294 return true 2295 } 2296 if a.pre != nil { 2297 a.cur.replacer = replacer 2298 a.cur.parent = parent 2299 a.cur.node = node 2300 if !a.pre(&a.cur) { 2301 return true 2302 } 2303 } 2304 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 2305 parent.(*DropDatabase).Comments = newNode.(*ParsedComments) 2306 }) { 2307 return false 2308 } 2309 if !a.rewriteIdentifierCS(node, node.DBName, func(newNode, parent SQLNode) { 2310 parent.(*DropDatabase).DBName = newNode.(IdentifierCS) 2311 }) { 2312 return false 2313 } 2314 if a.post != nil { 2315 a.cur.replacer = replacer 2316 a.cur.parent = parent 2317 a.cur.node = node 2318 if !a.post(&a.cur) { 2319 return false 2320 } 2321 } 2322 return true 2323 } 2324 func (a *application) rewriteRefOfDropKey(parent SQLNode, node *DropKey, replacer replacerFunc) bool { 2325 if node == nil { 2326 return true 2327 } 2328 if a.pre != nil { 2329 a.cur.replacer = replacer 2330 a.cur.parent = parent 2331 a.cur.node = node 2332 if !a.pre(&a.cur) { 2333 return true 2334 } 2335 } 2336 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 2337 parent.(*DropKey).Name = newNode.(IdentifierCI) 2338 }) { 2339 return false 2340 } 2341 if a.post != nil { 2342 a.cur.replacer = replacer 2343 a.cur.parent = parent 2344 a.cur.node = node 2345 if !a.post(&a.cur) { 2346 return false 2347 } 2348 } 2349 return true 2350 } 2351 func (a *application) rewriteRefOfDropTable(parent SQLNode, node *DropTable, replacer replacerFunc) bool { 2352 if node == nil { 2353 return true 2354 } 2355 if a.pre != nil { 2356 a.cur.replacer = replacer 2357 a.cur.parent = parent 2358 a.cur.node = node 2359 if !a.pre(&a.cur) { 2360 return true 2361 } 2362 } 2363 if !a.rewriteTableNames(node, node.FromTables, func(newNode, parent SQLNode) { 2364 parent.(*DropTable).FromTables = newNode.(TableNames) 2365 }) { 2366 return false 2367 } 2368 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 2369 parent.(*DropTable).Comments = newNode.(*ParsedComments) 2370 }) { 2371 return false 2372 } 2373 if a.post != nil { 2374 a.cur.replacer = replacer 2375 a.cur.parent = parent 2376 a.cur.node = node 2377 if !a.post(&a.cur) { 2378 return false 2379 } 2380 } 2381 return true 2382 } 2383 func (a *application) rewriteRefOfDropView(parent SQLNode, node *DropView, replacer replacerFunc) bool { 2384 if node == nil { 2385 return true 2386 } 2387 if a.pre != nil { 2388 a.cur.replacer = replacer 2389 a.cur.parent = parent 2390 a.cur.node = node 2391 if !a.pre(&a.cur) { 2392 return true 2393 } 2394 } 2395 if !a.rewriteTableNames(node, node.FromTables, func(newNode, parent SQLNode) { 2396 parent.(*DropView).FromTables = newNode.(TableNames) 2397 }) { 2398 return false 2399 } 2400 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 2401 parent.(*DropView).Comments = newNode.(*ParsedComments) 2402 }) { 2403 return false 2404 } 2405 if a.post != nil { 2406 a.cur.replacer = replacer 2407 a.cur.parent = parent 2408 a.cur.node = node 2409 if !a.post(&a.cur) { 2410 return false 2411 } 2412 } 2413 return true 2414 } 2415 func (a *application) rewriteRefOfExecuteStmt(parent SQLNode, node *ExecuteStmt, replacer replacerFunc) bool { 2416 if node == nil { 2417 return true 2418 } 2419 if a.pre != nil { 2420 a.cur.replacer = replacer 2421 a.cur.parent = parent 2422 a.cur.node = node 2423 if !a.pre(&a.cur) { 2424 return true 2425 } 2426 } 2427 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 2428 parent.(*ExecuteStmt).Name = newNode.(IdentifierCI) 2429 }) { 2430 return false 2431 } 2432 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 2433 parent.(*ExecuteStmt).Comments = newNode.(*ParsedComments) 2434 }) { 2435 return false 2436 } 2437 for x, el := range node.Arguments { 2438 if !a.rewriteRefOfVariable(node, el, func(idx int) replacerFunc { 2439 return func(newNode, parent SQLNode) { 2440 parent.(*ExecuteStmt).Arguments[idx] = newNode.(*Variable) 2441 } 2442 }(x)) { 2443 return false 2444 } 2445 } 2446 if a.post != nil { 2447 a.cur.replacer = replacer 2448 a.cur.parent = parent 2449 a.cur.node = node 2450 if !a.post(&a.cur) { 2451 return false 2452 } 2453 } 2454 return true 2455 } 2456 func (a *application) rewriteRefOfExistsExpr(parent SQLNode, node *ExistsExpr, replacer replacerFunc) bool { 2457 if node == nil { 2458 return true 2459 } 2460 if a.pre != nil { 2461 a.cur.replacer = replacer 2462 a.cur.parent = parent 2463 a.cur.node = node 2464 if !a.pre(&a.cur) { 2465 return true 2466 } 2467 } 2468 if !a.rewriteRefOfSubquery(node, node.Subquery, func(newNode, parent SQLNode) { 2469 parent.(*ExistsExpr).Subquery = newNode.(*Subquery) 2470 }) { 2471 return false 2472 } 2473 if a.post != nil { 2474 a.cur.replacer = replacer 2475 a.cur.parent = parent 2476 a.cur.node = node 2477 if !a.post(&a.cur) { 2478 return false 2479 } 2480 } 2481 return true 2482 } 2483 func (a *application) rewriteRefOfExplainStmt(parent SQLNode, node *ExplainStmt, replacer replacerFunc) bool { 2484 if node == nil { 2485 return true 2486 } 2487 if a.pre != nil { 2488 a.cur.replacer = replacer 2489 a.cur.parent = parent 2490 a.cur.node = node 2491 if !a.pre(&a.cur) { 2492 return true 2493 } 2494 } 2495 if !a.rewriteStatement(node, node.Statement, func(newNode, parent SQLNode) { 2496 parent.(*ExplainStmt).Statement = newNode.(Statement) 2497 }) { 2498 return false 2499 } 2500 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 2501 parent.(*ExplainStmt).Comments = newNode.(*ParsedComments) 2502 }) { 2503 return false 2504 } 2505 if a.post != nil { 2506 a.cur.replacer = replacer 2507 a.cur.parent = parent 2508 a.cur.node = node 2509 if !a.post(&a.cur) { 2510 return false 2511 } 2512 } 2513 return true 2514 } 2515 func (a *application) rewriteRefOfExplainTab(parent SQLNode, node *ExplainTab, replacer replacerFunc) bool { 2516 if node == nil { 2517 return true 2518 } 2519 if a.pre != nil { 2520 a.cur.replacer = replacer 2521 a.cur.parent = parent 2522 a.cur.node = node 2523 if !a.pre(&a.cur) { 2524 return true 2525 } 2526 } 2527 if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { 2528 parent.(*ExplainTab).Table = newNode.(TableName) 2529 }) { 2530 return false 2531 } 2532 if a.post != nil { 2533 a.cur.replacer = replacer 2534 a.cur.parent = parent 2535 a.cur.node = node 2536 if !a.post(&a.cur) { 2537 return false 2538 } 2539 } 2540 return true 2541 } 2542 func (a *application) rewriteExprs(parent SQLNode, node Exprs, replacer replacerFunc) bool { 2543 if node == nil { 2544 return true 2545 } 2546 if a.pre != nil { 2547 a.cur.replacer = replacer 2548 a.cur.parent = parent 2549 a.cur.node = node 2550 kontinue := !a.pre(&a.cur) 2551 if a.cur.revisit { 2552 node = a.cur.node.(Exprs) 2553 a.cur.revisit = false 2554 return a.rewriteExprs(parent, node, replacer) 2555 } 2556 if kontinue { 2557 return true 2558 } 2559 } 2560 for x, el := range node { 2561 if !a.rewriteExpr(node, el, func(idx int) replacerFunc { 2562 return func(newNode, parent SQLNode) { 2563 parent.(Exprs)[idx] = newNode.(Expr) 2564 } 2565 }(x)) { 2566 return false 2567 } 2568 } 2569 if a.post != nil { 2570 a.cur.replacer = replacer 2571 a.cur.parent = parent 2572 a.cur.node = node 2573 if !a.post(&a.cur) { 2574 return false 2575 } 2576 } 2577 return true 2578 } 2579 func (a *application) rewriteRefOfExtractFuncExpr(parent SQLNode, node *ExtractFuncExpr, replacer replacerFunc) bool { 2580 if node == nil { 2581 return true 2582 } 2583 if a.pre != nil { 2584 a.cur.replacer = replacer 2585 a.cur.parent = parent 2586 a.cur.node = node 2587 if !a.pre(&a.cur) { 2588 return true 2589 } 2590 } 2591 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 2592 parent.(*ExtractFuncExpr).Expr = newNode.(Expr) 2593 }) { 2594 return false 2595 } 2596 if a.post != nil { 2597 a.cur.replacer = replacer 2598 a.cur.parent = parent 2599 a.cur.node = node 2600 if !a.post(&a.cur) { 2601 return false 2602 } 2603 } 2604 return true 2605 } 2606 func (a *application) rewriteRefOfExtractValueExpr(parent SQLNode, node *ExtractValueExpr, replacer replacerFunc) bool { 2607 if node == nil { 2608 return true 2609 } 2610 if a.pre != nil { 2611 a.cur.replacer = replacer 2612 a.cur.parent = parent 2613 a.cur.node = node 2614 if !a.pre(&a.cur) { 2615 return true 2616 } 2617 } 2618 if !a.rewriteExpr(node, node.Fragment, func(newNode, parent SQLNode) { 2619 parent.(*ExtractValueExpr).Fragment = newNode.(Expr) 2620 }) { 2621 return false 2622 } 2623 if !a.rewriteExpr(node, node.XPathExpr, func(newNode, parent SQLNode) { 2624 parent.(*ExtractValueExpr).XPathExpr = newNode.(Expr) 2625 }) { 2626 return false 2627 } 2628 if a.post != nil { 2629 a.cur.replacer = replacer 2630 a.cur.parent = parent 2631 a.cur.node = node 2632 if !a.post(&a.cur) { 2633 return false 2634 } 2635 } 2636 return true 2637 } 2638 func (a *application) rewriteRefOfExtractedSubquery(parent SQLNode, node *ExtractedSubquery, replacer replacerFunc) bool { 2639 if node == nil { 2640 return true 2641 } 2642 if a.pre != nil { 2643 a.cur.replacer = replacer 2644 a.cur.parent = parent 2645 a.cur.node = node 2646 if !a.pre(&a.cur) { 2647 return true 2648 } 2649 } 2650 if !a.rewriteExpr(node, node.Original, func(newNode, parent SQLNode) { 2651 parent.(*ExtractedSubquery).Original = newNode.(Expr) 2652 }) { 2653 return false 2654 } 2655 if !a.rewriteRefOfSubquery(node, node.Subquery, func(newNode, parent SQLNode) { 2656 parent.(*ExtractedSubquery).Subquery = newNode.(*Subquery) 2657 }) { 2658 return false 2659 } 2660 if !a.rewriteExpr(node, node.OtherSide, func(newNode, parent SQLNode) { 2661 parent.(*ExtractedSubquery).OtherSide = newNode.(Expr) 2662 }) { 2663 return false 2664 } 2665 if !a.rewriteExpr(node, node.alternative, func(newNode, parent SQLNode) { 2666 parent.(*ExtractedSubquery).alternative = newNode.(Expr) 2667 }) { 2668 return false 2669 } 2670 if a.post != nil { 2671 a.cur.replacer = replacer 2672 a.cur.parent = parent 2673 a.cur.node = node 2674 if !a.post(&a.cur) { 2675 return false 2676 } 2677 } 2678 return true 2679 } 2680 func (a *application) rewriteRefOfFirstOrLastValueExpr(parent SQLNode, node *FirstOrLastValueExpr, replacer replacerFunc) bool { 2681 if node == nil { 2682 return true 2683 } 2684 if a.pre != nil { 2685 a.cur.replacer = replacer 2686 a.cur.parent = parent 2687 a.cur.node = node 2688 if !a.pre(&a.cur) { 2689 return true 2690 } 2691 } 2692 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 2693 parent.(*FirstOrLastValueExpr).Expr = newNode.(Expr) 2694 }) { 2695 return false 2696 } 2697 if !a.rewriteRefOfNullTreatmentClause(node, node.NullTreatmentClause, func(newNode, parent SQLNode) { 2698 parent.(*FirstOrLastValueExpr).NullTreatmentClause = newNode.(*NullTreatmentClause) 2699 }) { 2700 return false 2701 } 2702 if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { 2703 parent.(*FirstOrLastValueExpr).OverClause = newNode.(*OverClause) 2704 }) { 2705 return false 2706 } 2707 if a.post != nil { 2708 a.cur.replacer = replacer 2709 a.cur.parent = parent 2710 a.cur.node = node 2711 if !a.post(&a.cur) { 2712 return false 2713 } 2714 } 2715 return true 2716 } 2717 func (a *application) rewriteRefOfFlush(parent SQLNode, node *Flush, replacer replacerFunc) bool { 2718 if node == nil { 2719 return true 2720 } 2721 if a.pre != nil { 2722 a.cur.replacer = replacer 2723 a.cur.parent = parent 2724 a.cur.node = node 2725 if !a.pre(&a.cur) { 2726 return true 2727 } 2728 } 2729 if !a.rewriteTableNames(node, node.TableNames, func(newNode, parent SQLNode) { 2730 parent.(*Flush).TableNames = newNode.(TableNames) 2731 }) { 2732 return false 2733 } 2734 if a.post != nil { 2735 a.cur.replacer = replacer 2736 a.cur.parent = parent 2737 a.cur.node = node 2738 if !a.post(&a.cur) { 2739 return false 2740 } 2741 } 2742 return true 2743 } 2744 func (a *application) rewriteRefOfForce(parent SQLNode, node *Force, replacer replacerFunc) bool { 2745 if node == nil { 2746 return true 2747 } 2748 if a.pre != nil { 2749 a.cur.replacer = replacer 2750 a.cur.parent = parent 2751 a.cur.node = node 2752 if !a.pre(&a.cur) { 2753 return true 2754 } 2755 } 2756 if a.post != nil { 2757 if a.pre == nil { 2758 a.cur.replacer = replacer 2759 a.cur.parent = parent 2760 a.cur.node = node 2761 } 2762 if !a.post(&a.cur) { 2763 return false 2764 } 2765 } 2766 return true 2767 } 2768 func (a *application) rewriteRefOfForeignKeyDefinition(parent SQLNode, node *ForeignKeyDefinition, replacer replacerFunc) bool { 2769 if node == nil { 2770 return true 2771 } 2772 if a.pre != nil { 2773 a.cur.replacer = replacer 2774 a.cur.parent = parent 2775 a.cur.node = node 2776 if !a.pre(&a.cur) { 2777 return true 2778 } 2779 } 2780 if !a.rewriteColumns(node, node.Source, func(newNode, parent SQLNode) { 2781 parent.(*ForeignKeyDefinition).Source = newNode.(Columns) 2782 }) { 2783 return false 2784 } 2785 if !a.rewriteIdentifierCI(node, node.IndexName, func(newNode, parent SQLNode) { 2786 parent.(*ForeignKeyDefinition).IndexName = newNode.(IdentifierCI) 2787 }) { 2788 return false 2789 } 2790 if !a.rewriteRefOfReferenceDefinition(node, node.ReferenceDefinition, func(newNode, parent SQLNode) { 2791 parent.(*ForeignKeyDefinition).ReferenceDefinition = newNode.(*ReferenceDefinition) 2792 }) { 2793 return false 2794 } 2795 if a.post != nil { 2796 a.cur.replacer = replacer 2797 a.cur.parent = parent 2798 a.cur.node = node 2799 if !a.post(&a.cur) { 2800 return false 2801 } 2802 } 2803 return true 2804 } 2805 func (a *application) rewriteRefOfFrameClause(parent SQLNode, node *FrameClause, replacer replacerFunc) bool { 2806 if node == nil { 2807 return true 2808 } 2809 if a.pre != nil { 2810 a.cur.replacer = replacer 2811 a.cur.parent = parent 2812 a.cur.node = node 2813 if !a.pre(&a.cur) { 2814 return true 2815 } 2816 } 2817 if !a.rewriteRefOfFramePoint(node, node.Start, func(newNode, parent SQLNode) { 2818 parent.(*FrameClause).Start = newNode.(*FramePoint) 2819 }) { 2820 return false 2821 } 2822 if !a.rewriteRefOfFramePoint(node, node.End, func(newNode, parent SQLNode) { 2823 parent.(*FrameClause).End = newNode.(*FramePoint) 2824 }) { 2825 return false 2826 } 2827 if a.post != nil { 2828 a.cur.replacer = replacer 2829 a.cur.parent = parent 2830 a.cur.node = node 2831 if !a.post(&a.cur) { 2832 return false 2833 } 2834 } 2835 return true 2836 } 2837 func (a *application) rewriteRefOfFramePoint(parent SQLNode, node *FramePoint, replacer replacerFunc) bool { 2838 if node == nil { 2839 return true 2840 } 2841 if a.pre != nil { 2842 a.cur.replacer = replacer 2843 a.cur.parent = parent 2844 a.cur.node = node 2845 if !a.pre(&a.cur) { 2846 return true 2847 } 2848 } 2849 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 2850 parent.(*FramePoint).Expr = newNode.(Expr) 2851 }) { 2852 return false 2853 } 2854 if a.post != nil { 2855 a.cur.replacer = replacer 2856 a.cur.parent = parent 2857 a.cur.node = node 2858 if !a.post(&a.cur) { 2859 return false 2860 } 2861 } 2862 return true 2863 } 2864 func (a *application) rewriteRefOfFromFirstLastClause(parent SQLNode, node *FromFirstLastClause, replacer replacerFunc) bool { 2865 if node == nil { 2866 return true 2867 } 2868 if a.pre != nil { 2869 a.cur.replacer = replacer 2870 a.cur.parent = parent 2871 a.cur.node = node 2872 if !a.pre(&a.cur) { 2873 return true 2874 } 2875 } 2876 if a.post != nil { 2877 if a.pre == nil { 2878 a.cur.replacer = replacer 2879 a.cur.parent = parent 2880 a.cur.node = node 2881 } 2882 if !a.post(&a.cur) { 2883 return false 2884 } 2885 } 2886 return true 2887 } 2888 func (a *application) rewriteRefOfFuncExpr(parent SQLNode, node *FuncExpr, replacer replacerFunc) bool { 2889 if node == nil { 2890 return true 2891 } 2892 if a.pre != nil { 2893 a.cur.replacer = replacer 2894 a.cur.parent = parent 2895 a.cur.node = node 2896 if !a.pre(&a.cur) { 2897 return true 2898 } 2899 } 2900 if !a.rewriteIdentifierCS(node, node.Qualifier, func(newNode, parent SQLNode) { 2901 parent.(*FuncExpr).Qualifier = newNode.(IdentifierCS) 2902 }) { 2903 return false 2904 } 2905 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 2906 parent.(*FuncExpr).Name = newNode.(IdentifierCI) 2907 }) { 2908 return false 2909 } 2910 if !a.rewriteSelectExprs(node, node.Exprs, func(newNode, parent SQLNode) { 2911 parent.(*FuncExpr).Exprs = newNode.(SelectExprs) 2912 }) { 2913 return false 2914 } 2915 if a.post != nil { 2916 a.cur.replacer = replacer 2917 a.cur.parent = parent 2918 a.cur.node = node 2919 if !a.post(&a.cur) { 2920 return false 2921 } 2922 } 2923 return true 2924 } 2925 func (a *application) rewriteRefOfGTIDFuncExpr(parent SQLNode, node *GTIDFuncExpr, replacer replacerFunc) bool { 2926 if node == nil { 2927 return true 2928 } 2929 if a.pre != nil { 2930 a.cur.replacer = replacer 2931 a.cur.parent = parent 2932 a.cur.node = node 2933 if !a.pre(&a.cur) { 2934 return true 2935 } 2936 } 2937 if !a.rewriteExpr(node, node.Set1, func(newNode, parent SQLNode) { 2938 parent.(*GTIDFuncExpr).Set1 = newNode.(Expr) 2939 }) { 2940 return false 2941 } 2942 if !a.rewriteExpr(node, node.Set2, func(newNode, parent SQLNode) { 2943 parent.(*GTIDFuncExpr).Set2 = newNode.(Expr) 2944 }) { 2945 return false 2946 } 2947 if !a.rewriteExpr(node, node.Timeout, func(newNode, parent SQLNode) { 2948 parent.(*GTIDFuncExpr).Timeout = newNode.(Expr) 2949 }) { 2950 return false 2951 } 2952 if !a.rewriteExpr(node, node.Channel, func(newNode, parent SQLNode) { 2953 parent.(*GTIDFuncExpr).Channel = newNode.(Expr) 2954 }) { 2955 return false 2956 } 2957 if a.post != nil { 2958 a.cur.replacer = replacer 2959 a.cur.parent = parent 2960 a.cur.node = node 2961 if !a.post(&a.cur) { 2962 return false 2963 } 2964 } 2965 return true 2966 } 2967 func (a *application) rewriteGroupBy(parent SQLNode, node GroupBy, replacer replacerFunc) bool { 2968 if node == nil { 2969 return true 2970 } 2971 if a.pre != nil { 2972 a.cur.replacer = replacer 2973 a.cur.parent = parent 2974 a.cur.node = node 2975 kontinue := !a.pre(&a.cur) 2976 if a.cur.revisit { 2977 node = a.cur.node.(GroupBy) 2978 a.cur.revisit = false 2979 return a.rewriteGroupBy(parent, node, replacer) 2980 } 2981 if kontinue { 2982 return true 2983 } 2984 } 2985 for x, el := range node { 2986 if !a.rewriteExpr(node, el, func(idx int) replacerFunc { 2987 return func(newNode, parent SQLNode) { 2988 parent.(GroupBy)[idx] = newNode.(Expr) 2989 } 2990 }(x)) { 2991 return false 2992 } 2993 } 2994 if a.post != nil { 2995 a.cur.replacer = replacer 2996 a.cur.parent = parent 2997 a.cur.node = node 2998 if !a.post(&a.cur) { 2999 return false 3000 } 3001 } 3002 return true 3003 } 3004 func (a *application) rewriteRefOfGroupConcatExpr(parent SQLNode, node *GroupConcatExpr, replacer replacerFunc) bool { 3005 if node == nil { 3006 return true 3007 } 3008 if a.pre != nil { 3009 a.cur.replacer = replacer 3010 a.cur.parent = parent 3011 a.cur.node = node 3012 if !a.pre(&a.cur) { 3013 return true 3014 } 3015 } 3016 if !a.rewriteExprs(node, node.Exprs, func(newNode, parent SQLNode) { 3017 parent.(*GroupConcatExpr).Exprs = newNode.(Exprs) 3018 }) { 3019 return false 3020 } 3021 if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { 3022 parent.(*GroupConcatExpr).OrderBy = newNode.(OrderBy) 3023 }) { 3024 return false 3025 } 3026 if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { 3027 parent.(*GroupConcatExpr).Limit = newNode.(*Limit) 3028 }) { 3029 return false 3030 } 3031 if a.post != nil { 3032 a.cur.replacer = replacer 3033 a.cur.parent = parent 3034 a.cur.node = node 3035 if !a.post(&a.cur) { 3036 return false 3037 } 3038 } 3039 return true 3040 } 3041 func (a *application) rewriteIdentifierCI(parent SQLNode, node IdentifierCI, replacer replacerFunc) bool { 3042 if a.pre != nil { 3043 a.cur.replacer = replacer 3044 a.cur.parent = parent 3045 a.cur.node = node 3046 if !a.pre(&a.cur) { 3047 return true 3048 } 3049 } 3050 if a.post != nil { 3051 if a.pre == nil { 3052 a.cur.replacer = replacer 3053 a.cur.parent = parent 3054 a.cur.node = node 3055 } 3056 if !a.post(&a.cur) { 3057 return false 3058 } 3059 } 3060 return true 3061 } 3062 func (a *application) rewriteIdentifierCS(parent SQLNode, node IdentifierCS, replacer replacerFunc) bool { 3063 if a.pre != nil { 3064 a.cur.replacer = replacer 3065 a.cur.parent = parent 3066 a.cur.node = node 3067 if !a.pre(&a.cur) { 3068 return true 3069 } 3070 } 3071 if a.post != nil { 3072 if a.pre == nil { 3073 a.cur.replacer = replacer 3074 a.cur.parent = parent 3075 a.cur.node = node 3076 } 3077 if !a.post(&a.cur) { 3078 return false 3079 } 3080 } 3081 return true 3082 } 3083 func (a *application) rewriteRefOfIndexDefinition(parent SQLNode, node *IndexDefinition, replacer replacerFunc) bool { 3084 if node == nil { 3085 return true 3086 } 3087 if a.pre != nil { 3088 a.cur.replacer = replacer 3089 a.cur.parent = parent 3090 a.cur.node = node 3091 if !a.pre(&a.cur) { 3092 return true 3093 } 3094 } 3095 if !a.rewriteRefOfIndexInfo(node, node.Info, func(newNode, parent SQLNode) { 3096 parent.(*IndexDefinition).Info = newNode.(*IndexInfo) 3097 }) { 3098 return false 3099 } 3100 if a.post != nil { 3101 a.cur.replacer = replacer 3102 a.cur.parent = parent 3103 a.cur.node = node 3104 if !a.post(&a.cur) { 3105 return false 3106 } 3107 } 3108 return true 3109 } 3110 func (a *application) rewriteRefOfIndexHint(parent SQLNode, node *IndexHint, replacer replacerFunc) bool { 3111 if node == nil { 3112 return true 3113 } 3114 if a.pre != nil { 3115 a.cur.replacer = replacer 3116 a.cur.parent = parent 3117 a.cur.node = node 3118 if !a.pre(&a.cur) { 3119 return true 3120 } 3121 } 3122 for x, el := range node.Indexes { 3123 if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { 3124 return func(newNode, parent SQLNode) { 3125 parent.(*IndexHint).Indexes[idx] = newNode.(IdentifierCI) 3126 } 3127 }(x)) { 3128 return false 3129 } 3130 } 3131 if a.post != nil { 3132 a.cur.replacer = replacer 3133 a.cur.parent = parent 3134 a.cur.node = node 3135 if !a.post(&a.cur) { 3136 return false 3137 } 3138 } 3139 return true 3140 } 3141 func (a *application) rewriteIndexHints(parent SQLNode, node IndexHints, replacer replacerFunc) bool { 3142 if node == nil { 3143 return true 3144 } 3145 if a.pre != nil { 3146 a.cur.replacer = replacer 3147 a.cur.parent = parent 3148 a.cur.node = node 3149 kontinue := !a.pre(&a.cur) 3150 if a.cur.revisit { 3151 node = a.cur.node.(IndexHints) 3152 a.cur.revisit = false 3153 return a.rewriteIndexHints(parent, node, replacer) 3154 } 3155 if kontinue { 3156 return true 3157 } 3158 } 3159 for x, el := range node { 3160 if !a.rewriteRefOfIndexHint(node, el, func(idx int) replacerFunc { 3161 return func(newNode, parent SQLNode) { 3162 parent.(IndexHints)[idx] = newNode.(*IndexHint) 3163 } 3164 }(x)) { 3165 return false 3166 } 3167 } 3168 if a.post != nil { 3169 a.cur.replacer = replacer 3170 a.cur.parent = parent 3171 a.cur.node = node 3172 if !a.post(&a.cur) { 3173 return false 3174 } 3175 } 3176 return true 3177 } 3178 func (a *application) rewriteRefOfIndexInfo(parent SQLNode, node *IndexInfo, replacer replacerFunc) bool { 3179 if node == nil { 3180 return true 3181 } 3182 if a.pre != nil { 3183 a.cur.replacer = replacer 3184 a.cur.parent = parent 3185 a.cur.node = node 3186 if !a.pre(&a.cur) { 3187 return true 3188 } 3189 } 3190 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 3191 parent.(*IndexInfo).Name = newNode.(IdentifierCI) 3192 }) { 3193 return false 3194 } 3195 if !a.rewriteIdentifierCI(node, node.ConstraintName, func(newNode, parent SQLNode) { 3196 parent.(*IndexInfo).ConstraintName = newNode.(IdentifierCI) 3197 }) { 3198 return false 3199 } 3200 if a.post != nil { 3201 a.cur.replacer = replacer 3202 a.cur.parent = parent 3203 a.cur.node = node 3204 if !a.post(&a.cur) { 3205 return false 3206 } 3207 } 3208 return true 3209 } 3210 func (a *application) rewriteRefOfInsert(parent SQLNode, node *Insert, replacer replacerFunc) bool { 3211 if node == nil { 3212 return true 3213 } 3214 if a.pre != nil { 3215 a.cur.replacer = replacer 3216 a.cur.parent = parent 3217 a.cur.node = node 3218 if !a.pre(&a.cur) { 3219 return true 3220 } 3221 } 3222 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 3223 parent.(*Insert).Comments = newNode.(*ParsedComments) 3224 }) { 3225 return false 3226 } 3227 if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { 3228 parent.(*Insert).Table = newNode.(TableName) 3229 }) { 3230 return false 3231 } 3232 if !a.rewritePartitions(node, node.Partitions, func(newNode, parent SQLNode) { 3233 parent.(*Insert).Partitions = newNode.(Partitions) 3234 }) { 3235 return false 3236 } 3237 if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { 3238 parent.(*Insert).Columns = newNode.(Columns) 3239 }) { 3240 return false 3241 } 3242 if !a.rewriteInsertRows(node, node.Rows, func(newNode, parent SQLNode) { 3243 parent.(*Insert).Rows = newNode.(InsertRows) 3244 }) { 3245 return false 3246 } 3247 if !a.rewriteOnDup(node, node.OnDup, func(newNode, parent SQLNode) { 3248 parent.(*Insert).OnDup = newNode.(OnDup) 3249 }) { 3250 return false 3251 } 3252 if a.post != nil { 3253 a.cur.replacer = replacer 3254 a.cur.parent = parent 3255 a.cur.node = node 3256 if !a.post(&a.cur) { 3257 return false 3258 } 3259 } 3260 return true 3261 } 3262 func (a *application) rewriteRefOfInsertExpr(parent SQLNode, node *InsertExpr, replacer replacerFunc) bool { 3263 if node == nil { 3264 return true 3265 } 3266 if a.pre != nil { 3267 a.cur.replacer = replacer 3268 a.cur.parent = parent 3269 a.cur.node = node 3270 if !a.pre(&a.cur) { 3271 return true 3272 } 3273 } 3274 if !a.rewriteExpr(node, node.Str, func(newNode, parent SQLNode) { 3275 parent.(*InsertExpr).Str = newNode.(Expr) 3276 }) { 3277 return false 3278 } 3279 if !a.rewriteExpr(node, node.Pos, func(newNode, parent SQLNode) { 3280 parent.(*InsertExpr).Pos = newNode.(Expr) 3281 }) { 3282 return false 3283 } 3284 if !a.rewriteExpr(node, node.Len, func(newNode, parent SQLNode) { 3285 parent.(*InsertExpr).Len = newNode.(Expr) 3286 }) { 3287 return false 3288 } 3289 if !a.rewriteExpr(node, node.NewStr, func(newNode, parent SQLNode) { 3290 parent.(*InsertExpr).NewStr = newNode.(Expr) 3291 }) { 3292 return false 3293 } 3294 if a.post != nil { 3295 a.cur.replacer = replacer 3296 a.cur.parent = parent 3297 a.cur.node = node 3298 if !a.post(&a.cur) { 3299 return false 3300 } 3301 } 3302 return true 3303 } 3304 func (a *application) rewriteRefOfIntervalExpr(parent SQLNode, node *IntervalExpr, replacer replacerFunc) bool { 3305 if node == nil { 3306 return true 3307 } 3308 if a.pre != nil { 3309 a.cur.replacer = replacer 3310 a.cur.parent = parent 3311 a.cur.node = node 3312 if !a.pre(&a.cur) { 3313 return true 3314 } 3315 } 3316 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 3317 parent.(*IntervalExpr).Expr = newNode.(Expr) 3318 }) { 3319 return false 3320 } 3321 if a.post != nil { 3322 a.cur.replacer = replacer 3323 a.cur.parent = parent 3324 a.cur.node = node 3325 if !a.post(&a.cur) { 3326 return false 3327 } 3328 } 3329 return true 3330 } 3331 func (a *application) rewriteRefOfIntervalFuncExpr(parent SQLNode, node *IntervalFuncExpr, replacer replacerFunc) bool { 3332 if node == nil { 3333 return true 3334 } 3335 if a.pre != nil { 3336 a.cur.replacer = replacer 3337 a.cur.parent = parent 3338 a.cur.node = node 3339 if !a.pre(&a.cur) { 3340 return true 3341 } 3342 } 3343 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 3344 parent.(*IntervalFuncExpr).Expr = newNode.(Expr) 3345 }) { 3346 return false 3347 } 3348 if !a.rewriteExprs(node, node.Exprs, func(newNode, parent SQLNode) { 3349 parent.(*IntervalFuncExpr).Exprs = newNode.(Exprs) 3350 }) { 3351 return false 3352 } 3353 if a.post != nil { 3354 a.cur.replacer = replacer 3355 a.cur.parent = parent 3356 a.cur.node = node 3357 if !a.post(&a.cur) { 3358 return false 3359 } 3360 } 3361 return true 3362 } 3363 func (a *application) rewriteRefOfIntroducerExpr(parent SQLNode, node *IntroducerExpr, replacer replacerFunc) bool { 3364 if node == nil { 3365 return true 3366 } 3367 if a.pre != nil { 3368 a.cur.replacer = replacer 3369 a.cur.parent = parent 3370 a.cur.node = node 3371 if !a.pre(&a.cur) { 3372 return true 3373 } 3374 } 3375 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 3376 parent.(*IntroducerExpr).Expr = newNode.(Expr) 3377 }) { 3378 return false 3379 } 3380 if a.post != nil { 3381 a.cur.replacer = replacer 3382 a.cur.parent = parent 3383 a.cur.node = node 3384 if !a.post(&a.cur) { 3385 return false 3386 } 3387 } 3388 return true 3389 } 3390 func (a *application) rewriteRefOfIsExpr(parent SQLNode, node *IsExpr, replacer replacerFunc) bool { 3391 if node == nil { 3392 return true 3393 } 3394 if a.pre != nil { 3395 a.cur.replacer = replacer 3396 a.cur.parent = parent 3397 a.cur.node = node 3398 if !a.pre(&a.cur) { 3399 return true 3400 } 3401 } 3402 if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { 3403 parent.(*IsExpr).Left = newNode.(Expr) 3404 }) { 3405 return false 3406 } 3407 if a.post != nil { 3408 a.cur.replacer = replacer 3409 a.cur.parent = parent 3410 a.cur.node = node 3411 if !a.post(&a.cur) { 3412 return false 3413 } 3414 } 3415 return true 3416 } 3417 func (a *application) rewriteRefOfJSONArrayExpr(parent SQLNode, node *JSONArrayExpr, replacer replacerFunc) bool { 3418 if node == nil { 3419 return true 3420 } 3421 if a.pre != nil { 3422 a.cur.replacer = replacer 3423 a.cur.parent = parent 3424 a.cur.node = node 3425 if !a.pre(&a.cur) { 3426 return true 3427 } 3428 } 3429 if !a.rewriteExprs(node, node.Params, func(newNode, parent SQLNode) { 3430 parent.(*JSONArrayExpr).Params = newNode.(Exprs) 3431 }) { 3432 return false 3433 } 3434 if a.post != nil { 3435 a.cur.replacer = replacer 3436 a.cur.parent = parent 3437 a.cur.node = node 3438 if !a.post(&a.cur) { 3439 return false 3440 } 3441 } 3442 return true 3443 } 3444 func (a *application) rewriteRefOfJSONAttributesExpr(parent SQLNode, node *JSONAttributesExpr, replacer replacerFunc) bool { 3445 if node == nil { 3446 return true 3447 } 3448 if a.pre != nil { 3449 a.cur.replacer = replacer 3450 a.cur.parent = parent 3451 a.cur.node = node 3452 if !a.pre(&a.cur) { 3453 return true 3454 } 3455 } 3456 if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { 3457 parent.(*JSONAttributesExpr).JSONDoc = newNode.(Expr) 3458 }) { 3459 return false 3460 } 3461 if !a.rewriteExpr(node, node.Path, func(newNode, parent SQLNode) { 3462 parent.(*JSONAttributesExpr).Path = newNode.(Expr) 3463 }) { 3464 return false 3465 } 3466 if a.post != nil { 3467 a.cur.replacer = replacer 3468 a.cur.parent = parent 3469 a.cur.node = node 3470 if !a.post(&a.cur) { 3471 return false 3472 } 3473 } 3474 return true 3475 } 3476 func (a *application) rewriteRefOfJSONContainsExpr(parent SQLNode, node *JSONContainsExpr, replacer replacerFunc) bool { 3477 if node == nil { 3478 return true 3479 } 3480 if a.pre != nil { 3481 a.cur.replacer = replacer 3482 a.cur.parent = parent 3483 a.cur.node = node 3484 if !a.pre(&a.cur) { 3485 return true 3486 } 3487 } 3488 if !a.rewriteExpr(node, node.Target, func(newNode, parent SQLNode) { 3489 parent.(*JSONContainsExpr).Target = newNode.(Expr) 3490 }) { 3491 return false 3492 } 3493 if !a.rewriteExpr(node, node.Candidate, func(newNode, parent SQLNode) { 3494 parent.(*JSONContainsExpr).Candidate = newNode.(Expr) 3495 }) { 3496 return false 3497 } 3498 for x, el := range node.PathList { 3499 if !a.rewriteExpr(node, el, func(idx int) replacerFunc { 3500 return func(newNode, parent SQLNode) { 3501 parent.(*JSONContainsExpr).PathList[idx] = newNode.(Expr) 3502 } 3503 }(x)) { 3504 return false 3505 } 3506 } 3507 if a.post != nil { 3508 a.cur.replacer = replacer 3509 a.cur.parent = parent 3510 a.cur.node = node 3511 if !a.post(&a.cur) { 3512 return false 3513 } 3514 } 3515 return true 3516 } 3517 func (a *application) rewriteRefOfJSONContainsPathExpr(parent SQLNode, node *JSONContainsPathExpr, replacer replacerFunc) bool { 3518 if node == nil { 3519 return true 3520 } 3521 if a.pre != nil { 3522 a.cur.replacer = replacer 3523 a.cur.parent = parent 3524 a.cur.node = node 3525 if !a.pre(&a.cur) { 3526 return true 3527 } 3528 } 3529 if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { 3530 parent.(*JSONContainsPathExpr).JSONDoc = newNode.(Expr) 3531 }) { 3532 return false 3533 } 3534 if !a.rewriteExpr(node, node.OneOrAll, func(newNode, parent SQLNode) { 3535 parent.(*JSONContainsPathExpr).OneOrAll = newNode.(Expr) 3536 }) { 3537 return false 3538 } 3539 for x, el := range node.PathList { 3540 if !a.rewriteExpr(node, el, func(idx int) replacerFunc { 3541 return func(newNode, parent SQLNode) { 3542 parent.(*JSONContainsPathExpr).PathList[idx] = newNode.(Expr) 3543 } 3544 }(x)) { 3545 return false 3546 } 3547 } 3548 if a.post != nil { 3549 a.cur.replacer = replacer 3550 a.cur.parent = parent 3551 a.cur.node = node 3552 if !a.post(&a.cur) { 3553 return false 3554 } 3555 } 3556 return true 3557 } 3558 func (a *application) rewriteRefOfJSONExtractExpr(parent SQLNode, node *JSONExtractExpr, replacer replacerFunc) bool { 3559 if node == nil { 3560 return true 3561 } 3562 if a.pre != nil { 3563 a.cur.replacer = replacer 3564 a.cur.parent = parent 3565 a.cur.node = node 3566 if !a.pre(&a.cur) { 3567 return true 3568 } 3569 } 3570 if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { 3571 parent.(*JSONExtractExpr).JSONDoc = newNode.(Expr) 3572 }) { 3573 return false 3574 } 3575 for x, el := range node.PathList { 3576 if !a.rewriteExpr(node, el, func(idx int) replacerFunc { 3577 return func(newNode, parent SQLNode) { 3578 parent.(*JSONExtractExpr).PathList[idx] = newNode.(Expr) 3579 } 3580 }(x)) { 3581 return false 3582 } 3583 } 3584 if a.post != nil { 3585 a.cur.replacer = replacer 3586 a.cur.parent = parent 3587 a.cur.node = node 3588 if !a.post(&a.cur) { 3589 return false 3590 } 3591 } 3592 return true 3593 } 3594 func (a *application) rewriteRefOfJSONKeysExpr(parent SQLNode, node *JSONKeysExpr, replacer replacerFunc) bool { 3595 if node == nil { 3596 return true 3597 } 3598 if a.pre != nil { 3599 a.cur.replacer = replacer 3600 a.cur.parent = parent 3601 a.cur.node = node 3602 if !a.pre(&a.cur) { 3603 return true 3604 } 3605 } 3606 if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { 3607 parent.(*JSONKeysExpr).JSONDoc = newNode.(Expr) 3608 }) { 3609 return false 3610 } 3611 if !a.rewriteExpr(node, node.Path, func(newNode, parent SQLNode) { 3612 parent.(*JSONKeysExpr).Path = newNode.(Expr) 3613 }) { 3614 return false 3615 } 3616 if a.post != nil { 3617 a.cur.replacer = replacer 3618 a.cur.parent = parent 3619 a.cur.node = node 3620 if !a.post(&a.cur) { 3621 return false 3622 } 3623 } 3624 return true 3625 } 3626 func (a *application) rewriteRefOfJSONObjectExpr(parent SQLNode, node *JSONObjectExpr, replacer replacerFunc) bool { 3627 if node == nil { 3628 return true 3629 } 3630 if a.pre != nil { 3631 a.cur.replacer = replacer 3632 a.cur.parent = parent 3633 a.cur.node = node 3634 if !a.pre(&a.cur) { 3635 return true 3636 } 3637 } 3638 for x, el := range node.Params { 3639 if !a.rewriteRefOfJSONObjectParam(node, el, func(idx int) replacerFunc { 3640 return func(newNode, parent SQLNode) { 3641 parent.(*JSONObjectExpr).Params[idx] = newNode.(*JSONObjectParam) 3642 } 3643 }(x)) { 3644 return false 3645 } 3646 } 3647 if a.post != nil { 3648 a.cur.replacer = replacer 3649 a.cur.parent = parent 3650 a.cur.node = node 3651 if !a.post(&a.cur) { 3652 return false 3653 } 3654 } 3655 return true 3656 } 3657 func (a *application) rewriteRefOfJSONObjectParam(parent SQLNode, node *JSONObjectParam, replacer replacerFunc) bool { 3658 if node == nil { 3659 return true 3660 } 3661 if a.pre != nil { 3662 a.cur.replacer = replacer 3663 a.cur.parent = parent 3664 a.cur.node = node 3665 if !a.pre(&a.cur) { 3666 return true 3667 } 3668 } 3669 if !a.rewriteExpr(node, node.Key, func(newNode, parent SQLNode) { 3670 parent.(*JSONObjectParam).Key = newNode.(Expr) 3671 }) { 3672 return false 3673 } 3674 if !a.rewriteExpr(node, node.Value, func(newNode, parent SQLNode) { 3675 parent.(*JSONObjectParam).Value = newNode.(Expr) 3676 }) { 3677 return false 3678 } 3679 if a.post != nil { 3680 a.cur.replacer = replacer 3681 a.cur.parent = parent 3682 a.cur.node = node 3683 if !a.post(&a.cur) { 3684 return false 3685 } 3686 } 3687 return true 3688 } 3689 func (a *application) rewriteRefOfJSONOverlapsExpr(parent SQLNode, node *JSONOverlapsExpr, replacer replacerFunc) bool { 3690 if node == nil { 3691 return true 3692 } 3693 if a.pre != nil { 3694 a.cur.replacer = replacer 3695 a.cur.parent = parent 3696 a.cur.node = node 3697 if !a.pre(&a.cur) { 3698 return true 3699 } 3700 } 3701 if !a.rewriteExpr(node, node.JSONDoc1, func(newNode, parent SQLNode) { 3702 parent.(*JSONOverlapsExpr).JSONDoc1 = newNode.(Expr) 3703 }) { 3704 return false 3705 } 3706 if !a.rewriteExpr(node, node.JSONDoc2, func(newNode, parent SQLNode) { 3707 parent.(*JSONOverlapsExpr).JSONDoc2 = newNode.(Expr) 3708 }) { 3709 return false 3710 } 3711 if a.post != nil { 3712 a.cur.replacer = replacer 3713 a.cur.parent = parent 3714 a.cur.node = node 3715 if !a.post(&a.cur) { 3716 return false 3717 } 3718 } 3719 return true 3720 } 3721 func (a *application) rewriteRefOfJSONPrettyExpr(parent SQLNode, node *JSONPrettyExpr, replacer replacerFunc) bool { 3722 if node == nil { 3723 return true 3724 } 3725 if a.pre != nil { 3726 a.cur.replacer = replacer 3727 a.cur.parent = parent 3728 a.cur.node = node 3729 if !a.pre(&a.cur) { 3730 return true 3731 } 3732 } 3733 if !a.rewriteExpr(node, node.JSONVal, func(newNode, parent SQLNode) { 3734 parent.(*JSONPrettyExpr).JSONVal = newNode.(Expr) 3735 }) { 3736 return false 3737 } 3738 if a.post != nil { 3739 a.cur.replacer = replacer 3740 a.cur.parent = parent 3741 a.cur.node = node 3742 if !a.post(&a.cur) { 3743 return false 3744 } 3745 } 3746 return true 3747 } 3748 func (a *application) rewriteRefOfJSONQuoteExpr(parent SQLNode, node *JSONQuoteExpr, replacer replacerFunc) bool { 3749 if node == nil { 3750 return true 3751 } 3752 if a.pre != nil { 3753 a.cur.replacer = replacer 3754 a.cur.parent = parent 3755 a.cur.node = node 3756 if !a.pre(&a.cur) { 3757 return true 3758 } 3759 } 3760 if !a.rewriteExpr(node, node.StringArg, func(newNode, parent SQLNode) { 3761 parent.(*JSONQuoteExpr).StringArg = newNode.(Expr) 3762 }) { 3763 return false 3764 } 3765 if a.post != nil { 3766 a.cur.replacer = replacer 3767 a.cur.parent = parent 3768 a.cur.node = node 3769 if !a.post(&a.cur) { 3770 return false 3771 } 3772 } 3773 return true 3774 } 3775 func (a *application) rewriteRefOfJSONRemoveExpr(parent SQLNode, node *JSONRemoveExpr, replacer replacerFunc) bool { 3776 if node == nil { 3777 return true 3778 } 3779 if a.pre != nil { 3780 a.cur.replacer = replacer 3781 a.cur.parent = parent 3782 a.cur.node = node 3783 if !a.pre(&a.cur) { 3784 return true 3785 } 3786 } 3787 if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { 3788 parent.(*JSONRemoveExpr).JSONDoc = newNode.(Expr) 3789 }) { 3790 return false 3791 } 3792 if !a.rewriteExprs(node, node.PathList, func(newNode, parent SQLNode) { 3793 parent.(*JSONRemoveExpr).PathList = newNode.(Exprs) 3794 }) { 3795 return false 3796 } 3797 if a.post != nil { 3798 a.cur.replacer = replacer 3799 a.cur.parent = parent 3800 a.cur.node = node 3801 if !a.post(&a.cur) { 3802 return false 3803 } 3804 } 3805 return true 3806 } 3807 func (a *application) rewriteRefOfJSONSchemaValidFuncExpr(parent SQLNode, node *JSONSchemaValidFuncExpr, replacer replacerFunc) bool { 3808 if node == nil { 3809 return true 3810 } 3811 if a.pre != nil { 3812 a.cur.replacer = replacer 3813 a.cur.parent = parent 3814 a.cur.node = node 3815 if !a.pre(&a.cur) { 3816 return true 3817 } 3818 } 3819 if !a.rewriteExpr(node, node.Schema, func(newNode, parent SQLNode) { 3820 parent.(*JSONSchemaValidFuncExpr).Schema = newNode.(Expr) 3821 }) { 3822 return false 3823 } 3824 if !a.rewriteExpr(node, node.Document, func(newNode, parent SQLNode) { 3825 parent.(*JSONSchemaValidFuncExpr).Document = newNode.(Expr) 3826 }) { 3827 return false 3828 } 3829 if a.post != nil { 3830 a.cur.replacer = replacer 3831 a.cur.parent = parent 3832 a.cur.node = node 3833 if !a.post(&a.cur) { 3834 return false 3835 } 3836 } 3837 return true 3838 } 3839 func (a *application) rewriteRefOfJSONSchemaValidationReportFuncExpr(parent SQLNode, node *JSONSchemaValidationReportFuncExpr, replacer replacerFunc) bool { 3840 if node == nil { 3841 return true 3842 } 3843 if a.pre != nil { 3844 a.cur.replacer = replacer 3845 a.cur.parent = parent 3846 a.cur.node = node 3847 if !a.pre(&a.cur) { 3848 return true 3849 } 3850 } 3851 if !a.rewriteExpr(node, node.Schema, func(newNode, parent SQLNode) { 3852 parent.(*JSONSchemaValidationReportFuncExpr).Schema = newNode.(Expr) 3853 }) { 3854 return false 3855 } 3856 if !a.rewriteExpr(node, node.Document, func(newNode, parent SQLNode) { 3857 parent.(*JSONSchemaValidationReportFuncExpr).Document = newNode.(Expr) 3858 }) { 3859 return false 3860 } 3861 if a.post != nil { 3862 a.cur.replacer = replacer 3863 a.cur.parent = parent 3864 a.cur.node = node 3865 if !a.post(&a.cur) { 3866 return false 3867 } 3868 } 3869 return true 3870 } 3871 func (a *application) rewriteRefOfJSONSearchExpr(parent SQLNode, node *JSONSearchExpr, replacer replacerFunc) bool { 3872 if node == nil { 3873 return true 3874 } 3875 if a.pre != nil { 3876 a.cur.replacer = replacer 3877 a.cur.parent = parent 3878 a.cur.node = node 3879 if !a.pre(&a.cur) { 3880 return true 3881 } 3882 } 3883 if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { 3884 parent.(*JSONSearchExpr).JSONDoc = newNode.(Expr) 3885 }) { 3886 return false 3887 } 3888 if !a.rewriteExpr(node, node.OneOrAll, func(newNode, parent SQLNode) { 3889 parent.(*JSONSearchExpr).OneOrAll = newNode.(Expr) 3890 }) { 3891 return false 3892 } 3893 if !a.rewriteExpr(node, node.SearchStr, func(newNode, parent SQLNode) { 3894 parent.(*JSONSearchExpr).SearchStr = newNode.(Expr) 3895 }) { 3896 return false 3897 } 3898 if !a.rewriteExpr(node, node.EscapeChar, func(newNode, parent SQLNode) { 3899 parent.(*JSONSearchExpr).EscapeChar = newNode.(Expr) 3900 }) { 3901 return false 3902 } 3903 for x, el := range node.PathList { 3904 if !a.rewriteExpr(node, el, func(idx int) replacerFunc { 3905 return func(newNode, parent SQLNode) { 3906 parent.(*JSONSearchExpr).PathList[idx] = newNode.(Expr) 3907 } 3908 }(x)) { 3909 return false 3910 } 3911 } 3912 if a.post != nil { 3913 a.cur.replacer = replacer 3914 a.cur.parent = parent 3915 a.cur.node = node 3916 if !a.post(&a.cur) { 3917 return false 3918 } 3919 } 3920 return true 3921 } 3922 func (a *application) rewriteRefOfJSONStorageFreeExpr(parent SQLNode, node *JSONStorageFreeExpr, replacer replacerFunc) bool { 3923 if node == nil { 3924 return true 3925 } 3926 if a.pre != nil { 3927 a.cur.replacer = replacer 3928 a.cur.parent = parent 3929 a.cur.node = node 3930 if !a.pre(&a.cur) { 3931 return true 3932 } 3933 } 3934 if !a.rewriteExpr(node, node.JSONVal, func(newNode, parent SQLNode) { 3935 parent.(*JSONStorageFreeExpr).JSONVal = newNode.(Expr) 3936 }) { 3937 return false 3938 } 3939 if a.post != nil { 3940 a.cur.replacer = replacer 3941 a.cur.parent = parent 3942 a.cur.node = node 3943 if !a.post(&a.cur) { 3944 return false 3945 } 3946 } 3947 return true 3948 } 3949 func (a *application) rewriteRefOfJSONStorageSizeExpr(parent SQLNode, node *JSONStorageSizeExpr, replacer replacerFunc) bool { 3950 if node == nil { 3951 return true 3952 } 3953 if a.pre != nil { 3954 a.cur.replacer = replacer 3955 a.cur.parent = parent 3956 a.cur.node = node 3957 if !a.pre(&a.cur) { 3958 return true 3959 } 3960 } 3961 if !a.rewriteExpr(node, node.JSONVal, func(newNode, parent SQLNode) { 3962 parent.(*JSONStorageSizeExpr).JSONVal = newNode.(Expr) 3963 }) { 3964 return false 3965 } 3966 if a.post != nil { 3967 a.cur.replacer = replacer 3968 a.cur.parent = parent 3969 a.cur.node = node 3970 if !a.post(&a.cur) { 3971 return false 3972 } 3973 } 3974 return true 3975 } 3976 func (a *application) rewriteRefOfJSONTableExpr(parent SQLNode, node *JSONTableExpr, replacer replacerFunc) bool { 3977 if node == nil { 3978 return true 3979 } 3980 if a.pre != nil { 3981 a.cur.replacer = replacer 3982 a.cur.parent = parent 3983 a.cur.node = node 3984 if !a.pre(&a.cur) { 3985 return true 3986 } 3987 } 3988 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 3989 parent.(*JSONTableExpr).Expr = newNode.(Expr) 3990 }) { 3991 return false 3992 } 3993 if !a.rewriteIdentifierCS(node, node.Alias, func(newNode, parent SQLNode) { 3994 parent.(*JSONTableExpr).Alias = newNode.(IdentifierCS) 3995 }) { 3996 return false 3997 } 3998 if !a.rewriteExpr(node, node.Filter, func(newNode, parent SQLNode) { 3999 parent.(*JSONTableExpr).Filter = newNode.(Expr) 4000 }) { 4001 return false 4002 } 4003 for x, el := range node.Columns { 4004 if !a.rewriteRefOfJtColumnDefinition(node, el, func(idx int) replacerFunc { 4005 return func(newNode, parent SQLNode) { 4006 parent.(*JSONTableExpr).Columns[idx] = newNode.(*JtColumnDefinition) 4007 } 4008 }(x)) { 4009 return false 4010 } 4011 } 4012 if a.post != nil { 4013 a.cur.replacer = replacer 4014 a.cur.parent = parent 4015 a.cur.node = node 4016 if !a.post(&a.cur) { 4017 return false 4018 } 4019 } 4020 return true 4021 } 4022 func (a *application) rewriteRefOfJSONUnquoteExpr(parent SQLNode, node *JSONUnquoteExpr, replacer replacerFunc) bool { 4023 if node == nil { 4024 return true 4025 } 4026 if a.pre != nil { 4027 a.cur.replacer = replacer 4028 a.cur.parent = parent 4029 a.cur.node = node 4030 if !a.pre(&a.cur) { 4031 return true 4032 } 4033 } 4034 if !a.rewriteExpr(node, node.JSONValue, func(newNode, parent SQLNode) { 4035 parent.(*JSONUnquoteExpr).JSONValue = newNode.(Expr) 4036 }) { 4037 return false 4038 } 4039 if a.post != nil { 4040 a.cur.replacer = replacer 4041 a.cur.parent = parent 4042 a.cur.node = node 4043 if !a.post(&a.cur) { 4044 return false 4045 } 4046 } 4047 return true 4048 } 4049 func (a *application) rewriteRefOfJSONValueExpr(parent SQLNode, node *JSONValueExpr, replacer replacerFunc) bool { 4050 if node == nil { 4051 return true 4052 } 4053 if a.pre != nil { 4054 a.cur.replacer = replacer 4055 a.cur.parent = parent 4056 a.cur.node = node 4057 if !a.pre(&a.cur) { 4058 return true 4059 } 4060 } 4061 if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { 4062 parent.(*JSONValueExpr).JSONDoc = newNode.(Expr) 4063 }) { 4064 return false 4065 } 4066 if !a.rewriteExpr(node, node.Path, func(newNode, parent SQLNode) { 4067 parent.(*JSONValueExpr).Path = newNode.(Expr) 4068 }) { 4069 return false 4070 } 4071 if !a.rewriteRefOfConvertType(node, node.ReturningType, func(newNode, parent SQLNode) { 4072 parent.(*JSONValueExpr).ReturningType = newNode.(*ConvertType) 4073 }) { 4074 return false 4075 } 4076 if !a.rewriteRefOfJtOnResponse(node, node.EmptyOnResponse, func(newNode, parent SQLNode) { 4077 parent.(*JSONValueExpr).EmptyOnResponse = newNode.(*JtOnResponse) 4078 }) { 4079 return false 4080 } 4081 if !a.rewriteRefOfJtOnResponse(node, node.ErrorOnResponse, func(newNode, parent SQLNode) { 4082 parent.(*JSONValueExpr).ErrorOnResponse = newNode.(*JtOnResponse) 4083 }) { 4084 return false 4085 } 4086 if a.post != nil { 4087 a.cur.replacer = replacer 4088 a.cur.parent = parent 4089 a.cur.node = node 4090 if !a.post(&a.cur) { 4091 return false 4092 } 4093 } 4094 return true 4095 } 4096 func (a *application) rewriteRefOfJSONValueMergeExpr(parent SQLNode, node *JSONValueMergeExpr, replacer replacerFunc) bool { 4097 if node == nil { 4098 return true 4099 } 4100 if a.pre != nil { 4101 a.cur.replacer = replacer 4102 a.cur.parent = parent 4103 a.cur.node = node 4104 if !a.pre(&a.cur) { 4105 return true 4106 } 4107 } 4108 if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { 4109 parent.(*JSONValueMergeExpr).JSONDoc = newNode.(Expr) 4110 }) { 4111 return false 4112 } 4113 if !a.rewriteExprs(node, node.JSONDocList, func(newNode, parent SQLNode) { 4114 parent.(*JSONValueMergeExpr).JSONDocList = newNode.(Exprs) 4115 }) { 4116 return false 4117 } 4118 if a.post != nil { 4119 a.cur.replacer = replacer 4120 a.cur.parent = parent 4121 a.cur.node = node 4122 if !a.post(&a.cur) { 4123 return false 4124 } 4125 } 4126 return true 4127 } 4128 func (a *application) rewriteRefOfJSONValueModifierExpr(parent SQLNode, node *JSONValueModifierExpr, replacer replacerFunc) bool { 4129 if node == nil { 4130 return true 4131 } 4132 if a.pre != nil { 4133 a.cur.replacer = replacer 4134 a.cur.parent = parent 4135 a.cur.node = node 4136 if !a.pre(&a.cur) { 4137 return true 4138 } 4139 } 4140 if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { 4141 parent.(*JSONValueModifierExpr).JSONDoc = newNode.(Expr) 4142 }) { 4143 return false 4144 } 4145 for x, el := range node.Params { 4146 if !a.rewriteRefOfJSONObjectParam(node, el, func(idx int) replacerFunc { 4147 return func(newNode, parent SQLNode) { 4148 parent.(*JSONValueModifierExpr).Params[idx] = newNode.(*JSONObjectParam) 4149 } 4150 }(x)) { 4151 return false 4152 } 4153 } 4154 if a.post != nil { 4155 a.cur.replacer = replacer 4156 a.cur.parent = parent 4157 a.cur.node = node 4158 if !a.post(&a.cur) { 4159 return false 4160 } 4161 } 4162 return true 4163 } 4164 func (a *application) rewriteRefOfJoinCondition(parent SQLNode, node *JoinCondition, replacer replacerFunc) bool { 4165 if node == nil { 4166 return true 4167 } 4168 if a.pre != nil { 4169 a.cur.replacer = replacer 4170 a.cur.parent = parent 4171 a.cur.node = node 4172 if !a.pre(&a.cur) { 4173 return true 4174 } 4175 } 4176 if !a.rewriteExpr(node, node.On, func(newNode, parent SQLNode) { 4177 parent.(*JoinCondition).On = newNode.(Expr) 4178 }) { 4179 return false 4180 } 4181 if !a.rewriteColumns(node, node.Using, func(newNode, parent SQLNode) { 4182 parent.(*JoinCondition).Using = newNode.(Columns) 4183 }) { 4184 return false 4185 } 4186 if a.post != nil { 4187 a.cur.replacer = replacer 4188 a.cur.parent = parent 4189 a.cur.node = node 4190 if !a.post(&a.cur) { 4191 return false 4192 } 4193 } 4194 return true 4195 } 4196 func (a *application) rewriteRefOfJoinTableExpr(parent SQLNode, node *JoinTableExpr, replacer replacerFunc) bool { 4197 if node == nil { 4198 return true 4199 } 4200 if a.pre != nil { 4201 a.cur.replacer = replacer 4202 a.cur.parent = parent 4203 a.cur.node = node 4204 if !a.pre(&a.cur) { 4205 return true 4206 } 4207 } 4208 if !a.rewriteTableExpr(node, node.LeftExpr, func(newNode, parent SQLNode) { 4209 parent.(*JoinTableExpr).LeftExpr = newNode.(TableExpr) 4210 }) { 4211 return false 4212 } 4213 if !a.rewriteTableExpr(node, node.RightExpr, func(newNode, parent SQLNode) { 4214 parent.(*JoinTableExpr).RightExpr = newNode.(TableExpr) 4215 }) { 4216 return false 4217 } 4218 if !a.rewriteRefOfJoinCondition(node, node.Condition, func(newNode, parent SQLNode) { 4219 parent.(*JoinTableExpr).Condition = newNode.(*JoinCondition) 4220 }) { 4221 return false 4222 } 4223 if a.post != nil { 4224 a.cur.replacer = replacer 4225 a.cur.parent = parent 4226 a.cur.node = node 4227 if !a.post(&a.cur) { 4228 return false 4229 } 4230 } 4231 return true 4232 } 4233 func (a *application) rewriteRefOfJtColumnDefinition(parent SQLNode, node *JtColumnDefinition, replacer replacerFunc) bool { 4234 if node == nil { 4235 return true 4236 } 4237 if a.pre != nil { 4238 a.cur.replacer = replacer 4239 a.cur.parent = parent 4240 a.cur.node = node 4241 if !a.pre(&a.cur) { 4242 return true 4243 } 4244 } 4245 if a.post != nil { 4246 if a.pre == nil { 4247 a.cur.replacer = replacer 4248 a.cur.parent = parent 4249 a.cur.node = node 4250 } 4251 if !a.post(&a.cur) { 4252 return false 4253 } 4254 } 4255 return true 4256 } 4257 func (a *application) rewriteRefOfJtOnResponse(parent SQLNode, node *JtOnResponse, replacer replacerFunc) bool { 4258 if node == nil { 4259 return true 4260 } 4261 if a.pre != nil { 4262 a.cur.replacer = replacer 4263 a.cur.parent = parent 4264 a.cur.node = node 4265 if !a.pre(&a.cur) { 4266 return true 4267 } 4268 } 4269 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 4270 parent.(*JtOnResponse).Expr = newNode.(Expr) 4271 }) { 4272 return false 4273 } 4274 if a.post != nil { 4275 a.cur.replacer = replacer 4276 a.cur.parent = parent 4277 a.cur.node = node 4278 if !a.post(&a.cur) { 4279 return false 4280 } 4281 } 4282 return true 4283 } 4284 func (a *application) rewriteRefOfKeyState(parent SQLNode, node *KeyState, replacer replacerFunc) bool { 4285 if node == nil { 4286 return true 4287 } 4288 if a.pre != nil { 4289 a.cur.replacer = replacer 4290 a.cur.parent = parent 4291 a.cur.node = node 4292 if !a.pre(&a.cur) { 4293 return true 4294 } 4295 } 4296 if a.post != nil { 4297 if a.pre == nil { 4298 a.cur.replacer = replacer 4299 a.cur.parent = parent 4300 a.cur.node = node 4301 } 4302 if !a.post(&a.cur) { 4303 return false 4304 } 4305 } 4306 return true 4307 } 4308 func (a *application) rewriteRefOfLagLeadExpr(parent SQLNode, node *LagLeadExpr, replacer replacerFunc) bool { 4309 if node == nil { 4310 return true 4311 } 4312 if a.pre != nil { 4313 a.cur.replacer = replacer 4314 a.cur.parent = parent 4315 a.cur.node = node 4316 if !a.pre(&a.cur) { 4317 return true 4318 } 4319 } 4320 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 4321 parent.(*LagLeadExpr).Expr = newNode.(Expr) 4322 }) { 4323 return false 4324 } 4325 if !a.rewriteExpr(node, node.N, func(newNode, parent SQLNode) { 4326 parent.(*LagLeadExpr).N = newNode.(Expr) 4327 }) { 4328 return false 4329 } 4330 if !a.rewriteExpr(node, node.Default, func(newNode, parent SQLNode) { 4331 parent.(*LagLeadExpr).Default = newNode.(Expr) 4332 }) { 4333 return false 4334 } 4335 if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { 4336 parent.(*LagLeadExpr).OverClause = newNode.(*OverClause) 4337 }) { 4338 return false 4339 } 4340 if !a.rewriteRefOfNullTreatmentClause(node, node.NullTreatmentClause, func(newNode, parent SQLNode) { 4341 parent.(*LagLeadExpr).NullTreatmentClause = newNode.(*NullTreatmentClause) 4342 }) { 4343 return false 4344 } 4345 if a.post != nil { 4346 a.cur.replacer = replacer 4347 a.cur.parent = parent 4348 a.cur.node = node 4349 if !a.post(&a.cur) { 4350 return false 4351 } 4352 } 4353 return true 4354 } 4355 func (a *application) rewriteRefOfLimit(parent SQLNode, node *Limit, replacer replacerFunc) bool { 4356 if node == nil { 4357 return true 4358 } 4359 if a.pre != nil { 4360 a.cur.replacer = replacer 4361 a.cur.parent = parent 4362 a.cur.node = node 4363 if !a.pre(&a.cur) { 4364 return true 4365 } 4366 } 4367 if !a.rewriteExpr(node, node.Offset, func(newNode, parent SQLNode) { 4368 parent.(*Limit).Offset = newNode.(Expr) 4369 }) { 4370 return false 4371 } 4372 if !a.rewriteExpr(node, node.Rowcount, func(newNode, parent SQLNode) { 4373 parent.(*Limit).Rowcount = newNode.(Expr) 4374 }) { 4375 return false 4376 } 4377 if a.post != nil { 4378 a.cur.replacer = replacer 4379 a.cur.parent = parent 4380 a.cur.node = node 4381 if !a.post(&a.cur) { 4382 return false 4383 } 4384 } 4385 return true 4386 } 4387 func (a *application) rewriteRefOfLineStringExpr(parent SQLNode, node *LineStringExpr, replacer replacerFunc) bool { 4388 if node == nil { 4389 return true 4390 } 4391 if a.pre != nil { 4392 a.cur.replacer = replacer 4393 a.cur.parent = parent 4394 a.cur.node = node 4395 if !a.pre(&a.cur) { 4396 return true 4397 } 4398 } 4399 if !a.rewriteExprs(node, node.PointParams, func(newNode, parent SQLNode) { 4400 parent.(*LineStringExpr).PointParams = newNode.(Exprs) 4401 }) { 4402 return false 4403 } 4404 if a.post != nil { 4405 a.cur.replacer = replacer 4406 a.cur.parent = parent 4407 a.cur.node = node 4408 if !a.post(&a.cur) { 4409 return false 4410 } 4411 } 4412 return true 4413 } 4414 func (a *application) rewriteRefOfLiteral(parent SQLNode, node *Literal, replacer replacerFunc) bool { 4415 if node == nil { 4416 return true 4417 } 4418 if a.pre != nil { 4419 a.cur.replacer = replacer 4420 a.cur.parent = parent 4421 a.cur.node = node 4422 if !a.pre(&a.cur) { 4423 return true 4424 } 4425 } 4426 if a.post != nil { 4427 if a.pre == nil { 4428 a.cur.replacer = replacer 4429 a.cur.parent = parent 4430 a.cur.node = node 4431 } 4432 if !a.post(&a.cur) { 4433 return false 4434 } 4435 } 4436 return true 4437 } 4438 func (a *application) rewriteRefOfLoad(parent SQLNode, node *Load, replacer replacerFunc) bool { 4439 if node == nil { 4440 return true 4441 } 4442 if a.pre != nil { 4443 a.cur.replacer = replacer 4444 a.cur.parent = parent 4445 a.cur.node = node 4446 if !a.pre(&a.cur) { 4447 return true 4448 } 4449 } 4450 if a.post != nil { 4451 if a.pre == nil { 4452 a.cur.replacer = replacer 4453 a.cur.parent = parent 4454 a.cur.node = node 4455 } 4456 if !a.post(&a.cur) { 4457 return false 4458 } 4459 } 4460 return true 4461 } 4462 func (a *application) rewriteRefOfLocateExpr(parent SQLNode, node *LocateExpr, replacer replacerFunc) bool { 4463 if node == nil { 4464 return true 4465 } 4466 if a.pre != nil { 4467 a.cur.replacer = replacer 4468 a.cur.parent = parent 4469 a.cur.node = node 4470 if !a.pre(&a.cur) { 4471 return true 4472 } 4473 } 4474 if !a.rewriteExpr(node, node.SubStr, func(newNode, parent SQLNode) { 4475 parent.(*LocateExpr).SubStr = newNode.(Expr) 4476 }) { 4477 return false 4478 } 4479 if !a.rewriteExpr(node, node.Str, func(newNode, parent SQLNode) { 4480 parent.(*LocateExpr).Str = newNode.(Expr) 4481 }) { 4482 return false 4483 } 4484 if !a.rewriteExpr(node, node.Pos, func(newNode, parent SQLNode) { 4485 parent.(*LocateExpr).Pos = newNode.(Expr) 4486 }) { 4487 return false 4488 } 4489 if a.post != nil { 4490 a.cur.replacer = replacer 4491 a.cur.parent = parent 4492 a.cur.node = node 4493 if !a.post(&a.cur) { 4494 return false 4495 } 4496 } 4497 return true 4498 } 4499 func (a *application) rewriteRefOfLockOption(parent SQLNode, node *LockOption, replacer replacerFunc) bool { 4500 if node == nil { 4501 return true 4502 } 4503 if a.pre != nil { 4504 a.cur.replacer = replacer 4505 a.cur.parent = parent 4506 a.cur.node = node 4507 if !a.pre(&a.cur) { 4508 return true 4509 } 4510 } 4511 if a.post != nil { 4512 if a.pre == nil { 4513 a.cur.replacer = replacer 4514 a.cur.parent = parent 4515 a.cur.node = node 4516 } 4517 if !a.post(&a.cur) { 4518 return false 4519 } 4520 } 4521 return true 4522 } 4523 func (a *application) rewriteRefOfLockTables(parent SQLNode, node *LockTables, replacer replacerFunc) bool { 4524 if node == nil { 4525 return true 4526 } 4527 if a.pre != nil { 4528 a.cur.replacer = replacer 4529 a.cur.parent = parent 4530 a.cur.node = node 4531 if !a.pre(&a.cur) { 4532 return true 4533 } 4534 } 4535 if a.post != nil { 4536 if a.pre == nil { 4537 a.cur.replacer = replacer 4538 a.cur.parent = parent 4539 a.cur.node = node 4540 } 4541 if !a.post(&a.cur) { 4542 return false 4543 } 4544 } 4545 return true 4546 } 4547 func (a *application) rewriteRefOfLockingFunc(parent SQLNode, node *LockingFunc, replacer replacerFunc) bool { 4548 if node == nil { 4549 return true 4550 } 4551 if a.pre != nil { 4552 a.cur.replacer = replacer 4553 a.cur.parent = parent 4554 a.cur.node = node 4555 if !a.pre(&a.cur) { 4556 return true 4557 } 4558 } 4559 if !a.rewriteExpr(node, node.Name, func(newNode, parent SQLNode) { 4560 parent.(*LockingFunc).Name = newNode.(Expr) 4561 }) { 4562 return false 4563 } 4564 if !a.rewriteExpr(node, node.Timeout, func(newNode, parent SQLNode) { 4565 parent.(*LockingFunc).Timeout = newNode.(Expr) 4566 }) { 4567 return false 4568 } 4569 if a.post != nil { 4570 a.cur.replacer = replacer 4571 a.cur.parent = parent 4572 a.cur.node = node 4573 if !a.post(&a.cur) { 4574 return false 4575 } 4576 } 4577 return true 4578 } 4579 func (a *application) rewriteRefOfMatchExpr(parent SQLNode, node *MatchExpr, replacer replacerFunc) bool { 4580 if node == nil { 4581 return true 4582 } 4583 if a.pre != nil { 4584 a.cur.replacer = replacer 4585 a.cur.parent = parent 4586 a.cur.node = node 4587 if !a.pre(&a.cur) { 4588 return true 4589 } 4590 } 4591 for x, el := range node.Columns { 4592 if !a.rewriteRefOfColName(node, el, func(idx int) replacerFunc { 4593 return func(newNode, parent SQLNode) { 4594 parent.(*MatchExpr).Columns[idx] = newNode.(*ColName) 4595 } 4596 }(x)) { 4597 return false 4598 } 4599 } 4600 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 4601 parent.(*MatchExpr).Expr = newNode.(Expr) 4602 }) { 4603 return false 4604 } 4605 if a.post != nil { 4606 a.cur.replacer = replacer 4607 a.cur.parent = parent 4608 a.cur.node = node 4609 if !a.post(&a.cur) { 4610 return false 4611 } 4612 } 4613 return true 4614 } 4615 func (a *application) rewriteRefOfMax(parent SQLNode, node *Max, replacer replacerFunc) bool { 4616 if node == nil { 4617 return true 4618 } 4619 if a.pre != nil { 4620 a.cur.replacer = replacer 4621 a.cur.parent = parent 4622 a.cur.node = node 4623 if !a.pre(&a.cur) { 4624 return true 4625 } 4626 } 4627 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 4628 parent.(*Max).Arg = newNode.(Expr) 4629 }) { 4630 return false 4631 } 4632 if a.post != nil { 4633 a.cur.replacer = replacer 4634 a.cur.parent = parent 4635 a.cur.node = node 4636 if !a.post(&a.cur) { 4637 return false 4638 } 4639 } 4640 return true 4641 } 4642 func (a *application) rewriteRefOfMemberOfExpr(parent SQLNode, node *MemberOfExpr, replacer replacerFunc) bool { 4643 if node == nil { 4644 return true 4645 } 4646 if a.pre != nil { 4647 a.cur.replacer = replacer 4648 a.cur.parent = parent 4649 a.cur.node = node 4650 if !a.pre(&a.cur) { 4651 return true 4652 } 4653 } 4654 if !a.rewriteExpr(node, node.Value, func(newNode, parent SQLNode) { 4655 parent.(*MemberOfExpr).Value = newNode.(Expr) 4656 }) { 4657 return false 4658 } 4659 if !a.rewriteExpr(node, node.JSONArr, func(newNode, parent SQLNode) { 4660 parent.(*MemberOfExpr).JSONArr = newNode.(Expr) 4661 }) { 4662 return false 4663 } 4664 if a.post != nil { 4665 a.cur.replacer = replacer 4666 a.cur.parent = parent 4667 a.cur.node = node 4668 if !a.post(&a.cur) { 4669 return false 4670 } 4671 } 4672 return true 4673 } 4674 func (a *application) rewriteRefOfMin(parent SQLNode, node *Min, replacer replacerFunc) bool { 4675 if node == nil { 4676 return true 4677 } 4678 if a.pre != nil { 4679 a.cur.replacer = replacer 4680 a.cur.parent = parent 4681 a.cur.node = node 4682 if !a.pre(&a.cur) { 4683 return true 4684 } 4685 } 4686 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 4687 parent.(*Min).Arg = newNode.(Expr) 4688 }) { 4689 return false 4690 } 4691 if a.post != nil { 4692 a.cur.replacer = replacer 4693 a.cur.parent = parent 4694 a.cur.node = node 4695 if !a.post(&a.cur) { 4696 return false 4697 } 4698 } 4699 return true 4700 } 4701 func (a *application) rewriteRefOfModifyColumn(parent SQLNode, node *ModifyColumn, replacer replacerFunc) bool { 4702 if node == nil { 4703 return true 4704 } 4705 if a.pre != nil { 4706 a.cur.replacer = replacer 4707 a.cur.parent = parent 4708 a.cur.node = node 4709 if !a.pre(&a.cur) { 4710 return true 4711 } 4712 } 4713 if !a.rewriteRefOfColumnDefinition(node, node.NewColDefinition, func(newNode, parent SQLNode) { 4714 parent.(*ModifyColumn).NewColDefinition = newNode.(*ColumnDefinition) 4715 }) { 4716 return false 4717 } 4718 if !a.rewriteRefOfColName(node, node.After, func(newNode, parent SQLNode) { 4719 parent.(*ModifyColumn).After = newNode.(*ColName) 4720 }) { 4721 return false 4722 } 4723 if a.post != nil { 4724 a.cur.replacer = replacer 4725 a.cur.parent = parent 4726 a.cur.node = node 4727 if !a.post(&a.cur) { 4728 return false 4729 } 4730 } 4731 return true 4732 } 4733 func (a *application) rewriteRefOfNTHValueExpr(parent SQLNode, node *NTHValueExpr, replacer replacerFunc) bool { 4734 if node == nil { 4735 return true 4736 } 4737 if a.pre != nil { 4738 a.cur.replacer = replacer 4739 a.cur.parent = parent 4740 a.cur.node = node 4741 if !a.pre(&a.cur) { 4742 return true 4743 } 4744 } 4745 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 4746 parent.(*NTHValueExpr).Expr = newNode.(Expr) 4747 }) { 4748 return false 4749 } 4750 if !a.rewriteExpr(node, node.N, func(newNode, parent SQLNode) { 4751 parent.(*NTHValueExpr).N = newNode.(Expr) 4752 }) { 4753 return false 4754 } 4755 if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { 4756 parent.(*NTHValueExpr).OverClause = newNode.(*OverClause) 4757 }) { 4758 return false 4759 } 4760 if !a.rewriteRefOfFromFirstLastClause(node, node.FromFirstLastClause, func(newNode, parent SQLNode) { 4761 parent.(*NTHValueExpr).FromFirstLastClause = newNode.(*FromFirstLastClause) 4762 }) { 4763 return false 4764 } 4765 if !a.rewriteRefOfNullTreatmentClause(node, node.NullTreatmentClause, func(newNode, parent SQLNode) { 4766 parent.(*NTHValueExpr).NullTreatmentClause = newNode.(*NullTreatmentClause) 4767 }) { 4768 return false 4769 } 4770 if a.post != nil { 4771 a.cur.replacer = replacer 4772 a.cur.parent = parent 4773 a.cur.node = node 4774 if !a.post(&a.cur) { 4775 return false 4776 } 4777 } 4778 return true 4779 } 4780 func (a *application) rewriteRefOfNamedWindow(parent SQLNode, node *NamedWindow, replacer replacerFunc) bool { 4781 if node == nil { 4782 return true 4783 } 4784 if a.pre != nil { 4785 a.cur.replacer = replacer 4786 a.cur.parent = parent 4787 a.cur.node = node 4788 if !a.pre(&a.cur) { 4789 return true 4790 } 4791 } 4792 if !a.rewriteWindowDefinitions(node, node.Windows, func(newNode, parent SQLNode) { 4793 parent.(*NamedWindow).Windows = newNode.(WindowDefinitions) 4794 }) { 4795 return false 4796 } 4797 if a.post != nil { 4798 a.cur.replacer = replacer 4799 a.cur.parent = parent 4800 a.cur.node = node 4801 if !a.post(&a.cur) { 4802 return false 4803 } 4804 } 4805 return true 4806 } 4807 func (a *application) rewriteNamedWindows(parent SQLNode, node NamedWindows, replacer replacerFunc) bool { 4808 if node == nil { 4809 return true 4810 } 4811 if a.pre != nil { 4812 a.cur.replacer = replacer 4813 a.cur.parent = parent 4814 a.cur.node = node 4815 kontinue := !a.pre(&a.cur) 4816 if a.cur.revisit { 4817 node = a.cur.node.(NamedWindows) 4818 a.cur.revisit = false 4819 return a.rewriteNamedWindows(parent, node, replacer) 4820 } 4821 if kontinue { 4822 return true 4823 } 4824 } 4825 for x, el := range node { 4826 if !a.rewriteRefOfNamedWindow(node, el, func(idx int) replacerFunc { 4827 return func(newNode, parent SQLNode) { 4828 parent.(NamedWindows)[idx] = newNode.(*NamedWindow) 4829 } 4830 }(x)) { 4831 return false 4832 } 4833 } 4834 if a.post != nil { 4835 a.cur.replacer = replacer 4836 a.cur.parent = parent 4837 a.cur.node = node 4838 if !a.post(&a.cur) { 4839 return false 4840 } 4841 } 4842 return true 4843 } 4844 func (a *application) rewriteRefOfNextval(parent SQLNode, node *Nextval, replacer replacerFunc) bool { 4845 if node == nil { 4846 return true 4847 } 4848 if a.pre != nil { 4849 a.cur.replacer = replacer 4850 a.cur.parent = parent 4851 a.cur.node = node 4852 if !a.pre(&a.cur) { 4853 return true 4854 } 4855 } 4856 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 4857 parent.(*Nextval).Expr = newNode.(Expr) 4858 }) { 4859 return false 4860 } 4861 if a.post != nil { 4862 a.cur.replacer = replacer 4863 a.cur.parent = parent 4864 a.cur.node = node 4865 if !a.post(&a.cur) { 4866 return false 4867 } 4868 } 4869 return true 4870 } 4871 func (a *application) rewriteRefOfNotExpr(parent SQLNode, node *NotExpr, replacer replacerFunc) bool { 4872 if node == nil { 4873 return true 4874 } 4875 if a.pre != nil { 4876 a.cur.replacer = replacer 4877 a.cur.parent = parent 4878 a.cur.node = node 4879 if !a.pre(&a.cur) { 4880 return true 4881 } 4882 } 4883 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 4884 parent.(*NotExpr).Expr = newNode.(Expr) 4885 }) { 4886 return false 4887 } 4888 if a.post != nil { 4889 a.cur.replacer = replacer 4890 a.cur.parent = parent 4891 a.cur.node = node 4892 if !a.post(&a.cur) { 4893 return false 4894 } 4895 } 4896 return true 4897 } 4898 func (a *application) rewriteRefOfNtileExpr(parent SQLNode, node *NtileExpr, replacer replacerFunc) bool { 4899 if node == nil { 4900 return true 4901 } 4902 if a.pre != nil { 4903 a.cur.replacer = replacer 4904 a.cur.parent = parent 4905 a.cur.node = node 4906 if !a.pre(&a.cur) { 4907 return true 4908 } 4909 } 4910 if !a.rewriteExpr(node, node.N, func(newNode, parent SQLNode) { 4911 parent.(*NtileExpr).N = newNode.(Expr) 4912 }) { 4913 return false 4914 } 4915 if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { 4916 parent.(*NtileExpr).OverClause = newNode.(*OverClause) 4917 }) { 4918 return false 4919 } 4920 if a.post != nil { 4921 a.cur.replacer = replacer 4922 a.cur.parent = parent 4923 a.cur.node = node 4924 if !a.post(&a.cur) { 4925 return false 4926 } 4927 } 4928 return true 4929 } 4930 func (a *application) rewriteRefOfNullTreatmentClause(parent SQLNode, node *NullTreatmentClause, replacer replacerFunc) bool { 4931 if node == nil { 4932 return true 4933 } 4934 if a.pre != nil { 4935 a.cur.replacer = replacer 4936 a.cur.parent = parent 4937 a.cur.node = node 4938 if !a.pre(&a.cur) { 4939 return true 4940 } 4941 } 4942 if a.post != nil { 4943 if a.pre == nil { 4944 a.cur.replacer = replacer 4945 a.cur.parent = parent 4946 a.cur.node = node 4947 } 4948 if !a.post(&a.cur) { 4949 return false 4950 } 4951 } 4952 return true 4953 } 4954 func (a *application) rewriteRefOfNullVal(parent SQLNode, node *NullVal, replacer replacerFunc) bool { 4955 if node == nil { 4956 return true 4957 } 4958 if a.pre != nil { 4959 a.cur.replacer = replacer 4960 a.cur.parent = parent 4961 a.cur.node = node 4962 if !a.pre(&a.cur) { 4963 return true 4964 } 4965 } 4966 if a.post != nil { 4967 if a.pre == nil { 4968 a.cur.replacer = replacer 4969 a.cur.parent = parent 4970 a.cur.node = node 4971 } 4972 if !a.post(&a.cur) { 4973 return false 4974 } 4975 } 4976 return true 4977 } 4978 func (a *application) rewriteRefOfOffset(parent SQLNode, node *Offset, replacer replacerFunc) bool { 4979 if node == nil { 4980 return true 4981 } 4982 if a.pre != nil { 4983 a.cur.replacer = replacer 4984 a.cur.parent = parent 4985 a.cur.node = node 4986 if !a.pre(&a.cur) { 4987 return true 4988 } 4989 } 4990 if a.post != nil { 4991 if a.pre == nil { 4992 a.cur.replacer = replacer 4993 a.cur.parent = parent 4994 a.cur.node = node 4995 } 4996 if !a.post(&a.cur) { 4997 return false 4998 } 4999 } 5000 return true 5001 } 5002 func (a *application) rewriteOnDup(parent SQLNode, node OnDup, replacer replacerFunc) bool { 5003 if node == nil { 5004 return true 5005 } 5006 if a.pre != nil { 5007 a.cur.replacer = replacer 5008 a.cur.parent = parent 5009 a.cur.node = node 5010 kontinue := !a.pre(&a.cur) 5011 if a.cur.revisit { 5012 node = a.cur.node.(OnDup) 5013 a.cur.revisit = false 5014 return a.rewriteOnDup(parent, node, replacer) 5015 } 5016 if kontinue { 5017 return true 5018 } 5019 } 5020 for x, el := range node { 5021 if !a.rewriteRefOfUpdateExpr(node, el, func(idx int) replacerFunc { 5022 return func(newNode, parent SQLNode) { 5023 parent.(OnDup)[idx] = newNode.(*UpdateExpr) 5024 } 5025 }(x)) { 5026 return false 5027 } 5028 } 5029 if a.post != nil { 5030 a.cur.replacer = replacer 5031 a.cur.parent = parent 5032 a.cur.node = node 5033 if !a.post(&a.cur) { 5034 return false 5035 } 5036 } 5037 return true 5038 } 5039 func (a *application) rewriteRefOfOptLike(parent SQLNode, node *OptLike, replacer replacerFunc) bool { 5040 if node == nil { 5041 return true 5042 } 5043 if a.pre != nil { 5044 a.cur.replacer = replacer 5045 a.cur.parent = parent 5046 a.cur.node = node 5047 if !a.pre(&a.cur) { 5048 return true 5049 } 5050 } 5051 if !a.rewriteTableName(node, node.LikeTable, func(newNode, parent SQLNode) { 5052 parent.(*OptLike).LikeTable = newNode.(TableName) 5053 }) { 5054 return false 5055 } 5056 if a.post != nil { 5057 a.cur.replacer = replacer 5058 a.cur.parent = parent 5059 a.cur.node = node 5060 if !a.post(&a.cur) { 5061 return false 5062 } 5063 } 5064 return true 5065 } 5066 func (a *application) rewriteRefOfOrExpr(parent SQLNode, node *OrExpr, replacer replacerFunc) bool { 5067 if node == nil { 5068 return true 5069 } 5070 if a.pre != nil { 5071 a.cur.replacer = replacer 5072 a.cur.parent = parent 5073 a.cur.node = node 5074 if !a.pre(&a.cur) { 5075 return true 5076 } 5077 } 5078 if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { 5079 parent.(*OrExpr).Left = newNode.(Expr) 5080 }) { 5081 return false 5082 } 5083 if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { 5084 parent.(*OrExpr).Right = newNode.(Expr) 5085 }) { 5086 return false 5087 } 5088 if a.post != nil { 5089 a.cur.replacer = replacer 5090 a.cur.parent = parent 5091 a.cur.node = node 5092 if !a.post(&a.cur) { 5093 return false 5094 } 5095 } 5096 return true 5097 } 5098 func (a *application) rewriteRefOfOrder(parent SQLNode, node *Order, replacer replacerFunc) bool { 5099 if node == nil { 5100 return true 5101 } 5102 if a.pre != nil { 5103 a.cur.replacer = replacer 5104 a.cur.parent = parent 5105 a.cur.node = node 5106 if !a.pre(&a.cur) { 5107 return true 5108 } 5109 } 5110 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 5111 parent.(*Order).Expr = newNode.(Expr) 5112 }) { 5113 return false 5114 } 5115 if a.post != nil { 5116 a.cur.replacer = replacer 5117 a.cur.parent = parent 5118 a.cur.node = node 5119 if !a.post(&a.cur) { 5120 return false 5121 } 5122 } 5123 return true 5124 } 5125 func (a *application) rewriteOrderBy(parent SQLNode, node OrderBy, replacer replacerFunc) bool { 5126 if node == nil { 5127 return true 5128 } 5129 if a.pre != nil { 5130 a.cur.replacer = replacer 5131 a.cur.parent = parent 5132 a.cur.node = node 5133 kontinue := !a.pre(&a.cur) 5134 if a.cur.revisit { 5135 node = a.cur.node.(OrderBy) 5136 a.cur.revisit = false 5137 return a.rewriteOrderBy(parent, node, replacer) 5138 } 5139 if kontinue { 5140 return true 5141 } 5142 } 5143 for x, el := range node { 5144 if !a.rewriteRefOfOrder(node, el, func(idx int) replacerFunc { 5145 return func(newNode, parent SQLNode) { 5146 parent.(OrderBy)[idx] = newNode.(*Order) 5147 } 5148 }(x)) { 5149 return false 5150 } 5151 } 5152 if a.post != nil { 5153 a.cur.replacer = replacer 5154 a.cur.parent = parent 5155 a.cur.node = node 5156 if !a.post(&a.cur) { 5157 return false 5158 } 5159 } 5160 return true 5161 } 5162 func (a *application) rewriteRefOfOrderByOption(parent SQLNode, node *OrderByOption, replacer replacerFunc) bool { 5163 if node == nil { 5164 return true 5165 } 5166 if a.pre != nil { 5167 a.cur.replacer = replacer 5168 a.cur.parent = parent 5169 a.cur.node = node 5170 if !a.pre(&a.cur) { 5171 return true 5172 } 5173 } 5174 if !a.rewriteColumns(node, node.Cols, func(newNode, parent SQLNode) { 5175 parent.(*OrderByOption).Cols = newNode.(Columns) 5176 }) { 5177 return false 5178 } 5179 if a.post != nil { 5180 a.cur.replacer = replacer 5181 a.cur.parent = parent 5182 a.cur.node = node 5183 if !a.post(&a.cur) { 5184 return false 5185 } 5186 } 5187 return true 5188 } 5189 func (a *application) rewriteRefOfOtherAdmin(parent SQLNode, node *OtherAdmin, replacer replacerFunc) bool { 5190 if node == nil { 5191 return true 5192 } 5193 if a.pre != nil { 5194 a.cur.replacer = replacer 5195 a.cur.parent = parent 5196 a.cur.node = node 5197 if !a.pre(&a.cur) { 5198 return true 5199 } 5200 } 5201 if a.post != nil { 5202 if a.pre == nil { 5203 a.cur.replacer = replacer 5204 a.cur.parent = parent 5205 a.cur.node = node 5206 } 5207 if !a.post(&a.cur) { 5208 return false 5209 } 5210 } 5211 return true 5212 } 5213 func (a *application) rewriteRefOfOtherRead(parent SQLNode, node *OtherRead, replacer replacerFunc) bool { 5214 if node == nil { 5215 return true 5216 } 5217 if a.pre != nil { 5218 a.cur.replacer = replacer 5219 a.cur.parent = parent 5220 a.cur.node = node 5221 if !a.pre(&a.cur) { 5222 return true 5223 } 5224 } 5225 if a.post != nil { 5226 if a.pre == nil { 5227 a.cur.replacer = replacer 5228 a.cur.parent = parent 5229 a.cur.node = node 5230 } 5231 if !a.post(&a.cur) { 5232 return false 5233 } 5234 } 5235 return true 5236 } 5237 func (a *application) rewriteRefOfOverClause(parent SQLNode, node *OverClause, replacer replacerFunc) bool { 5238 if node == nil { 5239 return true 5240 } 5241 if a.pre != nil { 5242 a.cur.replacer = replacer 5243 a.cur.parent = parent 5244 a.cur.node = node 5245 if !a.pre(&a.cur) { 5246 return true 5247 } 5248 } 5249 if !a.rewriteIdentifierCI(node, node.WindowName, func(newNode, parent SQLNode) { 5250 parent.(*OverClause).WindowName = newNode.(IdentifierCI) 5251 }) { 5252 return false 5253 } 5254 if !a.rewriteRefOfWindowSpecification(node, node.WindowSpec, func(newNode, parent SQLNode) { 5255 parent.(*OverClause).WindowSpec = newNode.(*WindowSpecification) 5256 }) { 5257 return false 5258 } 5259 if a.post != nil { 5260 a.cur.replacer = replacer 5261 a.cur.parent = parent 5262 a.cur.node = node 5263 if !a.post(&a.cur) { 5264 return false 5265 } 5266 } 5267 return true 5268 } 5269 func (a *application) rewriteRefOfParenTableExpr(parent SQLNode, node *ParenTableExpr, replacer replacerFunc) bool { 5270 if node == nil { 5271 return true 5272 } 5273 if a.pre != nil { 5274 a.cur.replacer = replacer 5275 a.cur.parent = parent 5276 a.cur.node = node 5277 if !a.pre(&a.cur) { 5278 return true 5279 } 5280 } 5281 if !a.rewriteTableExprs(node, node.Exprs, func(newNode, parent SQLNode) { 5282 parent.(*ParenTableExpr).Exprs = newNode.(TableExprs) 5283 }) { 5284 return false 5285 } 5286 if a.post != nil { 5287 a.cur.replacer = replacer 5288 a.cur.parent = parent 5289 a.cur.node = node 5290 if !a.post(&a.cur) { 5291 return false 5292 } 5293 } 5294 return true 5295 } 5296 func (a *application) rewriteRefOfParsedComments(parent SQLNode, node *ParsedComments, replacer replacerFunc) bool { 5297 if node == nil { 5298 return true 5299 } 5300 if a.pre != nil { 5301 a.cur.replacer = replacer 5302 a.cur.parent = parent 5303 a.cur.node = node 5304 if !a.pre(&a.cur) { 5305 return true 5306 } 5307 } 5308 if a.post != nil { 5309 if a.pre == nil { 5310 a.cur.replacer = replacer 5311 a.cur.parent = parent 5312 a.cur.node = node 5313 } 5314 if !a.post(&a.cur) { 5315 return false 5316 } 5317 } 5318 return true 5319 } 5320 func (a *application) rewriteRefOfPartitionDefinition(parent SQLNode, node *PartitionDefinition, replacer replacerFunc) bool { 5321 if node == nil { 5322 return true 5323 } 5324 if a.pre != nil { 5325 a.cur.replacer = replacer 5326 a.cur.parent = parent 5327 a.cur.node = node 5328 if !a.pre(&a.cur) { 5329 return true 5330 } 5331 } 5332 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 5333 parent.(*PartitionDefinition).Name = newNode.(IdentifierCI) 5334 }) { 5335 return false 5336 } 5337 if !a.rewriteRefOfPartitionDefinitionOptions(node, node.Options, func(newNode, parent SQLNode) { 5338 parent.(*PartitionDefinition).Options = newNode.(*PartitionDefinitionOptions) 5339 }) { 5340 return false 5341 } 5342 if a.post != nil { 5343 a.cur.replacer = replacer 5344 a.cur.parent = parent 5345 a.cur.node = node 5346 if !a.post(&a.cur) { 5347 return false 5348 } 5349 } 5350 return true 5351 } 5352 func (a *application) rewriteRefOfPartitionDefinitionOptions(parent SQLNode, node *PartitionDefinitionOptions, replacer replacerFunc) bool { 5353 if node == nil { 5354 return true 5355 } 5356 if a.pre != nil { 5357 a.cur.replacer = replacer 5358 a.cur.parent = parent 5359 a.cur.node = node 5360 if !a.pre(&a.cur) { 5361 return true 5362 } 5363 } 5364 if !a.rewriteRefOfPartitionValueRange(node, node.ValueRange, func(newNode, parent SQLNode) { 5365 parent.(*PartitionDefinitionOptions).ValueRange = newNode.(*PartitionValueRange) 5366 }) { 5367 return false 5368 } 5369 if !a.rewriteRefOfLiteral(node, node.Comment, func(newNode, parent SQLNode) { 5370 parent.(*PartitionDefinitionOptions).Comment = newNode.(*Literal) 5371 }) { 5372 return false 5373 } 5374 if !a.rewriteRefOfPartitionEngine(node, node.Engine, func(newNode, parent SQLNode) { 5375 parent.(*PartitionDefinitionOptions).Engine = newNode.(*PartitionEngine) 5376 }) { 5377 return false 5378 } 5379 if !a.rewriteRefOfLiteral(node, node.DataDirectory, func(newNode, parent SQLNode) { 5380 parent.(*PartitionDefinitionOptions).DataDirectory = newNode.(*Literal) 5381 }) { 5382 return false 5383 } 5384 if !a.rewriteRefOfLiteral(node, node.IndexDirectory, func(newNode, parent SQLNode) { 5385 parent.(*PartitionDefinitionOptions).IndexDirectory = newNode.(*Literal) 5386 }) { 5387 return false 5388 } 5389 if !a.rewriteSubPartitionDefinitions(node, node.SubPartitionDefinitions, func(newNode, parent SQLNode) { 5390 parent.(*PartitionDefinitionOptions).SubPartitionDefinitions = newNode.(SubPartitionDefinitions) 5391 }) { 5392 return false 5393 } 5394 if a.post != nil { 5395 a.cur.replacer = replacer 5396 a.cur.parent = parent 5397 a.cur.node = node 5398 if !a.post(&a.cur) { 5399 return false 5400 } 5401 } 5402 return true 5403 } 5404 func (a *application) rewriteRefOfPartitionEngine(parent SQLNode, node *PartitionEngine, replacer replacerFunc) bool { 5405 if node == nil { 5406 return true 5407 } 5408 if a.pre != nil { 5409 a.cur.replacer = replacer 5410 a.cur.parent = parent 5411 a.cur.node = node 5412 if !a.pre(&a.cur) { 5413 return true 5414 } 5415 } 5416 if a.post != nil { 5417 if a.pre == nil { 5418 a.cur.replacer = replacer 5419 a.cur.parent = parent 5420 a.cur.node = node 5421 } 5422 if !a.post(&a.cur) { 5423 return false 5424 } 5425 } 5426 return true 5427 } 5428 func (a *application) rewriteRefOfPartitionOption(parent SQLNode, node *PartitionOption, replacer replacerFunc) bool { 5429 if node == nil { 5430 return true 5431 } 5432 if a.pre != nil { 5433 a.cur.replacer = replacer 5434 a.cur.parent = parent 5435 a.cur.node = node 5436 if !a.pre(&a.cur) { 5437 return true 5438 } 5439 } 5440 if !a.rewriteColumns(node, node.ColList, func(newNode, parent SQLNode) { 5441 parent.(*PartitionOption).ColList = newNode.(Columns) 5442 }) { 5443 return false 5444 } 5445 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 5446 parent.(*PartitionOption).Expr = newNode.(Expr) 5447 }) { 5448 return false 5449 } 5450 if !a.rewriteRefOfSubPartition(node, node.SubPartition, func(newNode, parent SQLNode) { 5451 parent.(*PartitionOption).SubPartition = newNode.(*SubPartition) 5452 }) { 5453 return false 5454 } 5455 for x, el := range node.Definitions { 5456 if !a.rewriteRefOfPartitionDefinition(node, el, func(idx int) replacerFunc { 5457 return func(newNode, parent SQLNode) { 5458 parent.(*PartitionOption).Definitions[idx] = newNode.(*PartitionDefinition) 5459 } 5460 }(x)) { 5461 return false 5462 } 5463 } 5464 if a.post != nil { 5465 a.cur.replacer = replacer 5466 a.cur.parent = parent 5467 a.cur.node = node 5468 if !a.post(&a.cur) { 5469 return false 5470 } 5471 } 5472 return true 5473 } 5474 func (a *application) rewriteRefOfPartitionSpec(parent SQLNode, node *PartitionSpec, replacer replacerFunc) bool { 5475 if node == nil { 5476 return true 5477 } 5478 if a.pre != nil { 5479 a.cur.replacer = replacer 5480 a.cur.parent = parent 5481 a.cur.node = node 5482 if !a.pre(&a.cur) { 5483 return true 5484 } 5485 } 5486 if !a.rewritePartitions(node, node.Names, func(newNode, parent SQLNode) { 5487 parent.(*PartitionSpec).Names = newNode.(Partitions) 5488 }) { 5489 return false 5490 } 5491 if !a.rewriteRefOfLiteral(node, node.Number, func(newNode, parent SQLNode) { 5492 parent.(*PartitionSpec).Number = newNode.(*Literal) 5493 }) { 5494 return false 5495 } 5496 if !a.rewriteTableName(node, node.TableName, func(newNode, parent SQLNode) { 5497 parent.(*PartitionSpec).TableName = newNode.(TableName) 5498 }) { 5499 return false 5500 } 5501 for x, el := range node.Definitions { 5502 if !a.rewriteRefOfPartitionDefinition(node, el, func(idx int) replacerFunc { 5503 return func(newNode, parent SQLNode) { 5504 parent.(*PartitionSpec).Definitions[idx] = newNode.(*PartitionDefinition) 5505 } 5506 }(x)) { 5507 return false 5508 } 5509 } 5510 if a.post != nil { 5511 a.cur.replacer = replacer 5512 a.cur.parent = parent 5513 a.cur.node = node 5514 if !a.post(&a.cur) { 5515 return false 5516 } 5517 } 5518 return true 5519 } 5520 func (a *application) rewriteRefOfPartitionValueRange(parent SQLNode, node *PartitionValueRange, replacer replacerFunc) bool { 5521 if node == nil { 5522 return true 5523 } 5524 if a.pre != nil { 5525 a.cur.replacer = replacer 5526 a.cur.parent = parent 5527 a.cur.node = node 5528 if !a.pre(&a.cur) { 5529 return true 5530 } 5531 } 5532 if !a.rewriteValTuple(node, node.Range, func(newNode, parent SQLNode) { 5533 parent.(*PartitionValueRange).Range = newNode.(ValTuple) 5534 }) { 5535 return false 5536 } 5537 if a.post != nil { 5538 a.cur.replacer = replacer 5539 a.cur.parent = parent 5540 a.cur.node = node 5541 if !a.post(&a.cur) { 5542 return false 5543 } 5544 } 5545 return true 5546 } 5547 func (a *application) rewritePartitions(parent SQLNode, node Partitions, replacer replacerFunc) bool { 5548 if node == nil { 5549 return true 5550 } 5551 if a.pre != nil { 5552 a.cur.replacer = replacer 5553 a.cur.parent = parent 5554 a.cur.node = node 5555 kontinue := !a.pre(&a.cur) 5556 if a.cur.revisit { 5557 node = a.cur.node.(Partitions) 5558 a.cur.revisit = false 5559 return a.rewritePartitions(parent, node, replacer) 5560 } 5561 if kontinue { 5562 return true 5563 } 5564 } 5565 for x, el := range node { 5566 if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { 5567 return func(newNode, parent SQLNode) { 5568 parent.(Partitions)[idx] = newNode.(IdentifierCI) 5569 } 5570 }(x)) { 5571 return false 5572 } 5573 } 5574 if a.post != nil { 5575 a.cur.replacer = replacer 5576 a.cur.parent = parent 5577 a.cur.node = node 5578 if !a.post(&a.cur) { 5579 return false 5580 } 5581 } 5582 return true 5583 } 5584 func (a *application) rewriteRefOfPerformanceSchemaFuncExpr(parent SQLNode, node *PerformanceSchemaFuncExpr, replacer replacerFunc) bool { 5585 if node == nil { 5586 return true 5587 } 5588 if a.pre != nil { 5589 a.cur.replacer = replacer 5590 a.cur.parent = parent 5591 a.cur.node = node 5592 if !a.pre(&a.cur) { 5593 return true 5594 } 5595 } 5596 if !a.rewriteExpr(node, node.Argument, func(newNode, parent SQLNode) { 5597 parent.(*PerformanceSchemaFuncExpr).Argument = newNode.(Expr) 5598 }) { 5599 return false 5600 } 5601 if a.post != nil { 5602 a.cur.replacer = replacer 5603 a.cur.parent = parent 5604 a.cur.node = node 5605 if !a.post(&a.cur) { 5606 return false 5607 } 5608 } 5609 return true 5610 } 5611 func (a *application) rewriteRefOfPointExpr(parent SQLNode, node *PointExpr, replacer replacerFunc) bool { 5612 if node == nil { 5613 return true 5614 } 5615 if a.pre != nil { 5616 a.cur.replacer = replacer 5617 a.cur.parent = parent 5618 a.cur.node = node 5619 if !a.pre(&a.cur) { 5620 return true 5621 } 5622 } 5623 if !a.rewriteExpr(node, node.XCordinate, func(newNode, parent SQLNode) { 5624 parent.(*PointExpr).XCordinate = newNode.(Expr) 5625 }) { 5626 return false 5627 } 5628 if !a.rewriteExpr(node, node.YCordinate, func(newNode, parent SQLNode) { 5629 parent.(*PointExpr).YCordinate = newNode.(Expr) 5630 }) { 5631 return false 5632 } 5633 if a.post != nil { 5634 a.cur.replacer = replacer 5635 a.cur.parent = parent 5636 a.cur.node = node 5637 if !a.post(&a.cur) { 5638 return false 5639 } 5640 } 5641 return true 5642 } 5643 func (a *application) rewriteRefOfPrepareStmt(parent SQLNode, node *PrepareStmt, replacer replacerFunc) bool { 5644 if node == nil { 5645 return true 5646 } 5647 if a.pre != nil { 5648 a.cur.replacer = replacer 5649 a.cur.parent = parent 5650 a.cur.node = node 5651 if !a.pre(&a.cur) { 5652 return true 5653 } 5654 } 5655 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 5656 parent.(*PrepareStmt).Name = newNode.(IdentifierCI) 5657 }) { 5658 return false 5659 } 5660 if !a.rewriteExpr(node, node.Statement, func(newNode, parent SQLNode) { 5661 parent.(*PrepareStmt).Statement = newNode.(Expr) 5662 }) { 5663 return false 5664 } 5665 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 5666 parent.(*PrepareStmt).Comments = newNode.(*ParsedComments) 5667 }) { 5668 return false 5669 } 5670 if a.post != nil { 5671 a.cur.replacer = replacer 5672 a.cur.parent = parent 5673 a.cur.node = node 5674 if !a.post(&a.cur) { 5675 return false 5676 } 5677 } 5678 return true 5679 } 5680 func (a *application) rewriteRefOfReferenceDefinition(parent SQLNode, node *ReferenceDefinition, replacer replacerFunc) bool { 5681 if node == nil { 5682 return true 5683 } 5684 if a.pre != nil { 5685 a.cur.replacer = replacer 5686 a.cur.parent = parent 5687 a.cur.node = node 5688 if !a.pre(&a.cur) { 5689 return true 5690 } 5691 } 5692 if !a.rewriteTableName(node, node.ReferencedTable, func(newNode, parent SQLNode) { 5693 parent.(*ReferenceDefinition).ReferencedTable = newNode.(TableName) 5694 }) { 5695 return false 5696 } 5697 if !a.rewriteColumns(node, node.ReferencedColumns, func(newNode, parent SQLNode) { 5698 parent.(*ReferenceDefinition).ReferencedColumns = newNode.(Columns) 5699 }) { 5700 return false 5701 } 5702 if !a.rewriteMatchAction(node, node.Match, func(newNode, parent SQLNode) { 5703 parent.(*ReferenceDefinition).Match = newNode.(MatchAction) 5704 }) { 5705 return false 5706 } 5707 if !a.rewriteReferenceAction(node, node.OnDelete, func(newNode, parent SQLNode) { 5708 parent.(*ReferenceDefinition).OnDelete = newNode.(ReferenceAction) 5709 }) { 5710 return false 5711 } 5712 if !a.rewriteReferenceAction(node, node.OnUpdate, func(newNode, parent SQLNode) { 5713 parent.(*ReferenceDefinition).OnUpdate = newNode.(ReferenceAction) 5714 }) { 5715 return false 5716 } 5717 if a.post != nil { 5718 a.cur.replacer = replacer 5719 a.cur.parent = parent 5720 a.cur.node = node 5721 if !a.post(&a.cur) { 5722 return false 5723 } 5724 } 5725 return true 5726 } 5727 func (a *application) rewriteRefOfRegexpInstrExpr(parent SQLNode, node *RegexpInstrExpr, replacer replacerFunc) bool { 5728 if node == nil { 5729 return true 5730 } 5731 if a.pre != nil { 5732 a.cur.replacer = replacer 5733 a.cur.parent = parent 5734 a.cur.node = node 5735 if !a.pre(&a.cur) { 5736 return true 5737 } 5738 } 5739 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 5740 parent.(*RegexpInstrExpr).Expr = newNode.(Expr) 5741 }) { 5742 return false 5743 } 5744 if !a.rewriteExpr(node, node.Pattern, func(newNode, parent SQLNode) { 5745 parent.(*RegexpInstrExpr).Pattern = newNode.(Expr) 5746 }) { 5747 return false 5748 } 5749 if !a.rewriteExpr(node, node.Position, func(newNode, parent SQLNode) { 5750 parent.(*RegexpInstrExpr).Position = newNode.(Expr) 5751 }) { 5752 return false 5753 } 5754 if !a.rewriteExpr(node, node.Occurrence, func(newNode, parent SQLNode) { 5755 parent.(*RegexpInstrExpr).Occurrence = newNode.(Expr) 5756 }) { 5757 return false 5758 } 5759 if !a.rewriteExpr(node, node.ReturnOption, func(newNode, parent SQLNode) { 5760 parent.(*RegexpInstrExpr).ReturnOption = newNode.(Expr) 5761 }) { 5762 return false 5763 } 5764 if !a.rewriteExpr(node, node.MatchType, func(newNode, parent SQLNode) { 5765 parent.(*RegexpInstrExpr).MatchType = newNode.(Expr) 5766 }) { 5767 return false 5768 } 5769 if a.post != nil { 5770 a.cur.replacer = replacer 5771 a.cur.parent = parent 5772 a.cur.node = node 5773 if !a.post(&a.cur) { 5774 return false 5775 } 5776 } 5777 return true 5778 } 5779 func (a *application) rewriteRefOfRegexpLikeExpr(parent SQLNode, node *RegexpLikeExpr, replacer replacerFunc) bool { 5780 if node == nil { 5781 return true 5782 } 5783 if a.pre != nil { 5784 a.cur.replacer = replacer 5785 a.cur.parent = parent 5786 a.cur.node = node 5787 if !a.pre(&a.cur) { 5788 return true 5789 } 5790 } 5791 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 5792 parent.(*RegexpLikeExpr).Expr = newNode.(Expr) 5793 }) { 5794 return false 5795 } 5796 if !a.rewriteExpr(node, node.Pattern, func(newNode, parent SQLNode) { 5797 parent.(*RegexpLikeExpr).Pattern = newNode.(Expr) 5798 }) { 5799 return false 5800 } 5801 if !a.rewriteExpr(node, node.MatchType, func(newNode, parent SQLNode) { 5802 parent.(*RegexpLikeExpr).MatchType = newNode.(Expr) 5803 }) { 5804 return false 5805 } 5806 if a.post != nil { 5807 a.cur.replacer = replacer 5808 a.cur.parent = parent 5809 a.cur.node = node 5810 if !a.post(&a.cur) { 5811 return false 5812 } 5813 } 5814 return true 5815 } 5816 func (a *application) rewriteRefOfRegexpReplaceExpr(parent SQLNode, node *RegexpReplaceExpr, replacer replacerFunc) bool { 5817 if node == nil { 5818 return true 5819 } 5820 if a.pre != nil { 5821 a.cur.replacer = replacer 5822 a.cur.parent = parent 5823 a.cur.node = node 5824 if !a.pre(&a.cur) { 5825 return true 5826 } 5827 } 5828 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 5829 parent.(*RegexpReplaceExpr).Expr = newNode.(Expr) 5830 }) { 5831 return false 5832 } 5833 if !a.rewriteExpr(node, node.Pattern, func(newNode, parent SQLNode) { 5834 parent.(*RegexpReplaceExpr).Pattern = newNode.(Expr) 5835 }) { 5836 return false 5837 } 5838 if !a.rewriteExpr(node, node.Repl, func(newNode, parent SQLNode) { 5839 parent.(*RegexpReplaceExpr).Repl = newNode.(Expr) 5840 }) { 5841 return false 5842 } 5843 if !a.rewriteExpr(node, node.Occurrence, func(newNode, parent SQLNode) { 5844 parent.(*RegexpReplaceExpr).Occurrence = newNode.(Expr) 5845 }) { 5846 return false 5847 } 5848 if !a.rewriteExpr(node, node.Position, func(newNode, parent SQLNode) { 5849 parent.(*RegexpReplaceExpr).Position = newNode.(Expr) 5850 }) { 5851 return false 5852 } 5853 if !a.rewriteExpr(node, node.MatchType, func(newNode, parent SQLNode) { 5854 parent.(*RegexpReplaceExpr).MatchType = newNode.(Expr) 5855 }) { 5856 return false 5857 } 5858 if a.post != nil { 5859 a.cur.replacer = replacer 5860 a.cur.parent = parent 5861 a.cur.node = node 5862 if !a.post(&a.cur) { 5863 return false 5864 } 5865 } 5866 return true 5867 } 5868 func (a *application) rewriteRefOfRegexpSubstrExpr(parent SQLNode, node *RegexpSubstrExpr, replacer replacerFunc) bool { 5869 if node == nil { 5870 return true 5871 } 5872 if a.pre != nil { 5873 a.cur.replacer = replacer 5874 a.cur.parent = parent 5875 a.cur.node = node 5876 if !a.pre(&a.cur) { 5877 return true 5878 } 5879 } 5880 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 5881 parent.(*RegexpSubstrExpr).Expr = newNode.(Expr) 5882 }) { 5883 return false 5884 } 5885 if !a.rewriteExpr(node, node.Pattern, func(newNode, parent SQLNode) { 5886 parent.(*RegexpSubstrExpr).Pattern = newNode.(Expr) 5887 }) { 5888 return false 5889 } 5890 if !a.rewriteExpr(node, node.Occurrence, func(newNode, parent SQLNode) { 5891 parent.(*RegexpSubstrExpr).Occurrence = newNode.(Expr) 5892 }) { 5893 return false 5894 } 5895 if !a.rewriteExpr(node, node.Position, func(newNode, parent SQLNode) { 5896 parent.(*RegexpSubstrExpr).Position = newNode.(Expr) 5897 }) { 5898 return false 5899 } 5900 if !a.rewriteExpr(node, node.MatchType, func(newNode, parent SQLNode) { 5901 parent.(*RegexpSubstrExpr).MatchType = newNode.(Expr) 5902 }) { 5903 return false 5904 } 5905 if a.post != nil { 5906 a.cur.replacer = replacer 5907 a.cur.parent = parent 5908 a.cur.node = node 5909 if !a.post(&a.cur) { 5910 return false 5911 } 5912 } 5913 return true 5914 } 5915 func (a *application) rewriteRefOfRelease(parent SQLNode, node *Release, replacer replacerFunc) bool { 5916 if node == nil { 5917 return true 5918 } 5919 if a.pre != nil { 5920 a.cur.replacer = replacer 5921 a.cur.parent = parent 5922 a.cur.node = node 5923 if !a.pre(&a.cur) { 5924 return true 5925 } 5926 } 5927 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 5928 parent.(*Release).Name = newNode.(IdentifierCI) 5929 }) { 5930 return false 5931 } 5932 if a.post != nil { 5933 a.cur.replacer = replacer 5934 a.cur.parent = parent 5935 a.cur.node = node 5936 if !a.post(&a.cur) { 5937 return false 5938 } 5939 } 5940 return true 5941 } 5942 func (a *application) rewriteRefOfRenameColumn(parent SQLNode, node *RenameColumn, replacer replacerFunc) bool { 5943 if node == nil { 5944 return true 5945 } 5946 if a.pre != nil { 5947 a.cur.replacer = replacer 5948 a.cur.parent = parent 5949 a.cur.node = node 5950 if !a.pre(&a.cur) { 5951 return true 5952 } 5953 } 5954 if !a.rewriteRefOfColName(node, node.OldName, func(newNode, parent SQLNode) { 5955 parent.(*RenameColumn).OldName = newNode.(*ColName) 5956 }) { 5957 return false 5958 } 5959 if !a.rewriteRefOfColName(node, node.NewName, func(newNode, parent SQLNode) { 5960 parent.(*RenameColumn).NewName = newNode.(*ColName) 5961 }) { 5962 return false 5963 } 5964 if a.post != nil { 5965 a.cur.replacer = replacer 5966 a.cur.parent = parent 5967 a.cur.node = node 5968 if !a.post(&a.cur) { 5969 return false 5970 } 5971 } 5972 return true 5973 } 5974 func (a *application) rewriteRefOfRenameIndex(parent SQLNode, node *RenameIndex, replacer replacerFunc) bool { 5975 if node == nil { 5976 return true 5977 } 5978 if a.pre != nil { 5979 a.cur.replacer = replacer 5980 a.cur.parent = parent 5981 a.cur.node = node 5982 if !a.pre(&a.cur) { 5983 return true 5984 } 5985 } 5986 if !a.rewriteIdentifierCI(node, node.OldName, func(newNode, parent SQLNode) { 5987 parent.(*RenameIndex).OldName = newNode.(IdentifierCI) 5988 }) { 5989 return false 5990 } 5991 if !a.rewriteIdentifierCI(node, node.NewName, func(newNode, parent SQLNode) { 5992 parent.(*RenameIndex).NewName = newNode.(IdentifierCI) 5993 }) { 5994 return false 5995 } 5996 if a.post != nil { 5997 a.cur.replacer = replacer 5998 a.cur.parent = parent 5999 a.cur.node = node 6000 if !a.post(&a.cur) { 6001 return false 6002 } 6003 } 6004 return true 6005 } 6006 func (a *application) rewriteRefOfRenameTable(parent SQLNode, node *RenameTable, replacer replacerFunc) bool { 6007 if node == nil { 6008 return true 6009 } 6010 if a.pre != nil { 6011 a.cur.replacer = replacer 6012 a.cur.parent = parent 6013 a.cur.node = node 6014 if !a.pre(&a.cur) { 6015 return true 6016 } 6017 } 6018 if a.post != nil { 6019 if a.pre == nil { 6020 a.cur.replacer = replacer 6021 a.cur.parent = parent 6022 a.cur.node = node 6023 } 6024 if !a.post(&a.cur) { 6025 return false 6026 } 6027 } 6028 return true 6029 } 6030 func (a *application) rewriteRefOfRenameTableName(parent SQLNode, node *RenameTableName, replacer replacerFunc) bool { 6031 if node == nil { 6032 return true 6033 } 6034 if a.pre != nil { 6035 a.cur.replacer = replacer 6036 a.cur.parent = parent 6037 a.cur.node = node 6038 if !a.pre(&a.cur) { 6039 return true 6040 } 6041 } 6042 if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { 6043 parent.(*RenameTableName).Table = newNode.(TableName) 6044 }) { 6045 return false 6046 } 6047 if a.post != nil { 6048 a.cur.replacer = replacer 6049 a.cur.parent = parent 6050 a.cur.node = node 6051 if !a.post(&a.cur) { 6052 return false 6053 } 6054 } 6055 return true 6056 } 6057 func (a *application) rewriteRefOfRevertMigration(parent SQLNode, node *RevertMigration, replacer replacerFunc) bool { 6058 if node == nil { 6059 return true 6060 } 6061 if a.pre != nil { 6062 a.cur.replacer = replacer 6063 a.cur.parent = parent 6064 a.cur.node = node 6065 if !a.pre(&a.cur) { 6066 return true 6067 } 6068 } 6069 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 6070 parent.(*RevertMigration).Comments = newNode.(*ParsedComments) 6071 }) { 6072 return false 6073 } 6074 if a.post != nil { 6075 a.cur.replacer = replacer 6076 a.cur.parent = parent 6077 a.cur.node = node 6078 if !a.post(&a.cur) { 6079 return false 6080 } 6081 } 6082 return true 6083 } 6084 func (a *application) rewriteRefOfRollback(parent SQLNode, node *Rollback, replacer replacerFunc) bool { 6085 if node == nil { 6086 return true 6087 } 6088 if a.pre != nil { 6089 a.cur.replacer = replacer 6090 a.cur.parent = parent 6091 a.cur.node = node 6092 if !a.pre(&a.cur) { 6093 return true 6094 } 6095 } 6096 if a.post != nil { 6097 if a.pre == nil { 6098 a.cur.replacer = replacer 6099 a.cur.parent = parent 6100 a.cur.node = node 6101 } 6102 if !a.post(&a.cur) { 6103 return false 6104 } 6105 } 6106 return true 6107 } 6108 func (a *application) rewriteRootNode(parent SQLNode, node RootNode, replacer replacerFunc) bool { 6109 if a.pre != nil { 6110 a.cur.replacer = replacer 6111 a.cur.parent = parent 6112 a.cur.node = node 6113 if !a.pre(&a.cur) { 6114 return true 6115 } 6116 } 6117 if !a.rewriteSQLNode(node, node.SQLNode, func(newNode, parent SQLNode) { 6118 panic("[BUG] tried to replace 'SQLNode' on 'RootNode'") 6119 }) { 6120 return false 6121 } 6122 if a.post != nil { 6123 a.cur.replacer = replacer 6124 a.cur.parent = parent 6125 a.cur.node = node 6126 if !a.post(&a.cur) { 6127 return false 6128 } 6129 } 6130 return true 6131 } 6132 func (a *application) rewriteRefOfSRollback(parent SQLNode, node *SRollback, replacer replacerFunc) bool { 6133 if node == nil { 6134 return true 6135 } 6136 if a.pre != nil { 6137 a.cur.replacer = replacer 6138 a.cur.parent = parent 6139 a.cur.node = node 6140 if !a.pre(&a.cur) { 6141 return true 6142 } 6143 } 6144 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 6145 parent.(*SRollback).Name = newNode.(IdentifierCI) 6146 }) { 6147 return false 6148 } 6149 if a.post != nil { 6150 a.cur.replacer = replacer 6151 a.cur.parent = parent 6152 a.cur.node = node 6153 if !a.post(&a.cur) { 6154 return false 6155 } 6156 } 6157 return true 6158 } 6159 func (a *application) rewriteRefOfSavepoint(parent SQLNode, node *Savepoint, replacer replacerFunc) bool { 6160 if node == nil { 6161 return true 6162 } 6163 if a.pre != nil { 6164 a.cur.replacer = replacer 6165 a.cur.parent = parent 6166 a.cur.node = node 6167 if !a.pre(&a.cur) { 6168 return true 6169 } 6170 } 6171 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 6172 parent.(*Savepoint).Name = newNode.(IdentifierCI) 6173 }) { 6174 return false 6175 } 6176 if a.post != nil { 6177 a.cur.replacer = replacer 6178 a.cur.parent = parent 6179 a.cur.node = node 6180 if !a.post(&a.cur) { 6181 return false 6182 } 6183 } 6184 return true 6185 } 6186 func (a *application) rewriteRefOfSelect(parent SQLNode, node *Select, replacer replacerFunc) bool { 6187 if node == nil { 6188 return true 6189 } 6190 if a.pre != nil { 6191 a.cur.replacer = replacer 6192 a.cur.parent = parent 6193 a.cur.node = node 6194 if !a.pre(&a.cur) { 6195 return true 6196 } 6197 } 6198 for x, el := range node.From { 6199 if !a.rewriteTableExpr(node, el, func(idx int) replacerFunc { 6200 return func(newNode, parent SQLNode) { 6201 parent.(*Select).From[idx] = newNode.(TableExpr) 6202 } 6203 }(x)) { 6204 return false 6205 } 6206 } 6207 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 6208 parent.(*Select).Comments = newNode.(*ParsedComments) 6209 }) { 6210 return false 6211 } 6212 if !a.rewriteSelectExprs(node, node.SelectExprs, func(newNode, parent SQLNode) { 6213 parent.(*Select).SelectExprs = newNode.(SelectExprs) 6214 }) { 6215 return false 6216 } 6217 if !a.rewriteRefOfWhere(node, node.Where, func(newNode, parent SQLNode) { 6218 parent.(*Select).Where = newNode.(*Where) 6219 }) { 6220 return false 6221 } 6222 if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { 6223 parent.(*Select).With = newNode.(*With) 6224 }) { 6225 return false 6226 } 6227 if !a.rewriteGroupBy(node, node.GroupBy, func(newNode, parent SQLNode) { 6228 parent.(*Select).GroupBy = newNode.(GroupBy) 6229 }) { 6230 return false 6231 } 6232 if !a.rewriteRefOfWhere(node, node.Having, func(newNode, parent SQLNode) { 6233 parent.(*Select).Having = newNode.(*Where) 6234 }) { 6235 return false 6236 } 6237 if !a.rewriteNamedWindows(node, node.Windows, func(newNode, parent SQLNode) { 6238 parent.(*Select).Windows = newNode.(NamedWindows) 6239 }) { 6240 return false 6241 } 6242 if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { 6243 parent.(*Select).OrderBy = newNode.(OrderBy) 6244 }) { 6245 return false 6246 } 6247 if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { 6248 parent.(*Select).Limit = newNode.(*Limit) 6249 }) { 6250 return false 6251 } 6252 if !a.rewriteRefOfSelectInto(node, node.Into, func(newNode, parent SQLNode) { 6253 parent.(*Select).Into = newNode.(*SelectInto) 6254 }) { 6255 return false 6256 } 6257 if a.post != nil { 6258 a.cur.replacer = replacer 6259 a.cur.parent = parent 6260 a.cur.node = node 6261 if !a.post(&a.cur) { 6262 return false 6263 } 6264 } 6265 return true 6266 } 6267 func (a *application) rewriteSelectExprs(parent SQLNode, node SelectExprs, replacer replacerFunc) bool { 6268 if node == nil { 6269 return true 6270 } 6271 if a.pre != nil { 6272 a.cur.replacer = replacer 6273 a.cur.parent = parent 6274 a.cur.node = node 6275 kontinue := !a.pre(&a.cur) 6276 if a.cur.revisit { 6277 node = a.cur.node.(SelectExprs) 6278 a.cur.revisit = false 6279 return a.rewriteSelectExprs(parent, node, replacer) 6280 } 6281 if kontinue { 6282 return true 6283 } 6284 } 6285 for x, el := range node { 6286 if !a.rewriteSelectExpr(node, el, func(idx int) replacerFunc { 6287 return func(newNode, parent SQLNode) { 6288 parent.(SelectExprs)[idx] = newNode.(SelectExpr) 6289 } 6290 }(x)) { 6291 return false 6292 } 6293 } 6294 if a.post != nil { 6295 a.cur.replacer = replacer 6296 a.cur.parent = parent 6297 a.cur.node = node 6298 if !a.post(&a.cur) { 6299 return false 6300 } 6301 } 6302 return true 6303 } 6304 func (a *application) rewriteRefOfSelectInto(parent SQLNode, node *SelectInto, replacer replacerFunc) bool { 6305 if node == nil { 6306 return true 6307 } 6308 if a.pre != nil { 6309 a.cur.replacer = replacer 6310 a.cur.parent = parent 6311 a.cur.node = node 6312 if !a.pre(&a.cur) { 6313 return true 6314 } 6315 } 6316 if a.post != nil { 6317 if a.pre == nil { 6318 a.cur.replacer = replacer 6319 a.cur.parent = parent 6320 a.cur.node = node 6321 } 6322 if !a.post(&a.cur) { 6323 return false 6324 } 6325 } 6326 return true 6327 } 6328 func (a *application) rewriteRefOfSet(parent SQLNode, node *Set, replacer replacerFunc) bool { 6329 if node == nil { 6330 return true 6331 } 6332 if a.pre != nil { 6333 a.cur.replacer = replacer 6334 a.cur.parent = parent 6335 a.cur.node = node 6336 if !a.pre(&a.cur) { 6337 return true 6338 } 6339 } 6340 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 6341 parent.(*Set).Comments = newNode.(*ParsedComments) 6342 }) { 6343 return false 6344 } 6345 if !a.rewriteSetExprs(node, node.Exprs, func(newNode, parent SQLNode) { 6346 parent.(*Set).Exprs = newNode.(SetExprs) 6347 }) { 6348 return false 6349 } 6350 if a.post != nil { 6351 a.cur.replacer = replacer 6352 a.cur.parent = parent 6353 a.cur.node = node 6354 if !a.post(&a.cur) { 6355 return false 6356 } 6357 } 6358 return true 6359 } 6360 func (a *application) rewriteRefOfSetExpr(parent SQLNode, node *SetExpr, replacer replacerFunc) bool { 6361 if node == nil { 6362 return true 6363 } 6364 if a.pre != nil { 6365 a.cur.replacer = replacer 6366 a.cur.parent = parent 6367 a.cur.node = node 6368 if !a.pre(&a.cur) { 6369 return true 6370 } 6371 } 6372 if !a.rewriteRefOfVariable(node, node.Var, func(newNode, parent SQLNode) { 6373 parent.(*SetExpr).Var = newNode.(*Variable) 6374 }) { 6375 return false 6376 } 6377 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 6378 parent.(*SetExpr).Expr = newNode.(Expr) 6379 }) { 6380 return false 6381 } 6382 if a.post != nil { 6383 a.cur.replacer = replacer 6384 a.cur.parent = parent 6385 a.cur.node = node 6386 if !a.post(&a.cur) { 6387 return false 6388 } 6389 } 6390 return true 6391 } 6392 func (a *application) rewriteSetExprs(parent SQLNode, node SetExprs, replacer replacerFunc) bool { 6393 if node == nil { 6394 return true 6395 } 6396 if a.pre != nil { 6397 a.cur.replacer = replacer 6398 a.cur.parent = parent 6399 a.cur.node = node 6400 kontinue := !a.pre(&a.cur) 6401 if a.cur.revisit { 6402 node = a.cur.node.(SetExprs) 6403 a.cur.revisit = false 6404 return a.rewriteSetExprs(parent, node, replacer) 6405 } 6406 if kontinue { 6407 return true 6408 } 6409 } 6410 for x, el := range node { 6411 if !a.rewriteRefOfSetExpr(node, el, func(idx int) replacerFunc { 6412 return func(newNode, parent SQLNode) { 6413 parent.(SetExprs)[idx] = newNode.(*SetExpr) 6414 } 6415 }(x)) { 6416 return false 6417 } 6418 } 6419 if a.post != nil { 6420 a.cur.replacer = replacer 6421 a.cur.parent = parent 6422 a.cur.node = node 6423 if !a.post(&a.cur) { 6424 return false 6425 } 6426 } 6427 return true 6428 } 6429 func (a *application) rewriteRefOfShow(parent SQLNode, node *Show, replacer replacerFunc) bool { 6430 if node == nil { 6431 return true 6432 } 6433 if a.pre != nil { 6434 a.cur.replacer = replacer 6435 a.cur.parent = parent 6436 a.cur.node = node 6437 if !a.pre(&a.cur) { 6438 return true 6439 } 6440 } 6441 if !a.rewriteShowInternal(node, node.Internal, func(newNode, parent SQLNode) { 6442 parent.(*Show).Internal = newNode.(ShowInternal) 6443 }) { 6444 return false 6445 } 6446 if a.post != nil { 6447 a.cur.replacer = replacer 6448 a.cur.parent = parent 6449 a.cur.node = node 6450 if !a.post(&a.cur) { 6451 return false 6452 } 6453 } 6454 return true 6455 } 6456 func (a *application) rewriteRefOfShowBasic(parent SQLNode, node *ShowBasic, replacer replacerFunc) bool { 6457 if node == nil { 6458 return true 6459 } 6460 if a.pre != nil { 6461 a.cur.replacer = replacer 6462 a.cur.parent = parent 6463 a.cur.node = node 6464 if !a.pre(&a.cur) { 6465 return true 6466 } 6467 } 6468 if !a.rewriteTableName(node, node.Tbl, func(newNode, parent SQLNode) { 6469 parent.(*ShowBasic).Tbl = newNode.(TableName) 6470 }) { 6471 return false 6472 } 6473 if !a.rewriteIdentifierCS(node, node.DbName, func(newNode, parent SQLNode) { 6474 parent.(*ShowBasic).DbName = newNode.(IdentifierCS) 6475 }) { 6476 return false 6477 } 6478 if !a.rewriteRefOfShowFilter(node, node.Filter, func(newNode, parent SQLNode) { 6479 parent.(*ShowBasic).Filter = newNode.(*ShowFilter) 6480 }) { 6481 return false 6482 } 6483 if a.post != nil { 6484 a.cur.replacer = replacer 6485 a.cur.parent = parent 6486 a.cur.node = node 6487 if !a.post(&a.cur) { 6488 return false 6489 } 6490 } 6491 return true 6492 } 6493 func (a *application) rewriteRefOfShowCreate(parent SQLNode, node *ShowCreate, replacer replacerFunc) bool { 6494 if node == nil { 6495 return true 6496 } 6497 if a.pre != nil { 6498 a.cur.replacer = replacer 6499 a.cur.parent = parent 6500 a.cur.node = node 6501 if !a.pre(&a.cur) { 6502 return true 6503 } 6504 } 6505 if !a.rewriteTableName(node, node.Op, func(newNode, parent SQLNode) { 6506 parent.(*ShowCreate).Op = newNode.(TableName) 6507 }) { 6508 return false 6509 } 6510 if a.post != nil { 6511 a.cur.replacer = replacer 6512 a.cur.parent = parent 6513 a.cur.node = node 6514 if !a.post(&a.cur) { 6515 return false 6516 } 6517 } 6518 return true 6519 } 6520 func (a *application) rewriteRefOfShowFilter(parent SQLNode, node *ShowFilter, replacer replacerFunc) bool { 6521 if node == nil { 6522 return true 6523 } 6524 if a.pre != nil { 6525 a.cur.replacer = replacer 6526 a.cur.parent = parent 6527 a.cur.node = node 6528 if !a.pre(&a.cur) { 6529 return true 6530 } 6531 } 6532 if !a.rewriteExpr(node, node.Filter, func(newNode, parent SQLNode) { 6533 parent.(*ShowFilter).Filter = newNode.(Expr) 6534 }) { 6535 return false 6536 } 6537 if a.post != nil { 6538 a.cur.replacer = replacer 6539 a.cur.parent = parent 6540 a.cur.node = node 6541 if !a.post(&a.cur) { 6542 return false 6543 } 6544 } 6545 return true 6546 } 6547 func (a *application) rewriteRefOfShowMigrationLogs(parent SQLNode, node *ShowMigrationLogs, replacer replacerFunc) bool { 6548 if node == nil { 6549 return true 6550 } 6551 if a.pre != nil { 6552 a.cur.replacer = replacer 6553 a.cur.parent = parent 6554 a.cur.node = node 6555 if !a.pre(&a.cur) { 6556 return true 6557 } 6558 } 6559 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 6560 parent.(*ShowMigrationLogs).Comments = newNode.(*ParsedComments) 6561 }) { 6562 return false 6563 } 6564 if a.post != nil { 6565 a.cur.replacer = replacer 6566 a.cur.parent = parent 6567 a.cur.node = node 6568 if !a.post(&a.cur) { 6569 return false 6570 } 6571 } 6572 return true 6573 } 6574 func (a *application) rewriteRefOfShowOther(parent SQLNode, node *ShowOther, replacer replacerFunc) bool { 6575 if node == nil { 6576 return true 6577 } 6578 if a.pre != nil { 6579 a.cur.replacer = replacer 6580 a.cur.parent = parent 6581 a.cur.node = node 6582 if !a.pre(&a.cur) { 6583 return true 6584 } 6585 } 6586 if a.post != nil { 6587 if a.pre == nil { 6588 a.cur.replacer = replacer 6589 a.cur.parent = parent 6590 a.cur.node = node 6591 } 6592 if !a.post(&a.cur) { 6593 return false 6594 } 6595 } 6596 return true 6597 } 6598 func (a *application) rewriteRefOfShowThrottledApps(parent SQLNode, node *ShowThrottledApps, replacer replacerFunc) bool { 6599 if node == nil { 6600 return true 6601 } 6602 if a.pre != nil { 6603 a.cur.replacer = replacer 6604 a.cur.parent = parent 6605 a.cur.node = node 6606 if !a.pre(&a.cur) { 6607 return true 6608 } 6609 } 6610 if a.post != nil { 6611 if a.pre == nil { 6612 a.cur.replacer = replacer 6613 a.cur.parent = parent 6614 a.cur.node = node 6615 } 6616 if !a.post(&a.cur) { 6617 return false 6618 } 6619 } 6620 return true 6621 } 6622 func (a *application) rewriteRefOfShowThrottlerStatus(parent SQLNode, node *ShowThrottlerStatus, replacer replacerFunc) bool { 6623 if node == nil { 6624 return true 6625 } 6626 if a.pre != nil { 6627 a.cur.replacer = replacer 6628 a.cur.parent = parent 6629 a.cur.node = node 6630 if !a.pre(&a.cur) { 6631 return true 6632 } 6633 } 6634 if a.post != nil { 6635 if a.pre == nil { 6636 a.cur.replacer = replacer 6637 a.cur.parent = parent 6638 a.cur.node = node 6639 } 6640 if !a.post(&a.cur) { 6641 return false 6642 } 6643 } 6644 return true 6645 } 6646 func (a *application) rewriteRefOfStarExpr(parent SQLNode, node *StarExpr, replacer replacerFunc) bool { 6647 if node == nil { 6648 return true 6649 } 6650 if a.pre != nil { 6651 a.cur.replacer = replacer 6652 a.cur.parent = parent 6653 a.cur.node = node 6654 if !a.pre(&a.cur) { 6655 return true 6656 } 6657 } 6658 if !a.rewriteTableName(node, node.TableName, func(newNode, parent SQLNode) { 6659 parent.(*StarExpr).TableName = newNode.(TableName) 6660 }) { 6661 return false 6662 } 6663 if a.post != nil { 6664 a.cur.replacer = replacer 6665 a.cur.parent = parent 6666 a.cur.node = node 6667 if !a.post(&a.cur) { 6668 return false 6669 } 6670 } 6671 return true 6672 } 6673 func (a *application) rewriteRefOfStd(parent SQLNode, node *Std, replacer replacerFunc) bool { 6674 if node == nil { 6675 return true 6676 } 6677 if a.pre != nil { 6678 a.cur.replacer = replacer 6679 a.cur.parent = parent 6680 a.cur.node = node 6681 if !a.pre(&a.cur) { 6682 return true 6683 } 6684 } 6685 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 6686 parent.(*Std).Arg = newNode.(Expr) 6687 }) { 6688 return false 6689 } 6690 if a.post != nil { 6691 a.cur.replacer = replacer 6692 a.cur.parent = parent 6693 a.cur.node = node 6694 if !a.post(&a.cur) { 6695 return false 6696 } 6697 } 6698 return true 6699 } 6700 func (a *application) rewriteRefOfStdDev(parent SQLNode, node *StdDev, replacer replacerFunc) bool { 6701 if node == nil { 6702 return true 6703 } 6704 if a.pre != nil { 6705 a.cur.replacer = replacer 6706 a.cur.parent = parent 6707 a.cur.node = node 6708 if !a.pre(&a.cur) { 6709 return true 6710 } 6711 } 6712 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 6713 parent.(*StdDev).Arg = newNode.(Expr) 6714 }) { 6715 return false 6716 } 6717 if a.post != nil { 6718 a.cur.replacer = replacer 6719 a.cur.parent = parent 6720 a.cur.node = node 6721 if !a.post(&a.cur) { 6722 return false 6723 } 6724 } 6725 return true 6726 } 6727 func (a *application) rewriteRefOfStdPop(parent SQLNode, node *StdPop, replacer replacerFunc) bool { 6728 if node == nil { 6729 return true 6730 } 6731 if a.pre != nil { 6732 a.cur.replacer = replacer 6733 a.cur.parent = parent 6734 a.cur.node = node 6735 if !a.pre(&a.cur) { 6736 return true 6737 } 6738 } 6739 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 6740 parent.(*StdPop).Arg = newNode.(Expr) 6741 }) { 6742 return false 6743 } 6744 if a.post != nil { 6745 a.cur.replacer = replacer 6746 a.cur.parent = parent 6747 a.cur.node = node 6748 if !a.post(&a.cur) { 6749 return false 6750 } 6751 } 6752 return true 6753 } 6754 func (a *application) rewriteRefOfStdSamp(parent SQLNode, node *StdSamp, replacer replacerFunc) bool { 6755 if node == nil { 6756 return true 6757 } 6758 if a.pre != nil { 6759 a.cur.replacer = replacer 6760 a.cur.parent = parent 6761 a.cur.node = node 6762 if !a.pre(&a.cur) { 6763 return true 6764 } 6765 } 6766 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 6767 parent.(*StdSamp).Arg = newNode.(Expr) 6768 }) { 6769 return false 6770 } 6771 if a.post != nil { 6772 a.cur.replacer = replacer 6773 a.cur.parent = parent 6774 a.cur.node = node 6775 if !a.post(&a.cur) { 6776 return false 6777 } 6778 } 6779 return true 6780 } 6781 func (a *application) rewriteRefOfStream(parent SQLNode, node *Stream, replacer replacerFunc) bool { 6782 if node == nil { 6783 return true 6784 } 6785 if a.pre != nil { 6786 a.cur.replacer = replacer 6787 a.cur.parent = parent 6788 a.cur.node = node 6789 if !a.pre(&a.cur) { 6790 return true 6791 } 6792 } 6793 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 6794 parent.(*Stream).Comments = newNode.(*ParsedComments) 6795 }) { 6796 return false 6797 } 6798 if !a.rewriteSelectExpr(node, node.SelectExpr, func(newNode, parent SQLNode) { 6799 parent.(*Stream).SelectExpr = newNode.(SelectExpr) 6800 }) { 6801 return false 6802 } 6803 if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { 6804 parent.(*Stream).Table = newNode.(TableName) 6805 }) { 6806 return false 6807 } 6808 if a.post != nil { 6809 a.cur.replacer = replacer 6810 a.cur.parent = parent 6811 a.cur.node = node 6812 if !a.post(&a.cur) { 6813 return false 6814 } 6815 } 6816 return true 6817 } 6818 func (a *application) rewriteRefOfSubPartition(parent SQLNode, node *SubPartition, replacer replacerFunc) bool { 6819 if node == nil { 6820 return true 6821 } 6822 if a.pre != nil { 6823 a.cur.replacer = replacer 6824 a.cur.parent = parent 6825 a.cur.node = node 6826 if !a.pre(&a.cur) { 6827 return true 6828 } 6829 } 6830 if !a.rewriteColumns(node, node.ColList, func(newNode, parent SQLNode) { 6831 parent.(*SubPartition).ColList = newNode.(Columns) 6832 }) { 6833 return false 6834 } 6835 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 6836 parent.(*SubPartition).Expr = newNode.(Expr) 6837 }) { 6838 return false 6839 } 6840 if a.post != nil { 6841 a.cur.replacer = replacer 6842 a.cur.parent = parent 6843 a.cur.node = node 6844 if !a.post(&a.cur) { 6845 return false 6846 } 6847 } 6848 return true 6849 } 6850 func (a *application) rewriteRefOfSubPartitionDefinition(parent SQLNode, node *SubPartitionDefinition, replacer replacerFunc) bool { 6851 if node == nil { 6852 return true 6853 } 6854 if a.pre != nil { 6855 a.cur.replacer = replacer 6856 a.cur.parent = parent 6857 a.cur.node = node 6858 if !a.pre(&a.cur) { 6859 return true 6860 } 6861 } 6862 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 6863 parent.(*SubPartitionDefinition).Name = newNode.(IdentifierCI) 6864 }) { 6865 return false 6866 } 6867 if !a.rewriteRefOfSubPartitionDefinitionOptions(node, node.Options, func(newNode, parent SQLNode) { 6868 parent.(*SubPartitionDefinition).Options = newNode.(*SubPartitionDefinitionOptions) 6869 }) { 6870 return false 6871 } 6872 if a.post != nil { 6873 a.cur.replacer = replacer 6874 a.cur.parent = parent 6875 a.cur.node = node 6876 if !a.post(&a.cur) { 6877 return false 6878 } 6879 } 6880 return true 6881 } 6882 func (a *application) rewriteRefOfSubPartitionDefinitionOptions(parent SQLNode, node *SubPartitionDefinitionOptions, replacer replacerFunc) bool { 6883 if node == nil { 6884 return true 6885 } 6886 if a.pre != nil { 6887 a.cur.replacer = replacer 6888 a.cur.parent = parent 6889 a.cur.node = node 6890 if !a.pre(&a.cur) { 6891 return true 6892 } 6893 } 6894 if !a.rewriteRefOfLiteral(node, node.Comment, func(newNode, parent SQLNode) { 6895 parent.(*SubPartitionDefinitionOptions).Comment = newNode.(*Literal) 6896 }) { 6897 return false 6898 } 6899 if !a.rewriteRefOfPartitionEngine(node, node.Engine, func(newNode, parent SQLNode) { 6900 parent.(*SubPartitionDefinitionOptions).Engine = newNode.(*PartitionEngine) 6901 }) { 6902 return false 6903 } 6904 if !a.rewriteRefOfLiteral(node, node.DataDirectory, func(newNode, parent SQLNode) { 6905 parent.(*SubPartitionDefinitionOptions).DataDirectory = newNode.(*Literal) 6906 }) { 6907 return false 6908 } 6909 if !a.rewriteRefOfLiteral(node, node.IndexDirectory, func(newNode, parent SQLNode) { 6910 parent.(*SubPartitionDefinitionOptions).IndexDirectory = newNode.(*Literal) 6911 }) { 6912 return false 6913 } 6914 if a.post != nil { 6915 a.cur.replacer = replacer 6916 a.cur.parent = parent 6917 a.cur.node = node 6918 if !a.post(&a.cur) { 6919 return false 6920 } 6921 } 6922 return true 6923 } 6924 func (a *application) rewriteSubPartitionDefinitions(parent SQLNode, node SubPartitionDefinitions, replacer replacerFunc) bool { 6925 if node == nil { 6926 return true 6927 } 6928 if a.pre != nil { 6929 a.cur.replacer = replacer 6930 a.cur.parent = parent 6931 a.cur.node = node 6932 kontinue := !a.pre(&a.cur) 6933 if a.cur.revisit { 6934 node = a.cur.node.(SubPartitionDefinitions) 6935 a.cur.revisit = false 6936 return a.rewriteSubPartitionDefinitions(parent, node, replacer) 6937 } 6938 if kontinue { 6939 return true 6940 } 6941 } 6942 for x, el := range node { 6943 if !a.rewriteRefOfSubPartitionDefinition(node, el, func(idx int) replacerFunc { 6944 return func(newNode, parent SQLNode) { 6945 parent.(SubPartitionDefinitions)[idx] = newNode.(*SubPartitionDefinition) 6946 } 6947 }(x)) { 6948 return false 6949 } 6950 } 6951 if a.post != nil { 6952 a.cur.replacer = replacer 6953 a.cur.parent = parent 6954 a.cur.node = node 6955 if !a.post(&a.cur) { 6956 return false 6957 } 6958 } 6959 return true 6960 } 6961 func (a *application) rewriteRefOfSubquery(parent SQLNode, node *Subquery, replacer replacerFunc) bool { 6962 if node == nil { 6963 return true 6964 } 6965 if a.pre != nil { 6966 a.cur.replacer = replacer 6967 a.cur.parent = parent 6968 a.cur.node = node 6969 if !a.pre(&a.cur) { 6970 return true 6971 } 6972 } 6973 if !a.rewriteSelectStatement(node, node.Select, func(newNode, parent SQLNode) { 6974 parent.(*Subquery).Select = newNode.(SelectStatement) 6975 }) { 6976 return false 6977 } 6978 if a.post != nil { 6979 a.cur.replacer = replacer 6980 a.cur.parent = parent 6981 a.cur.node = node 6982 if !a.post(&a.cur) { 6983 return false 6984 } 6985 } 6986 return true 6987 } 6988 func (a *application) rewriteRefOfSubstrExpr(parent SQLNode, node *SubstrExpr, replacer replacerFunc) bool { 6989 if node == nil { 6990 return true 6991 } 6992 if a.pre != nil { 6993 a.cur.replacer = replacer 6994 a.cur.parent = parent 6995 a.cur.node = node 6996 if !a.pre(&a.cur) { 6997 return true 6998 } 6999 } 7000 if !a.rewriteExpr(node, node.Name, func(newNode, parent SQLNode) { 7001 parent.(*SubstrExpr).Name = newNode.(Expr) 7002 }) { 7003 return false 7004 } 7005 if !a.rewriteExpr(node, node.From, func(newNode, parent SQLNode) { 7006 parent.(*SubstrExpr).From = newNode.(Expr) 7007 }) { 7008 return false 7009 } 7010 if !a.rewriteExpr(node, node.To, func(newNode, parent SQLNode) { 7011 parent.(*SubstrExpr).To = newNode.(Expr) 7012 }) { 7013 return false 7014 } 7015 if a.post != nil { 7016 a.cur.replacer = replacer 7017 a.cur.parent = parent 7018 a.cur.node = node 7019 if !a.post(&a.cur) { 7020 return false 7021 } 7022 } 7023 return true 7024 } 7025 func (a *application) rewriteRefOfSum(parent SQLNode, node *Sum, replacer replacerFunc) bool { 7026 if node == nil { 7027 return true 7028 } 7029 if a.pre != nil { 7030 a.cur.replacer = replacer 7031 a.cur.parent = parent 7032 a.cur.node = node 7033 if !a.pre(&a.cur) { 7034 return true 7035 } 7036 } 7037 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 7038 parent.(*Sum).Arg = newNode.(Expr) 7039 }) { 7040 return false 7041 } 7042 if a.post != nil { 7043 a.cur.replacer = replacer 7044 a.cur.parent = parent 7045 a.cur.node = node 7046 if !a.post(&a.cur) { 7047 return false 7048 } 7049 } 7050 return true 7051 } 7052 func (a *application) rewriteTableExprs(parent SQLNode, node TableExprs, replacer replacerFunc) bool { 7053 if node == nil { 7054 return true 7055 } 7056 if a.pre != nil { 7057 a.cur.replacer = replacer 7058 a.cur.parent = parent 7059 a.cur.node = node 7060 kontinue := !a.pre(&a.cur) 7061 if a.cur.revisit { 7062 node = a.cur.node.(TableExprs) 7063 a.cur.revisit = false 7064 return a.rewriteTableExprs(parent, node, replacer) 7065 } 7066 if kontinue { 7067 return true 7068 } 7069 } 7070 for x, el := range node { 7071 if !a.rewriteTableExpr(node, el, func(idx int) replacerFunc { 7072 return func(newNode, parent SQLNode) { 7073 parent.(TableExprs)[idx] = newNode.(TableExpr) 7074 } 7075 }(x)) { 7076 return false 7077 } 7078 } 7079 if a.post != nil { 7080 a.cur.replacer = replacer 7081 a.cur.parent = parent 7082 a.cur.node = node 7083 if !a.post(&a.cur) { 7084 return false 7085 } 7086 } 7087 return true 7088 } 7089 func (a *application) rewriteTableName(parent SQLNode, node TableName, replacer replacerFunc) bool { 7090 if a.pre != nil { 7091 a.cur.replacer = replacer 7092 a.cur.parent = parent 7093 a.cur.node = node 7094 if !a.pre(&a.cur) { 7095 return true 7096 } 7097 } 7098 if !a.rewriteIdentifierCS(node, node.Name, func(newNode, parent SQLNode) { 7099 panic("[BUG] tried to replace 'Name' on 'TableName'") 7100 }) { 7101 return false 7102 } 7103 if !a.rewriteIdentifierCS(node, node.Qualifier, func(newNode, parent SQLNode) { 7104 panic("[BUG] tried to replace 'Qualifier' on 'TableName'") 7105 }) { 7106 return false 7107 } 7108 if a.post != nil { 7109 a.cur.replacer = replacer 7110 a.cur.parent = parent 7111 a.cur.node = node 7112 if !a.post(&a.cur) { 7113 return false 7114 } 7115 } 7116 return true 7117 } 7118 func (a *application) rewriteTableNames(parent SQLNode, node TableNames, replacer replacerFunc) bool { 7119 if node == nil { 7120 return true 7121 } 7122 if a.pre != nil { 7123 a.cur.replacer = replacer 7124 a.cur.parent = parent 7125 a.cur.node = node 7126 kontinue := !a.pre(&a.cur) 7127 if a.cur.revisit { 7128 node = a.cur.node.(TableNames) 7129 a.cur.revisit = false 7130 return a.rewriteTableNames(parent, node, replacer) 7131 } 7132 if kontinue { 7133 return true 7134 } 7135 } 7136 for x, el := range node { 7137 if !a.rewriteTableName(node, el, func(idx int) replacerFunc { 7138 return func(newNode, parent SQLNode) { 7139 parent.(TableNames)[idx] = newNode.(TableName) 7140 } 7141 }(x)) { 7142 return false 7143 } 7144 } 7145 if a.post != nil { 7146 a.cur.replacer = replacer 7147 a.cur.parent = parent 7148 a.cur.node = node 7149 if !a.post(&a.cur) { 7150 return false 7151 } 7152 } 7153 return true 7154 } 7155 func (a *application) rewriteTableOptions(parent SQLNode, node TableOptions, replacer replacerFunc) bool { 7156 if node == nil { 7157 return true 7158 } 7159 if a.pre != nil { 7160 a.cur.replacer = replacer 7161 a.cur.parent = parent 7162 a.cur.node = node 7163 kontinue := !a.pre(&a.cur) 7164 if a.cur.revisit { 7165 node = a.cur.node.(TableOptions) 7166 a.cur.revisit = false 7167 return a.rewriteTableOptions(parent, node, replacer) 7168 } 7169 if kontinue { 7170 return true 7171 } 7172 } 7173 if a.post != nil { 7174 if a.pre == nil { 7175 a.cur.replacer = replacer 7176 a.cur.parent = parent 7177 a.cur.node = node 7178 } 7179 if !a.post(&a.cur) { 7180 return false 7181 } 7182 } 7183 return true 7184 } 7185 func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, replacer replacerFunc) bool { 7186 if node == nil { 7187 return true 7188 } 7189 if a.pre != nil { 7190 a.cur.replacer = replacer 7191 a.cur.parent = parent 7192 a.cur.node = node 7193 if !a.pre(&a.cur) { 7194 return true 7195 } 7196 } 7197 for x, el := range node.Columns { 7198 if !a.rewriteRefOfColumnDefinition(node, el, func(idx int) replacerFunc { 7199 return func(newNode, parent SQLNode) { 7200 parent.(*TableSpec).Columns[idx] = newNode.(*ColumnDefinition) 7201 } 7202 }(x)) { 7203 return false 7204 } 7205 } 7206 for x, el := range node.Indexes { 7207 if !a.rewriteRefOfIndexDefinition(node, el, func(idx int) replacerFunc { 7208 return func(newNode, parent SQLNode) { 7209 parent.(*TableSpec).Indexes[idx] = newNode.(*IndexDefinition) 7210 } 7211 }(x)) { 7212 return false 7213 } 7214 } 7215 for x, el := range node.Constraints { 7216 if !a.rewriteRefOfConstraintDefinition(node, el, func(idx int) replacerFunc { 7217 return func(newNode, parent SQLNode) { 7218 parent.(*TableSpec).Constraints[idx] = newNode.(*ConstraintDefinition) 7219 } 7220 }(x)) { 7221 return false 7222 } 7223 } 7224 if !a.rewriteTableOptions(node, node.Options, func(newNode, parent SQLNode) { 7225 parent.(*TableSpec).Options = newNode.(TableOptions) 7226 }) { 7227 return false 7228 } 7229 if !a.rewriteRefOfPartitionOption(node, node.PartitionOption, func(newNode, parent SQLNode) { 7230 parent.(*TableSpec).PartitionOption = newNode.(*PartitionOption) 7231 }) { 7232 return false 7233 } 7234 if a.post != nil { 7235 a.cur.replacer = replacer 7236 a.cur.parent = parent 7237 a.cur.node = node 7238 if !a.post(&a.cur) { 7239 return false 7240 } 7241 } 7242 return true 7243 } 7244 func (a *application) rewriteRefOfTablespaceOperation(parent SQLNode, node *TablespaceOperation, replacer replacerFunc) bool { 7245 if node == nil { 7246 return true 7247 } 7248 if a.pre != nil { 7249 a.cur.replacer = replacer 7250 a.cur.parent = parent 7251 a.cur.node = node 7252 if !a.pre(&a.cur) { 7253 return true 7254 } 7255 } 7256 if a.post != nil { 7257 if a.pre == nil { 7258 a.cur.replacer = replacer 7259 a.cur.parent = parent 7260 a.cur.node = node 7261 } 7262 if !a.post(&a.cur) { 7263 return false 7264 } 7265 } 7266 return true 7267 } 7268 func (a *application) rewriteRefOfTimestampFuncExpr(parent SQLNode, node *TimestampFuncExpr, replacer replacerFunc) bool { 7269 if node == nil { 7270 return true 7271 } 7272 if a.pre != nil { 7273 a.cur.replacer = replacer 7274 a.cur.parent = parent 7275 a.cur.node = node 7276 if !a.pre(&a.cur) { 7277 return true 7278 } 7279 } 7280 if !a.rewriteExpr(node, node.Expr1, func(newNode, parent SQLNode) { 7281 parent.(*TimestampFuncExpr).Expr1 = newNode.(Expr) 7282 }) { 7283 return false 7284 } 7285 if !a.rewriteExpr(node, node.Expr2, func(newNode, parent SQLNode) { 7286 parent.(*TimestampFuncExpr).Expr2 = newNode.(Expr) 7287 }) { 7288 return false 7289 } 7290 if a.post != nil { 7291 a.cur.replacer = replacer 7292 a.cur.parent = parent 7293 a.cur.node = node 7294 if !a.post(&a.cur) { 7295 return false 7296 } 7297 } 7298 return true 7299 } 7300 func (a *application) rewriteRefOfTrimFuncExpr(parent SQLNode, node *TrimFuncExpr, replacer replacerFunc) bool { 7301 if node == nil { 7302 return true 7303 } 7304 if a.pre != nil { 7305 a.cur.replacer = replacer 7306 a.cur.parent = parent 7307 a.cur.node = node 7308 if !a.pre(&a.cur) { 7309 return true 7310 } 7311 } 7312 if !a.rewriteExpr(node, node.TrimArg, func(newNode, parent SQLNode) { 7313 parent.(*TrimFuncExpr).TrimArg = newNode.(Expr) 7314 }) { 7315 return false 7316 } 7317 if !a.rewriteExpr(node, node.StringArg, func(newNode, parent SQLNode) { 7318 parent.(*TrimFuncExpr).StringArg = newNode.(Expr) 7319 }) { 7320 return false 7321 } 7322 if a.post != nil { 7323 a.cur.replacer = replacer 7324 a.cur.parent = parent 7325 a.cur.node = node 7326 if !a.post(&a.cur) { 7327 return false 7328 } 7329 } 7330 return true 7331 } 7332 func (a *application) rewriteRefOfTruncateTable(parent SQLNode, node *TruncateTable, replacer replacerFunc) bool { 7333 if node == nil { 7334 return true 7335 } 7336 if a.pre != nil { 7337 a.cur.replacer = replacer 7338 a.cur.parent = parent 7339 a.cur.node = node 7340 if !a.pre(&a.cur) { 7341 return true 7342 } 7343 } 7344 if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { 7345 parent.(*TruncateTable).Table = newNode.(TableName) 7346 }) { 7347 return false 7348 } 7349 if a.post != nil { 7350 a.cur.replacer = replacer 7351 a.cur.parent = parent 7352 a.cur.node = node 7353 if !a.post(&a.cur) { 7354 return false 7355 } 7356 } 7357 return true 7358 } 7359 func (a *application) rewriteRefOfUnaryExpr(parent SQLNode, node *UnaryExpr, replacer replacerFunc) bool { 7360 if node == nil { 7361 return true 7362 } 7363 if a.pre != nil { 7364 a.cur.replacer = replacer 7365 a.cur.parent = parent 7366 a.cur.node = node 7367 if !a.pre(&a.cur) { 7368 return true 7369 } 7370 } 7371 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 7372 parent.(*UnaryExpr).Expr = newNode.(Expr) 7373 }) { 7374 return false 7375 } 7376 if a.post != nil { 7377 a.cur.replacer = replacer 7378 a.cur.parent = parent 7379 a.cur.node = node 7380 if !a.post(&a.cur) { 7381 return false 7382 } 7383 } 7384 return true 7385 } 7386 func (a *application) rewriteRefOfUnion(parent SQLNode, node *Union, replacer replacerFunc) bool { 7387 if node == nil { 7388 return true 7389 } 7390 if a.pre != nil { 7391 a.cur.replacer = replacer 7392 a.cur.parent = parent 7393 a.cur.node = node 7394 if !a.pre(&a.cur) { 7395 return true 7396 } 7397 } 7398 if !a.rewriteSelectStatement(node, node.Left, func(newNode, parent SQLNode) { 7399 parent.(*Union).Left = newNode.(SelectStatement) 7400 }) { 7401 return false 7402 } 7403 if !a.rewriteSelectStatement(node, node.Right, func(newNode, parent SQLNode) { 7404 parent.(*Union).Right = newNode.(SelectStatement) 7405 }) { 7406 return false 7407 } 7408 if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { 7409 parent.(*Union).OrderBy = newNode.(OrderBy) 7410 }) { 7411 return false 7412 } 7413 if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { 7414 parent.(*Union).With = newNode.(*With) 7415 }) { 7416 return false 7417 } 7418 if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { 7419 parent.(*Union).Limit = newNode.(*Limit) 7420 }) { 7421 return false 7422 } 7423 if !a.rewriteRefOfSelectInto(node, node.Into, func(newNode, parent SQLNode) { 7424 parent.(*Union).Into = newNode.(*SelectInto) 7425 }) { 7426 return false 7427 } 7428 if a.post != nil { 7429 a.cur.replacer = replacer 7430 a.cur.parent = parent 7431 a.cur.node = node 7432 if !a.post(&a.cur) { 7433 return false 7434 } 7435 } 7436 return true 7437 } 7438 func (a *application) rewriteRefOfUnlockTables(parent SQLNode, node *UnlockTables, replacer replacerFunc) bool { 7439 if node == nil { 7440 return true 7441 } 7442 if a.pre != nil { 7443 a.cur.replacer = replacer 7444 a.cur.parent = parent 7445 a.cur.node = node 7446 if !a.pre(&a.cur) { 7447 return true 7448 } 7449 } 7450 if a.post != nil { 7451 if a.pre == nil { 7452 a.cur.replacer = replacer 7453 a.cur.parent = parent 7454 a.cur.node = node 7455 } 7456 if !a.post(&a.cur) { 7457 return false 7458 } 7459 } 7460 return true 7461 } 7462 func (a *application) rewriteRefOfUpdate(parent SQLNode, node *Update, replacer replacerFunc) bool { 7463 if node == nil { 7464 return true 7465 } 7466 if a.pre != nil { 7467 a.cur.replacer = replacer 7468 a.cur.parent = parent 7469 a.cur.node = node 7470 if !a.pre(&a.cur) { 7471 return true 7472 } 7473 } 7474 if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { 7475 parent.(*Update).With = newNode.(*With) 7476 }) { 7477 return false 7478 } 7479 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 7480 parent.(*Update).Comments = newNode.(*ParsedComments) 7481 }) { 7482 return false 7483 } 7484 if !a.rewriteTableExprs(node, node.TableExprs, func(newNode, parent SQLNode) { 7485 parent.(*Update).TableExprs = newNode.(TableExprs) 7486 }) { 7487 return false 7488 } 7489 if !a.rewriteUpdateExprs(node, node.Exprs, func(newNode, parent SQLNode) { 7490 parent.(*Update).Exprs = newNode.(UpdateExprs) 7491 }) { 7492 return false 7493 } 7494 if !a.rewriteRefOfWhere(node, node.Where, func(newNode, parent SQLNode) { 7495 parent.(*Update).Where = newNode.(*Where) 7496 }) { 7497 return false 7498 } 7499 if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { 7500 parent.(*Update).OrderBy = newNode.(OrderBy) 7501 }) { 7502 return false 7503 } 7504 if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { 7505 parent.(*Update).Limit = newNode.(*Limit) 7506 }) { 7507 return false 7508 } 7509 if a.post != nil { 7510 a.cur.replacer = replacer 7511 a.cur.parent = parent 7512 a.cur.node = node 7513 if !a.post(&a.cur) { 7514 return false 7515 } 7516 } 7517 return true 7518 } 7519 func (a *application) rewriteRefOfUpdateExpr(parent SQLNode, node *UpdateExpr, replacer replacerFunc) bool { 7520 if node == nil { 7521 return true 7522 } 7523 if a.pre != nil { 7524 a.cur.replacer = replacer 7525 a.cur.parent = parent 7526 a.cur.node = node 7527 if !a.pre(&a.cur) { 7528 return true 7529 } 7530 } 7531 if !a.rewriteRefOfColName(node, node.Name, func(newNode, parent SQLNode) { 7532 parent.(*UpdateExpr).Name = newNode.(*ColName) 7533 }) { 7534 return false 7535 } 7536 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 7537 parent.(*UpdateExpr).Expr = newNode.(Expr) 7538 }) { 7539 return false 7540 } 7541 if a.post != nil { 7542 a.cur.replacer = replacer 7543 a.cur.parent = parent 7544 a.cur.node = node 7545 if !a.post(&a.cur) { 7546 return false 7547 } 7548 } 7549 return true 7550 } 7551 func (a *application) rewriteUpdateExprs(parent SQLNode, node UpdateExprs, replacer replacerFunc) bool { 7552 if node == nil { 7553 return true 7554 } 7555 if a.pre != nil { 7556 a.cur.replacer = replacer 7557 a.cur.parent = parent 7558 a.cur.node = node 7559 kontinue := !a.pre(&a.cur) 7560 if a.cur.revisit { 7561 node = a.cur.node.(UpdateExprs) 7562 a.cur.revisit = false 7563 return a.rewriteUpdateExprs(parent, node, replacer) 7564 } 7565 if kontinue { 7566 return true 7567 } 7568 } 7569 for x, el := range node { 7570 if !a.rewriteRefOfUpdateExpr(node, el, func(idx int) replacerFunc { 7571 return func(newNode, parent SQLNode) { 7572 parent.(UpdateExprs)[idx] = newNode.(*UpdateExpr) 7573 } 7574 }(x)) { 7575 return false 7576 } 7577 } 7578 if a.post != nil { 7579 a.cur.replacer = replacer 7580 a.cur.parent = parent 7581 a.cur.node = node 7582 if !a.post(&a.cur) { 7583 return false 7584 } 7585 } 7586 return true 7587 } 7588 func (a *application) rewriteRefOfUpdateXMLExpr(parent SQLNode, node *UpdateXMLExpr, replacer replacerFunc) bool { 7589 if node == nil { 7590 return true 7591 } 7592 if a.pre != nil { 7593 a.cur.replacer = replacer 7594 a.cur.parent = parent 7595 a.cur.node = node 7596 if !a.pre(&a.cur) { 7597 return true 7598 } 7599 } 7600 if !a.rewriteExpr(node, node.Target, func(newNode, parent SQLNode) { 7601 parent.(*UpdateXMLExpr).Target = newNode.(Expr) 7602 }) { 7603 return false 7604 } 7605 if !a.rewriteExpr(node, node.XPathExpr, func(newNode, parent SQLNode) { 7606 parent.(*UpdateXMLExpr).XPathExpr = newNode.(Expr) 7607 }) { 7608 return false 7609 } 7610 if !a.rewriteExpr(node, node.NewXML, func(newNode, parent SQLNode) { 7611 parent.(*UpdateXMLExpr).NewXML = newNode.(Expr) 7612 }) { 7613 return false 7614 } 7615 if a.post != nil { 7616 a.cur.replacer = replacer 7617 a.cur.parent = parent 7618 a.cur.node = node 7619 if !a.post(&a.cur) { 7620 return false 7621 } 7622 } 7623 return true 7624 } 7625 func (a *application) rewriteRefOfUse(parent SQLNode, node *Use, replacer replacerFunc) bool { 7626 if node == nil { 7627 return true 7628 } 7629 if a.pre != nil { 7630 a.cur.replacer = replacer 7631 a.cur.parent = parent 7632 a.cur.node = node 7633 if !a.pre(&a.cur) { 7634 return true 7635 } 7636 } 7637 if !a.rewriteIdentifierCS(node, node.DBName, func(newNode, parent SQLNode) { 7638 parent.(*Use).DBName = newNode.(IdentifierCS) 7639 }) { 7640 return false 7641 } 7642 if a.post != nil { 7643 a.cur.replacer = replacer 7644 a.cur.parent = parent 7645 a.cur.node = node 7646 if !a.post(&a.cur) { 7647 return false 7648 } 7649 } 7650 return true 7651 } 7652 func (a *application) rewriteRefOfVExplainStmt(parent SQLNode, node *VExplainStmt, replacer replacerFunc) bool { 7653 if node == nil { 7654 return true 7655 } 7656 if a.pre != nil { 7657 a.cur.replacer = replacer 7658 a.cur.parent = parent 7659 a.cur.node = node 7660 if !a.pre(&a.cur) { 7661 return true 7662 } 7663 } 7664 if !a.rewriteStatement(node, node.Statement, func(newNode, parent SQLNode) { 7665 parent.(*VExplainStmt).Statement = newNode.(Statement) 7666 }) { 7667 return false 7668 } 7669 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 7670 parent.(*VExplainStmt).Comments = newNode.(*ParsedComments) 7671 }) { 7672 return false 7673 } 7674 if a.post != nil { 7675 a.cur.replacer = replacer 7676 a.cur.parent = parent 7677 a.cur.node = node 7678 if !a.post(&a.cur) { 7679 return false 7680 } 7681 } 7682 return true 7683 } 7684 func (a *application) rewriteRefOfVStream(parent SQLNode, node *VStream, replacer replacerFunc) bool { 7685 if node == nil { 7686 return true 7687 } 7688 if a.pre != nil { 7689 a.cur.replacer = replacer 7690 a.cur.parent = parent 7691 a.cur.node = node 7692 if !a.pre(&a.cur) { 7693 return true 7694 } 7695 } 7696 if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { 7697 parent.(*VStream).Comments = newNode.(*ParsedComments) 7698 }) { 7699 return false 7700 } 7701 if !a.rewriteSelectExpr(node, node.SelectExpr, func(newNode, parent SQLNode) { 7702 parent.(*VStream).SelectExpr = newNode.(SelectExpr) 7703 }) { 7704 return false 7705 } 7706 if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { 7707 parent.(*VStream).Table = newNode.(TableName) 7708 }) { 7709 return false 7710 } 7711 if !a.rewriteRefOfWhere(node, node.Where, func(newNode, parent SQLNode) { 7712 parent.(*VStream).Where = newNode.(*Where) 7713 }) { 7714 return false 7715 } 7716 if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { 7717 parent.(*VStream).Limit = newNode.(*Limit) 7718 }) { 7719 return false 7720 } 7721 if a.post != nil { 7722 a.cur.replacer = replacer 7723 a.cur.parent = parent 7724 a.cur.node = node 7725 if !a.post(&a.cur) { 7726 return false 7727 } 7728 } 7729 return true 7730 } 7731 func (a *application) rewriteValTuple(parent SQLNode, node ValTuple, replacer replacerFunc) bool { 7732 if node == nil { 7733 return true 7734 } 7735 if a.pre != nil { 7736 a.cur.replacer = replacer 7737 a.cur.parent = parent 7738 a.cur.node = node 7739 kontinue := !a.pre(&a.cur) 7740 if a.cur.revisit { 7741 node = a.cur.node.(ValTuple) 7742 a.cur.revisit = false 7743 return a.rewriteValTuple(parent, node, replacer) 7744 } 7745 if kontinue { 7746 return true 7747 } 7748 } 7749 for x, el := range node { 7750 if !a.rewriteExpr(node, el, func(idx int) replacerFunc { 7751 return func(newNode, parent SQLNode) { 7752 parent.(ValTuple)[idx] = newNode.(Expr) 7753 } 7754 }(x)) { 7755 return false 7756 } 7757 } 7758 if a.post != nil { 7759 a.cur.replacer = replacer 7760 a.cur.parent = parent 7761 a.cur.node = node 7762 if !a.post(&a.cur) { 7763 return false 7764 } 7765 } 7766 return true 7767 } 7768 func (a *application) rewriteRefOfValidation(parent SQLNode, node *Validation, replacer replacerFunc) bool { 7769 if node == nil { 7770 return true 7771 } 7772 if a.pre != nil { 7773 a.cur.replacer = replacer 7774 a.cur.parent = parent 7775 a.cur.node = node 7776 if !a.pre(&a.cur) { 7777 return true 7778 } 7779 } 7780 if a.post != nil { 7781 if a.pre == nil { 7782 a.cur.replacer = replacer 7783 a.cur.parent = parent 7784 a.cur.node = node 7785 } 7786 if !a.post(&a.cur) { 7787 return false 7788 } 7789 } 7790 return true 7791 } 7792 func (a *application) rewriteValues(parent SQLNode, node Values, replacer replacerFunc) bool { 7793 if node == nil { 7794 return true 7795 } 7796 if a.pre != nil { 7797 a.cur.replacer = replacer 7798 a.cur.parent = parent 7799 a.cur.node = node 7800 kontinue := !a.pre(&a.cur) 7801 if a.cur.revisit { 7802 node = a.cur.node.(Values) 7803 a.cur.revisit = false 7804 return a.rewriteValues(parent, node, replacer) 7805 } 7806 if kontinue { 7807 return true 7808 } 7809 } 7810 for x, el := range node { 7811 if !a.rewriteValTuple(node, el, func(idx int) replacerFunc { 7812 return func(newNode, parent SQLNode) { 7813 parent.(Values)[idx] = newNode.(ValTuple) 7814 } 7815 }(x)) { 7816 return false 7817 } 7818 } 7819 if a.post != nil { 7820 a.cur.replacer = replacer 7821 a.cur.parent = parent 7822 a.cur.node = node 7823 if !a.post(&a.cur) { 7824 return false 7825 } 7826 } 7827 return true 7828 } 7829 func (a *application) rewriteRefOfValuesFuncExpr(parent SQLNode, node *ValuesFuncExpr, replacer replacerFunc) bool { 7830 if node == nil { 7831 return true 7832 } 7833 if a.pre != nil { 7834 a.cur.replacer = replacer 7835 a.cur.parent = parent 7836 a.cur.node = node 7837 if !a.pre(&a.cur) { 7838 return true 7839 } 7840 } 7841 if !a.rewriteRefOfColName(node, node.Name, func(newNode, parent SQLNode) { 7842 parent.(*ValuesFuncExpr).Name = newNode.(*ColName) 7843 }) { 7844 return false 7845 } 7846 if a.post != nil { 7847 a.cur.replacer = replacer 7848 a.cur.parent = parent 7849 a.cur.node = node 7850 if !a.post(&a.cur) { 7851 return false 7852 } 7853 } 7854 return true 7855 } 7856 func (a *application) rewriteRefOfVarPop(parent SQLNode, node *VarPop, replacer replacerFunc) bool { 7857 if node == nil { 7858 return true 7859 } 7860 if a.pre != nil { 7861 a.cur.replacer = replacer 7862 a.cur.parent = parent 7863 a.cur.node = node 7864 if !a.pre(&a.cur) { 7865 return true 7866 } 7867 } 7868 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 7869 parent.(*VarPop).Arg = newNode.(Expr) 7870 }) { 7871 return false 7872 } 7873 if a.post != nil { 7874 a.cur.replacer = replacer 7875 a.cur.parent = parent 7876 a.cur.node = node 7877 if !a.post(&a.cur) { 7878 return false 7879 } 7880 } 7881 return true 7882 } 7883 func (a *application) rewriteRefOfVarSamp(parent SQLNode, node *VarSamp, replacer replacerFunc) bool { 7884 if node == nil { 7885 return true 7886 } 7887 if a.pre != nil { 7888 a.cur.replacer = replacer 7889 a.cur.parent = parent 7890 a.cur.node = node 7891 if !a.pre(&a.cur) { 7892 return true 7893 } 7894 } 7895 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 7896 parent.(*VarSamp).Arg = newNode.(Expr) 7897 }) { 7898 return false 7899 } 7900 if a.post != nil { 7901 a.cur.replacer = replacer 7902 a.cur.parent = parent 7903 a.cur.node = node 7904 if !a.post(&a.cur) { 7905 return false 7906 } 7907 } 7908 return true 7909 } 7910 func (a *application) rewriteRefOfVariable(parent SQLNode, node *Variable, replacer replacerFunc) bool { 7911 if node == nil { 7912 return true 7913 } 7914 if a.pre != nil { 7915 a.cur.replacer = replacer 7916 a.cur.parent = parent 7917 a.cur.node = node 7918 if !a.pre(&a.cur) { 7919 return true 7920 } 7921 } 7922 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 7923 parent.(*Variable).Name = newNode.(IdentifierCI) 7924 }) { 7925 return false 7926 } 7927 if a.post != nil { 7928 a.cur.replacer = replacer 7929 a.cur.parent = parent 7930 a.cur.node = node 7931 if !a.post(&a.cur) { 7932 return false 7933 } 7934 } 7935 return true 7936 } 7937 func (a *application) rewriteRefOfVariance(parent SQLNode, node *Variance, replacer replacerFunc) bool { 7938 if node == nil { 7939 return true 7940 } 7941 if a.pre != nil { 7942 a.cur.replacer = replacer 7943 a.cur.parent = parent 7944 a.cur.node = node 7945 if !a.pre(&a.cur) { 7946 return true 7947 } 7948 } 7949 if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { 7950 parent.(*Variance).Arg = newNode.(Expr) 7951 }) { 7952 return false 7953 } 7954 if a.post != nil { 7955 a.cur.replacer = replacer 7956 a.cur.parent = parent 7957 a.cur.node = node 7958 if !a.post(&a.cur) { 7959 return false 7960 } 7961 } 7962 return true 7963 } 7964 func (a *application) rewriteVindexParam(parent SQLNode, node VindexParam, replacer replacerFunc) bool { 7965 if a.pre != nil { 7966 a.cur.replacer = replacer 7967 a.cur.parent = parent 7968 a.cur.node = node 7969 if !a.pre(&a.cur) { 7970 return true 7971 } 7972 } 7973 if !a.rewriteIdentifierCI(node, node.Key, func(newNode, parent SQLNode) { 7974 panic("[BUG] tried to replace 'Key' on 'VindexParam'") 7975 }) { 7976 return false 7977 } 7978 if a.post != nil { 7979 a.cur.replacer = replacer 7980 a.cur.parent = parent 7981 a.cur.node = node 7982 if !a.post(&a.cur) { 7983 return false 7984 } 7985 } 7986 return true 7987 } 7988 func (a *application) rewriteRefOfVindexSpec(parent SQLNode, node *VindexSpec, replacer replacerFunc) bool { 7989 if node == nil { 7990 return true 7991 } 7992 if a.pre != nil { 7993 a.cur.replacer = replacer 7994 a.cur.parent = parent 7995 a.cur.node = node 7996 if !a.pre(&a.cur) { 7997 return true 7998 } 7999 } 8000 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 8001 parent.(*VindexSpec).Name = newNode.(IdentifierCI) 8002 }) { 8003 return false 8004 } 8005 if !a.rewriteIdentifierCI(node, node.Type, func(newNode, parent SQLNode) { 8006 parent.(*VindexSpec).Type = newNode.(IdentifierCI) 8007 }) { 8008 return false 8009 } 8010 for x, el := range node.Params { 8011 if !a.rewriteVindexParam(node, el, func(idx int) replacerFunc { 8012 return func(newNode, parent SQLNode) { 8013 parent.(*VindexSpec).Params[idx] = newNode.(VindexParam) 8014 } 8015 }(x)) { 8016 return false 8017 } 8018 } 8019 if a.post != nil { 8020 a.cur.replacer = replacer 8021 a.cur.parent = parent 8022 a.cur.node = node 8023 if !a.post(&a.cur) { 8024 return false 8025 } 8026 } 8027 return true 8028 } 8029 func (a *application) rewriteRefOfWeightStringFuncExpr(parent SQLNode, node *WeightStringFuncExpr, replacer replacerFunc) bool { 8030 if node == nil { 8031 return true 8032 } 8033 if a.pre != nil { 8034 a.cur.replacer = replacer 8035 a.cur.parent = parent 8036 a.cur.node = node 8037 if !a.pre(&a.cur) { 8038 return true 8039 } 8040 } 8041 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 8042 parent.(*WeightStringFuncExpr).Expr = newNode.(Expr) 8043 }) { 8044 return false 8045 } 8046 if !a.rewriteRefOfConvertType(node, node.As, func(newNode, parent SQLNode) { 8047 parent.(*WeightStringFuncExpr).As = newNode.(*ConvertType) 8048 }) { 8049 return false 8050 } 8051 if a.post != nil { 8052 a.cur.replacer = replacer 8053 a.cur.parent = parent 8054 a.cur.node = node 8055 if !a.post(&a.cur) { 8056 return false 8057 } 8058 } 8059 return true 8060 } 8061 func (a *application) rewriteRefOfWhen(parent SQLNode, node *When, replacer replacerFunc) bool { 8062 if node == nil { 8063 return true 8064 } 8065 if a.pre != nil { 8066 a.cur.replacer = replacer 8067 a.cur.parent = parent 8068 a.cur.node = node 8069 if !a.pre(&a.cur) { 8070 return true 8071 } 8072 } 8073 if !a.rewriteExpr(node, node.Cond, func(newNode, parent SQLNode) { 8074 parent.(*When).Cond = newNode.(Expr) 8075 }) { 8076 return false 8077 } 8078 if !a.rewriteExpr(node, node.Val, func(newNode, parent SQLNode) { 8079 parent.(*When).Val = newNode.(Expr) 8080 }) { 8081 return false 8082 } 8083 if a.post != nil { 8084 a.cur.replacer = replacer 8085 a.cur.parent = parent 8086 a.cur.node = node 8087 if !a.post(&a.cur) { 8088 return false 8089 } 8090 } 8091 return true 8092 } 8093 func (a *application) rewriteRefOfWhere(parent SQLNode, node *Where, replacer replacerFunc) bool { 8094 if node == nil { 8095 return true 8096 } 8097 if a.pre != nil { 8098 a.cur.replacer = replacer 8099 a.cur.parent = parent 8100 a.cur.node = node 8101 if !a.pre(&a.cur) { 8102 return true 8103 } 8104 } 8105 if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { 8106 parent.(*Where).Expr = newNode.(Expr) 8107 }) { 8108 return false 8109 } 8110 if a.post != nil { 8111 a.cur.replacer = replacer 8112 a.cur.parent = parent 8113 a.cur.node = node 8114 if !a.post(&a.cur) { 8115 return false 8116 } 8117 } 8118 return true 8119 } 8120 func (a *application) rewriteRefOfWindowDefinition(parent SQLNode, node *WindowDefinition, replacer replacerFunc) bool { 8121 if node == nil { 8122 return true 8123 } 8124 if a.pre != nil { 8125 a.cur.replacer = replacer 8126 a.cur.parent = parent 8127 a.cur.node = node 8128 if !a.pre(&a.cur) { 8129 return true 8130 } 8131 } 8132 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 8133 parent.(*WindowDefinition).Name = newNode.(IdentifierCI) 8134 }) { 8135 return false 8136 } 8137 if !a.rewriteRefOfWindowSpecification(node, node.WindowSpec, func(newNode, parent SQLNode) { 8138 parent.(*WindowDefinition).WindowSpec = newNode.(*WindowSpecification) 8139 }) { 8140 return false 8141 } 8142 if a.post != nil { 8143 a.cur.replacer = replacer 8144 a.cur.parent = parent 8145 a.cur.node = node 8146 if !a.post(&a.cur) { 8147 return false 8148 } 8149 } 8150 return true 8151 } 8152 func (a *application) rewriteWindowDefinitions(parent SQLNode, node WindowDefinitions, replacer replacerFunc) bool { 8153 if node == nil { 8154 return true 8155 } 8156 if a.pre != nil { 8157 a.cur.replacer = replacer 8158 a.cur.parent = parent 8159 a.cur.node = node 8160 kontinue := !a.pre(&a.cur) 8161 if a.cur.revisit { 8162 node = a.cur.node.(WindowDefinitions) 8163 a.cur.revisit = false 8164 return a.rewriteWindowDefinitions(parent, node, replacer) 8165 } 8166 if kontinue { 8167 return true 8168 } 8169 } 8170 for x, el := range node { 8171 if !a.rewriteRefOfWindowDefinition(node, el, func(idx int) replacerFunc { 8172 return func(newNode, parent SQLNode) { 8173 parent.(WindowDefinitions)[idx] = newNode.(*WindowDefinition) 8174 } 8175 }(x)) { 8176 return false 8177 } 8178 } 8179 if a.post != nil { 8180 a.cur.replacer = replacer 8181 a.cur.parent = parent 8182 a.cur.node = node 8183 if !a.post(&a.cur) { 8184 return false 8185 } 8186 } 8187 return true 8188 } 8189 func (a *application) rewriteRefOfWindowSpecification(parent SQLNode, node *WindowSpecification, replacer replacerFunc) bool { 8190 if node == nil { 8191 return true 8192 } 8193 if a.pre != nil { 8194 a.cur.replacer = replacer 8195 a.cur.parent = parent 8196 a.cur.node = node 8197 if !a.pre(&a.cur) { 8198 return true 8199 } 8200 } 8201 if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { 8202 parent.(*WindowSpecification).Name = newNode.(IdentifierCI) 8203 }) { 8204 return false 8205 } 8206 if !a.rewriteExprs(node, node.PartitionClause, func(newNode, parent SQLNode) { 8207 parent.(*WindowSpecification).PartitionClause = newNode.(Exprs) 8208 }) { 8209 return false 8210 } 8211 if !a.rewriteOrderBy(node, node.OrderClause, func(newNode, parent SQLNode) { 8212 parent.(*WindowSpecification).OrderClause = newNode.(OrderBy) 8213 }) { 8214 return false 8215 } 8216 if !a.rewriteRefOfFrameClause(node, node.FrameClause, func(newNode, parent SQLNode) { 8217 parent.(*WindowSpecification).FrameClause = newNode.(*FrameClause) 8218 }) { 8219 return false 8220 } 8221 if a.post != nil { 8222 a.cur.replacer = replacer 8223 a.cur.parent = parent 8224 a.cur.node = node 8225 if !a.post(&a.cur) { 8226 return false 8227 } 8228 } 8229 return true 8230 } 8231 func (a *application) rewriteRefOfWith(parent SQLNode, node *With, replacer replacerFunc) bool { 8232 if node == nil { 8233 return true 8234 } 8235 if a.pre != nil { 8236 a.cur.replacer = replacer 8237 a.cur.parent = parent 8238 a.cur.node = node 8239 if !a.pre(&a.cur) { 8240 return true 8241 } 8242 } 8243 for x, el := range node.Ctes { 8244 if !a.rewriteRefOfCommonTableExpr(node, el, func(idx int) replacerFunc { 8245 return func(newNode, parent SQLNode) { 8246 parent.(*With).Ctes[idx] = newNode.(*CommonTableExpr) 8247 } 8248 }(x)) { 8249 return false 8250 } 8251 } 8252 if a.post != nil { 8253 a.cur.replacer = replacer 8254 a.cur.parent = parent 8255 a.cur.node = node 8256 if !a.post(&a.cur) { 8257 return false 8258 } 8259 } 8260 return true 8261 } 8262 func (a *application) rewriteRefOfXorExpr(parent SQLNode, node *XorExpr, replacer replacerFunc) bool { 8263 if node == nil { 8264 return true 8265 } 8266 if a.pre != nil { 8267 a.cur.replacer = replacer 8268 a.cur.parent = parent 8269 a.cur.node = node 8270 if !a.pre(&a.cur) { 8271 return true 8272 } 8273 } 8274 if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { 8275 parent.(*XorExpr).Left = newNode.(Expr) 8276 }) { 8277 return false 8278 } 8279 if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { 8280 parent.(*XorExpr).Right = newNode.(Expr) 8281 }) { 8282 return false 8283 } 8284 if a.post != nil { 8285 a.cur.replacer = replacer 8286 a.cur.parent = parent 8287 a.cur.node = node 8288 if !a.post(&a.cur) { 8289 return false 8290 } 8291 } 8292 return true 8293 } 8294 func (a *application) rewriteAggrFunc(parent SQLNode, node AggrFunc, replacer replacerFunc) bool { 8295 if node == nil { 8296 return true 8297 } 8298 switch node := node.(type) { 8299 case *Avg: 8300 return a.rewriteRefOfAvg(parent, node, replacer) 8301 case *BitAnd: 8302 return a.rewriteRefOfBitAnd(parent, node, replacer) 8303 case *BitOr: 8304 return a.rewriteRefOfBitOr(parent, node, replacer) 8305 case *BitXor: 8306 return a.rewriteRefOfBitXor(parent, node, replacer) 8307 case *Count: 8308 return a.rewriteRefOfCount(parent, node, replacer) 8309 case *CountStar: 8310 return a.rewriteRefOfCountStar(parent, node, replacer) 8311 case *GroupConcatExpr: 8312 return a.rewriteRefOfGroupConcatExpr(parent, node, replacer) 8313 case *Max: 8314 return a.rewriteRefOfMax(parent, node, replacer) 8315 case *Min: 8316 return a.rewriteRefOfMin(parent, node, replacer) 8317 case *Std: 8318 return a.rewriteRefOfStd(parent, node, replacer) 8319 case *StdDev: 8320 return a.rewriteRefOfStdDev(parent, node, replacer) 8321 case *StdPop: 8322 return a.rewriteRefOfStdPop(parent, node, replacer) 8323 case *StdSamp: 8324 return a.rewriteRefOfStdSamp(parent, node, replacer) 8325 case *Sum: 8326 return a.rewriteRefOfSum(parent, node, replacer) 8327 case *VarPop: 8328 return a.rewriteRefOfVarPop(parent, node, replacer) 8329 case *VarSamp: 8330 return a.rewriteRefOfVarSamp(parent, node, replacer) 8331 case *Variance: 8332 return a.rewriteRefOfVariance(parent, node, replacer) 8333 default: 8334 // this should never happen 8335 return true 8336 } 8337 } 8338 func (a *application) rewriteAlterOption(parent SQLNode, node AlterOption, replacer replacerFunc) bool { 8339 if node == nil { 8340 return true 8341 } 8342 switch node := node.(type) { 8343 case *AddColumns: 8344 return a.rewriteRefOfAddColumns(parent, node, replacer) 8345 case *AddConstraintDefinition: 8346 return a.rewriteRefOfAddConstraintDefinition(parent, node, replacer) 8347 case *AddIndexDefinition: 8348 return a.rewriteRefOfAddIndexDefinition(parent, node, replacer) 8349 case AlgorithmValue: 8350 return a.rewriteAlgorithmValue(parent, node, replacer) 8351 case *AlterCharset: 8352 return a.rewriteRefOfAlterCharset(parent, node, replacer) 8353 case *AlterCheck: 8354 return a.rewriteRefOfAlterCheck(parent, node, replacer) 8355 case *AlterColumn: 8356 return a.rewriteRefOfAlterColumn(parent, node, replacer) 8357 case *AlterIndex: 8358 return a.rewriteRefOfAlterIndex(parent, node, replacer) 8359 case *ChangeColumn: 8360 return a.rewriteRefOfChangeColumn(parent, node, replacer) 8361 case *DropColumn: 8362 return a.rewriteRefOfDropColumn(parent, node, replacer) 8363 case *DropKey: 8364 return a.rewriteRefOfDropKey(parent, node, replacer) 8365 case *Force: 8366 return a.rewriteRefOfForce(parent, node, replacer) 8367 case *KeyState: 8368 return a.rewriteRefOfKeyState(parent, node, replacer) 8369 case *LockOption: 8370 return a.rewriteRefOfLockOption(parent, node, replacer) 8371 case *ModifyColumn: 8372 return a.rewriteRefOfModifyColumn(parent, node, replacer) 8373 case *OrderByOption: 8374 return a.rewriteRefOfOrderByOption(parent, node, replacer) 8375 case *RenameColumn: 8376 return a.rewriteRefOfRenameColumn(parent, node, replacer) 8377 case *RenameIndex: 8378 return a.rewriteRefOfRenameIndex(parent, node, replacer) 8379 case *RenameTableName: 8380 return a.rewriteRefOfRenameTableName(parent, node, replacer) 8381 case TableOptions: 8382 return a.rewriteTableOptions(parent, node, replacer) 8383 case *TablespaceOperation: 8384 return a.rewriteRefOfTablespaceOperation(parent, node, replacer) 8385 case *Validation: 8386 return a.rewriteRefOfValidation(parent, node, replacer) 8387 default: 8388 // this should never happen 8389 return true 8390 } 8391 } 8392 func (a *application) rewriteCallable(parent SQLNode, node Callable, replacer replacerFunc) bool { 8393 if node == nil { 8394 return true 8395 } 8396 switch node := node.(type) { 8397 case *ArgumentLessWindowExpr: 8398 return a.rewriteRefOfArgumentLessWindowExpr(parent, node, replacer) 8399 case *Avg: 8400 return a.rewriteRefOfAvg(parent, node, replacer) 8401 case *CharExpr: 8402 return a.rewriteRefOfCharExpr(parent, node, replacer) 8403 case *ConvertExpr: 8404 return a.rewriteRefOfConvertExpr(parent, node, replacer) 8405 case *ConvertUsingExpr: 8406 return a.rewriteRefOfConvertUsingExpr(parent, node, replacer) 8407 case *Count: 8408 return a.rewriteRefOfCount(parent, node, replacer) 8409 case *CountStar: 8410 return a.rewriteRefOfCountStar(parent, node, replacer) 8411 case *CurTimeFuncExpr: 8412 return a.rewriteRefOfCurTimeFuncExpr(parent, node, replacer) 8413 case *ExtractFuncExpr: 8414 return a.rewriteRefOfExtractFuncExpr(parent, node, replacer) 8415 case *ExtractValueExpr: 8416 return a.rewriteRefOfExtractValueExpr(parent, node, replacer) 8417 case *FirstOrLastValueExpr: 8418 return a.rewriteRefOfFirstOrLastValueExpr(parent, node, replacer) 8419 case *FuncExpr: 8420 return a.rewriteRefOfFuncExpr(parent, node, replacer) 8421 case *GTIDFuncExpr: 8422 return a.rewriteRefOfGTIDFuncExpr(parent, node, replacer) 8423 case *GroupConcatExpr: 8424 return a.rewriteRefOfGroupConcatExpr(parent, node, replacer) 8425 case *InsertExpr: 8426 return a.rewriteRefOfInsertExpr(parent, node, replacer) 8427 case *IntervalFuncExpr: 8428 return a.rewriteRefOfIntervalFuncExpr(parent, node, replacer) 8429 case *JSONArrayExpr: 8430 return a.rewriteRefOfJSONArrayExpr(parent, node, replacer) 8431 case *JSONAttributesExpr: 8432 return a.rewriteRefOfJSONAttributesExpr(parent, node, replacer) 8433 case *JSONContainsExpr: 8434 return a.rewriteRefOfJSONContainsExpr(parent, node, replacer) 8435 case *JSONContainsPathExpr: 8436 return a.rewriteRefOfJSONContainsPathExpr(parent, node, replacer) 8437 case *JSONExtractExpr: 8438 return a.rewriteRefOfJSONExtractExpr(parent, node, replacer) 8439 case *JSONKeysExpr: 8440 return a.rewriteRefOfJSONKeysExpr(parent, node, replacer) 8441 case *JSONObjectExpr: 8442 return a.rewriteRefOfJSONObjectExpr(parent, node, replacer) 8443 case *JSONOverlapsExpr: 8444 return a.rewriteRefOfJSONOverlapsExpr(parent, node, replacer) 8445 case *JSONPrettyExpr: 8446 return a.rewriteRefOfJSONPrettyExpr(parent, node, replacer) 8447 case *JSONQuoteExpr: 8448 return a.rewriteRefOfJSONQuoteExpr(parent, node, replacer) 8449 case *JSONRemoveExpr: 8450 return a.rewriteRefOfJSONRemoveExpr(parent, node, replacer) 8451 case *JSONSchemaValidFuncExpr: 8452 return a.rewriteRefOfJSONSchemaValidFuncExpr(parent, node, replacer) 8453 case *JSONSchemaValidationReportFuncExpr: 8454 return a.rewriteRefOfJSONSchemaValidationReportFuncExpr(parent, node, replacer) 8455 case *JSONSearchExpr: 8456 return a.rewriteRefOfJSONSearchExpr(parent, node, replacer) 8457 case *JSONStorageFreeExpr: 8458 return a.rewriteRefOfJSONStorageFreeExpr(parent, node, replacer) 8459 case *JSONStorageSizeExpr: 8460 return a.rewriteRefOfJSONStorageSizeExpr(parent, node, replacer) 8461 case *JSONUnquoteExpr: 8462 return a.rewriteRefOfJSONUnquoteExpr(parent, node, replacer) 8463 case *JSONValueExpr: 8464 return a.rewriteRefOfJSONValueExpr(parent, node, replacer) 8465 case *JSONValueMergeExpr: 8466 return a.rewriteRefOfJSONValueMergeExpr(parent, node, replacer) 8467 case *JSONValueModifierExpr: 8468 return a.rewriteRefOfJSONValueModifierExpr(parent, node, replacer) 8469 case *LagLeadExpr: 8470 return a.rewriteRefOfLagLeadExpr(parent, node, replacer) 8471 case *LineStringExpr: 8472 return a.rewriteRefOfLineStringExpr(parent, node, replacer) 8473 case *LocateExpr: 8474 return a.rewriteRefOfLocateExpr(parent, node, replacer) 8475 case *MatchExpr: 8476 return a.rewriteRefOfMatchExpr(parent, node, replacer) 8477 case *Max: 8478 return a.rewriteRefOfMax(parent, node, replacer) 8479 case *MemberOfExpr: 8480 return a.rewriteRefOfMemberOfExpr(parent, node, replacer) 8481 case *Min: 8482 return a.rewriteRefOfMin(parent, node, replacer) 8483 case *NTHValueExpr: 8484 return a.rewriteRefOfNTHValueExpr(parent, node, replacer) 8485 case *NamedWindow: 8486 return a.rewriteRefOfNamedWindow(parent, node, replacer) 8487 case *NtileExpr: 8488 return a.rewriteRefOfNtileExpr(parent, node, replacer) 8489 case *PerformanceSchemaFuncExpr: 8490 return a.rewriteRefOfPerformanceSchemaFuncExpr(parent, node, replacer) 8491 case *PointExpr: 8492 return a.rewriteRefOfPointExpr(parent, node, replacer) 8493 case *RegexpInstrExpr: 8494 return a.rewriteRefOfRegexpInstrExpr(parent, node, replacer) 8495 case *RegexpLikeExpr: 8496 return a.rewriteRefOfRegexpLikeExpr(parent, node, replacer) 8497 case *RegexpReplaceExpr: 8498 return a.rewriteRefOfRegexpReplaceExpr(parent, node, replacer) 8499 case *RegexpSubstrExpr: 8500 return a.rewriteRefOfRegexpSubstrExpr(parent, node, replacer) 8501 case *SubstrExpr: 8502 return a.rewriteRefOfSubstrExpr(parent, node, replacer) 8503 case *Sum: 8504 return a.rewriteRefOfSum(parent, node, replacer) 8505 case *TimestampFuncExpr: 8506 return a.rewriteRefOfTimestampFuncExpr(parent, node, replacer) 8507 case *TrimFuncExpr: 8508 return a.rewriteRefOfTrimFuncExpr(parent, node, replacer) 8509 case *UpdateXMLExpr: 8510 return a.rewriteRefOfUpdateXMLExpr(parent, node, replacer) 8511 case *ValuesFuncExpr: 8512 return a.rewriteRefOfValuesFuncExpr(parent, node, replacer) 8513 case *WeightStringFuncExpr: 8514 return a.rewriteRefOfWeightStringFuncExpr(parent, node, replacer) 8515 default: 8516 // this should never happen 8517 return true 8518 } 8519 } 8520 func (a *application) rewriteColTuple(parent SQLNode, node ColTuple, replacer replacerFunc) bool { 8521 if node == nil { 8522 return true 8523 } 8524 switch node := node.(type) { 8525 case ListArg: 8526 return a.rewriteListArg(parent, node, replacer) 8527 case *Subquery: 8528 return a.rewriteRefOfSubquery(parent, node, replacer) 8529 case ValTuple: 8530 return a.rewriteValTuple(parent, node, replacer) 8531 default: 8532 // this should never happen 8533 return true 8534 } 8535 } 8536 func (a *application) rewriteConstraintInfo(parent SQLNode, node ConstraintInfo, replacer replacerFunc) bool { 8537 if node == nil { 8538 return true 8539 } 8540 switch node := node.(type) { 8541 case *CheckConstraintDefinition: 8542 return a.rewriteRefOfCheckConstraintDefinition(parent, node, replacer) 8543 case *ForeignKeyDefinition: 8544 return a.rewriteRefOfForeignKeyDefinition(parent, node, replacer) 8545 default: 8546 // this should never happen 8547 return true 8548 } 8549 } 8550 func (a *application) rewriteDBDDLStatement(parent SQLNode, node DBDDLStatement, replacer replacerFunc) bool { 8551 if node == nil { 8552 return true 8553 } 8554 switch node := node.(type) { 8555 case *AlterDatabase: 8556 return a.rewriteRefOfAlterDatabase(parent, node, replacer) 8557 case *CreateDatabase: 8558 return a.rewriteRefOfCreateDatabase(parent, node, replacer) 8559 case *DropDatabase: 8560 return a.rewriteRefOfDropDatabase(parent, node, replacer) 8561 default: 8562 // this should never happen 8563 return true 8564 } 8565 } 8566 func (a *application) rewriteDDLStatement(parent SQLNode, node DDLStatement, replacer replacerFunc) bool { 8567 if node == nil { 8568 return true 8569 } 8570 switch node := node.(type) { 8571 case *AlterTable: 8572 return a.rewriteRefOfAlterTable(parent, node, replacer) 8573 case *AlterView: 8574 return a.rewriteRefOfAlterView(parent, node, replacer) 8575 case *CreateTable: 8576 return a.rewriteRefOfCreateTable(parent, node, replacer) 8577 case *CreateView: 8578 return a.rewriteRefOfCreateView(parent, node, replacer) 8579 case *DropTable: 8580 return a.rewriteRefOfDropTable(parent, node, replacer) 8581 case *DropView: 8582 return a.rewriteRefOfDropView(parent, node, replacer) 8583 case *RenameTable: 8584 return a.rewriteRefOfRenameTable(parent, node, replacer) 8585 case *TruncateTable: 8586 return a.rewriteRefOfTruncateTable(parent, node, replacer) 8587 default: 8588 // this should never happen 8589 return true 8590 } 8591 } 8592 func (a *application) rewriteExplain(parent SQLNode, node Explain, replacer replacerFunc) bool { 8593 if node == nil { 8594 return true 8595 } 8596 switch node := node.(type) { 8597 case *ExplainStmt: 8598 return a.rewriteRefOfExplainStmt(parent, node, replacer) 8599 case *ExplainTab: 8600 return a.rewriteRefOfExplainTab(parent, node, replacer) 8601 default: 8602 // this should never happen 8603 return true 8604 } 8605 } 8606 func (a *application) rewriteExpr(parent SQLNode, node Expr, replacer replacerFunc) bool { 8607 if node == nil { 8608 return true 8609 } 8610 switch node := node.(type) { 8611 case *AndExpr: 8612 return a.rewriteRefOfAndExpr(parent, node, replacer) 8613 case Argument: 8614 return a.rewriteArgument(parent, node, replacer) 8615 case *ArgumentLessWindowExpr: 8616 return a.rewriteRefOfArgumentLessWindowExpr(parent, node, replacer) 8617 case *Avg: 8618 return a.rewriteRefOfAvg(parent, node, replacer) 8619 case *BetweenExpr: 8620 return a.rewriteRefOfBetweenExpr(parent, node, replacer) 8621 case *BinaryExpr: 8622 return a.rewriteRefOfBinaryExpr(parent, node, replacer) 8623 case *BitAnd: 8624 return a.rewriteRefOfBitAnd(parent, node, replacer) 8625 case *BitOr: 8626 return a.rewriteRefOfBitOr(parent, node, replacer) 8627 case *BitXor: 8628 return a.rewriteRefOfBitXor(parent, node, replacer) 8629 case BoolVal: 8630 return a.rewriteBoolVal(parent, node, replacer) 8631 case *CaseExpr: 8632 return a.rewriteRefOfCaseExpr(parent, node, replacer) 8633 case *CastExpr: 8634 return a.rewriteRefOfCastExpr(parent, node, replacer) 8635 case *CharExpr: 8636 return a.rewriteRefOfCharExpr(parent, node, replacer) 8637 case *ColName: 8638 return a.rewriteRefOfColName(parent, node, replacer) 8639 case *CollateExpr: 8640 return a.rewriteRefOfCollateExpr(parent, node, replacer) 8641 case *ComparisonExpr: 8642 return a.rewriteRefOfComparisonExpr(parent, node, replacer) 8643 case *ConvertExpr: 8644 return a.rewriteRefOfConvertExpr(parent, node, replacer) 8645 case *ConvertUsingExpr: 8646 return a.rewriteRefOfConvertUsingExpr(parent, node, replacer) 8647 case *Count: 8648 return a.rewriteRefOfCount(parent, node, replacer) 8649 case *CountStar: 8650 return a.rewriteRefOfCountStar(parent, node, replacer) 8651 case *CurTimeFuncExpr: 8652 return a.rewriteRefOfCurTimeFuncExpr(parent, node, replacer) 8653 case *Default: 8654 return a.rewriteRefOfDefault(parent, node, replacer) 8655 case *ExistsExpr: 8656 return a.rewriteRefOfExistsExpr(parent, node, replacer) 8657 case *ExtractFuncExpr: 8658 return a.rewriteRefOfExtractFuncExpr(parent, node, replacer) 8659 case *ExtractValueExpr: 8660 return a.rewriteRefOfExtractValueExpr(parent, node, replacer) 8661 case *ExtractedSubquery: 8662 return a.rewriteRefOfExtractedSubquery(parent, node, replacer) 8663 case *FirstOrLastValueExpr: 8664 return a.rewriteRefOfFirstOrLastValueExpr(parent, node, replacer) 8665 case *FuncExpr: 8666 return a.rewriteRefOfFuncExpr(parent, node, replacer) 8667 case *GTIDFuncExpr: 8668 return a.rewriteRefOfGTIDFuncExpr(parent, node, replacer) 8669 case *GroupConcatExpr: 8670 return a.rewriteRefOfGroupConcatExpr(parent, node, replacer) 8671 case *InsertExpr: 8672 return a.rewriteRefOfInsertExpr(parent, node, replacer) 8673 case *IntervalExpr: 8674 return a.rewriteRefOfIntervalExpr(parent, node, replacer) 8675 case *IntervalFuncExpr: 8676 return a.rewriteRefOfIntervalFuncExpr(parent, node, replacer) 8677 case *IntroducerExpr: 8678 return a.rewriteRefOfIntroducerExpr(parent, node, replacer) 8679 case *IsExpr: 8680 return a.rewriteRefOfIsExpr(parent, node, replacer) 8681 case *JSONArrayExpr: 8682 return a.rewriteRefOfJSONArrayExpr(parent, node, replacer) 8683 case *JSONAttributesExpr: 8684 return a.rewriteRefOfJSONAttributesExpr(parent, node, replacer) 8685 case *JSONContainsExpr: 8686 return a.rewriteRefOfJSONContainsExpr(parent, node, replacer) 8687 case *JSONContainsPathExpr: 8688 return a.rewriteRefOfJSONContainsPathExpr(parent, node, replacer) 8689 case *JSONExtractExpr: 8690 return a.rewriteRefOfJSONExtractExpr(parent, node, replacer) 8691 case *JSONKeysExpr: 8692 return a.rewriteRefOfJSONKeysExpr(parent, node, replacer) 8693 case *JSONObjectExpr: 8694 return a.rewriteRefOfJSONObjectExpr(parent, node, replacer) 8695 case *JSONOverlapsExpr: 8696 return a.rewriteRefOfJSONOverlapsExpr(parent, node, replacer) 8697 case *JSONPrettyExpr: 8698 return a.rewriteRefOfJSONPrettyExpr(parent, node, replacer) 8699 case *JSONQuoteExpr: 8700 return a.rewriteRefOfJSONQuoteExpr(parent, node, replacer) 8701 case *JSONRemoveExpr: 8702 return a.rewriteRefOfJSONRemoveExpr(parent, node, replacer) 8703 case *JSONSchemaValidFuncExpr: 8704 return a.rewriteRefOfJSONSchemaValidFuncExpr(parent, node, replacer) 8705 case *JSONSchemaValidationReportFuncExpr: 8706 return a.rewriteRefOfJSONSchemaValidationReportFuncExpr(parent, node, replacer) 8707 case *JSONSearchExpr: 8708 return a.rewriteRefOfJSONSearchExpr(parent, node, replacer) 8709 case *JSONStorageFreeExpr: 8710 return a.rewriteRefOfJSONStorageFreeExpr(parent, node, replacer) 8711 case *JSONStorageSizeExpr: 8712 return a.rewriteRefOfJSONStorageSizeExpr(parent, node, replacer) 8713 case *JSONUnquoteExpr: 8714 return a.rewriteRefOfJSONUnquoteExpr(parent, node, replacer) 8715 case *JSONValueExpr: 8716 return a.rewriteRefOfJSONValueExpr(parent, node, replacer) 8717 case *JSONValueMergeExpr: 8718 return a.rewriteRefOfJSONValueMergeExpr(parent, node, replacer) 8719 case *JSONValueModifierExpr: 8720 return a.rewriteRefOfJSONValueModifierExpr(parent, node, replacer) 8721 case *LagLeadExpr: 8722 return a.rewriteRefOfLagLeadExpr(parent, node, replacer) 8723 case *LineStringExpr: 8724 return a.rewriteRefOfLineStringExpr(parent, node, replacer) 8725 case ListArg: 8726 return a.rewriteListArg(parent, node, replacer) 8727 case *Literal: 8728 return a.rewriteRefOfLiteral(parent, node, replacer) 8729 case *LocateExpr: 8730 return a.rewriteRefOfLocateExpr(parent, node, replacer) 8731 case *LockingFunc: 8732 return a.rewriteRefOfLockingFunc(parent, node, replacer) 8733 case *MatchExpr: 8734 return a.rewriteRefOfMatchExpr(parent, node, replacer) 8735 case *Max: 8736 return a.rewriteRefOfMax(parent, node, replacer) 8737 case *MemberOfExpr: 8738 return a.rewriteRefOfMemberOfExpr(parent, node, replacer) 8739 case *Min: 8740 return a.rewriteRefOfMin(parent, node, replacer) 8741 case *NTHValueExpr: 8742 return a.rewriteRefOfNTHValueExpr(parent, node, replacer) 8743 case *NamedWindow: 8744 return a.rewriteRefOfNamedWindow(parent, node, replacer) 8745 case *NotExpr: 8746 return a.rewriteRefOfNotExpr(parent, node, replacer) 8747 case *NtileExpr: 8748 return a.rewriteRefOfNtileExpr(parent, node, replacer) 8749 case *NullVal: 8750 return a.rewriteRefOfNullVal(parent, node, replacer) 8751 case *Offset: 8752 return a.rewriteRefOfOffset(parent, node, replacer) 8753 case *OrExpr: 8754 return a.rewriteRefOfOrExpr(parent, node, replacer) 8755 case *PerformanceSchemaFuncExpr: 8756 return a.rewriteRefOfPerformanceSchemaFuncExpr(parent, node, replacer) 8757 case *PointExpr: 8758 return a.rewriteRefOfPointExpr(parent, node, replacer) 8759 case *RegexpInstrExpr: 8760 return a.rewriteRefOfRegexpInstrExpr(parent, node, replacer) 8761 case *RegexpLikeExpr: 8762 return a.rewriteRefOfRegexpLikeExpr(parent, node, replacer) 8763 case *RegexpReplaceExpr: 8764 return a.rewriteRefOfRegexpReplaceExpr(parent, node, replacer) 8765 case *RegexpSubstrExpr: 8766 return a.rewriteRefOfRegexpSubstrExpr(parent, node, replacer) 8767 case *Std: 8768 return a.rewriteRefOfStd(parent, node, replacer) 8769 case *StdDev: 8770 return a.rewriteRefOfStdDev(parent, node, replacer) 8771 case *StdPop: 8772 return a.rewriteRefOfStdPop(parent, node, replacer) 8773 case *StdSamp: 8774 return a.rewriteRefOfStdSamp(parent, node, replacer) 8775 case *Subquery: 8776 return a.rewriteRefOfSubquery(parent, node, replacer) 8777 case *SubstrExpr: 8778 return a.rewriteRefOfSubstrExpr(parent, node, replacer) 8779 case *Sum: 8780 return a.rewriteRefOfSum(parent, node, replacer) 8781 case *TimestampFuncExpr: 8782 return a.rewriteRefOfTimestampFuncExpr(parent, node, replacer) 8783 case *TrimFuncExpr: 8784 return a.rewriteRefOfTrimFuncExpr(parent, node, replacer) 8785 case *UnaryExpr: 8786 return a.rewriteRefOfUnaryExpr(parent, node, replacer) 8787 case *UpdateXMLExpr: 8788 return a.rewriteRefOfUpdateXMLExpr(parent, node, replacer) 8789 case ValTuple: 8790 return a.rewriteValTuple(parent, node, replacer) 8791 case *ValuesFuncExpr: 8792 return a.rewriteRefOfValuesFuncExpr(parent, node, replacer) 8793 case *VarPop: 8794 return a.rewriteRefOfVarPop(parent, node, replacer) 8795 case *VarSamp: 8796 return a.rewriteRefOfVarSamp(parent, node, replacer) 8797 case *Variable: 8798 return a.rewriteRefOfVariable(parent, node, replacer) 8799 case *Variance: 8800 return a.rewriteRefOfVariance(parent, node, replacer) 8801 case *WeightStringFuncExpr: 8802 return a.rewriteRefOfWeightStringFuncExpr(parent, node, replacer) 8803 case *XorExpr: 8804 return a.rewriteRefOfXorExpr(parent, node, replacer) 8805 default: 8806 // this should never happen 8807 return true 8808 } 8809 } 8810 func (a *application) rewriteInsertRows(parent SQLNode, node InsertRows, replacer replacerFunc) bool { 8811 if node == nil { 8812 return true 8813 } 8814 switch node := node.(type) { 8815 case *Select: 8816 return a.rewriteRefOfSelect(parent, node, replacer) 8817 case *Union: 8818 return a.rewriteRefOfUnion(parent, node, replacer) 8819 case Values: 8820 return a.rewriteValues(parent, node, replacer) 8821 default: 8822 // this should never happen 8823 return true 8824 } 8825 } 8826 func (a *application) rewriteSelectExpr(parent SQLNode, node SelectExpr, replacer replacerFunc) bool { 8827 if node == nil { 8828 return true 8829 } 8830 switch node := node.(type) { 8831 case *AliasedExpr: 8832 return a.rewriteRefOfAliasedExpr(parent, node, replacer) 8833 case *Nextval: 8834 return a.rewriteRefOfNextval(parent, node, replacer) 8835 case *StarExpr: 8836 return a.rewriteRefOfStarExpr(parent, node, replacer) 8837 default: 8838 // this should never happen 8839 return true 8840 } 8841 } 8842 func (a *application) rewriteSelectStatement(parent SQLNode, node SelectStatement, replacer replacerFunc) bool { 8843 if node == nil { 8844 return true 8845 } 8846 switch node := node.(type) { 8847 case *Select: 8848 return a.rewriteRefOfSelect(parent, node, replacer) 8849 case *Union: 8850 return a.rewriteRefOfUnion(parent, node, replacer) 8851 default: 8852 // this should never happen 8853 return true 8854 } 8855 } 8856 func (a *application) rewriteShowInternal(parent SQLNode, node ShowInternal, replacer replacerFunc) bool { 8857 if node == nil { 8858 return true 8859 } 8860 switch node := node.(type) { 8861 case *ShowBasic: 8862 return a.rewriteRefOfShowBasic(parent, node, replacer) 8863 case *ShowCreate: 8864 return a.rewriteRefOfShowCreate(parent, node, replacer) 8865 case *ShowOther: 8866 return a.rewriteRefOfShowOther(parent, node, replacer) 8867 default: 8868 // this should never happen 8869 return true 8870 } 8871 } 8872 func (a *application) rewriteSimpleTableExpr(parent SQLNode, node SimpleTableExpr, replacer replacerFunc) bool { 8873 if node == nil { 8874 return true 8875 } 8876 switch node := node.(type) { 8877 case *DerivedTable: 8878 return a.rewriteRefOfDerivedTable(parent, node, replacer) 8879 case TableName: 8880 return a.rewriteTableName(parent, node, replacer) 8881 default: 8882 // this should never happen 8883 return true 8884 } 8885 } 8886 func (a *application) rewriteStatement(parent SQLNode, node Statement, replacer replacerFunc) bool { 8887 if node == nil { 8888 return true 8889 } 8890 switch node := node.(type) { 8891 case *AlterDatabase: 8892 return a.rewriteRefOfAlterDatabase(parent, node, replacer) 8893 case *AlterMigration: 8894 return a.rewriteRefOfAlterMigration(parent, node, replacer) 8895 case *AlterTable: 8896 return a.rewriteRefOfAlterTable(parent, node, replacer) 8897 case *AlterView: 8898 return a.rewriteRefOfAlterView(parent, node, replacer) 8899 case *AlterVschema: 8900 return a.rewriteRefOfAlterVschema(parent, node, replacer) 8901 case *Begin: 8902 return a.rewriteRefOfBegin(parent, node, replacer) 8903 case *CallProc: 8904 return a.rewriteRefOfCallProc(parent, node, replacer) 8905 case *CommentOnly: 8906 return a.rewriteRefOfCommentOnly(parent, node, replacer) 8907 case *Commit: 8908 return a.rewriteRefOfCommit(parent, node, replacer) 8909 case *CreateDatabase: 8910 return a.rewriteRefOfCreateDatabase(parent, node, replacer) 8911 case *CreateTable: 8912 return a.rewriteRefOfCreateTable(parent, node, replacer) 8913 case *CreateView: 8914 return a.rewriteRefOfCreateView(parent, node, replacer) 8915 case *DeallocateStmt: 8916 return a.rewriteRefOfDeallocateStmt(parent, node, replacer) 8917 case *Delete: 8918 return a.rewriteRefOfDelete(parent, node, replacer) 8919 case *DropDatabase: 8920 return a.rewriteRefOfDropDatabase(parent, node, replacer) 8921 case *DropTable: 8922 return a.rewriteRefOfDropTable(parent, node, replacer) 8923 case *DropView: 8924 return a.rewriteRefOfDropView(parent, node, replacer) 8925 case *ExecuteStmt: 8926 return a.rewriteRefOfExecuteStmt(parent, node, replacer) 8927 case *ExplainStmt: 8928 return a.rewriteRefOfExplainStmt(parent, node, replacer) 8929 case *ExplainTab: 8930 return a.rewriteRefOfExplainTab(parent, node, replacer) 8931 case *Flush: 8932 return a.rewriteRefOfFlush(parent, node, replacer) 8933 case *Insert: 8934 return a.rewriteRefOfInsert(parent, node, replacer) 8935 case *Load: 8936 return a.rewriteRefOfLoad(parent, node, replacer) 8937 case *LockTables: 8938 return a.rewriteRefOfLockTables(parent, node, replacer) 8939 case *OtherAdmin: 8940 return a.rewriteRefOfOtherAdmin(parent, node, replacer) 8941 case *OtherRead: 8942 return a.rewriteRefOfOtherRead(parent, node, replacer) 8943 case *PrepareStmt: 8944 return a.rewriteRefOfPrepareStmt(parent, node, replacer) 8945 case *Release: 8946 return a.rewriteRefOfRelease(parent, node, replacer) 8947 case *RenameTable: 8948 return a.rewriteRefOfRenameTable(parent, node, replacer) 8949 case *RevertMigration: 8950 return a.rewriteRefOfRevertMigration(parent, node, replacer) 8951 case *Rollback: 8952 return a.rewriteRefOfRollback(parent, node, replacer) 8953 case *SRollback: 8954 return a.rewriteRefOfSRollback(parent, node, replacer) 8955 case *Savepoint: 8956 return a.rewriteRefOfSavepoint(parent, node, replacer) 8957 case *Select: 8958 return a.rewriteRefOfSelect(parent, node, replacer) 8959 case *Set: 8960 return a.rewriteRefOfSet(parent, node, replacer) 8961 case *Show: 8962 return a.rewriteRefOfShow(parent, node, replacer) 8963 case *ShowMigrationLogs: 8964 return a.rewriteRefOfShowMigrationLogs(parent, node, replacer) 8965 case *ShowThrottledApps: 8966 return a.rewriteRefOfShowThrottledApps(parent, node, replacer) 8967 case *ShowThrottlerStatus: 8968 return a.rewriteRefOfShowThrottlerStatus(parent, node, replacer) 8969 case *Stream: 8970 return a.rewriteRefOfStream(parent, node, replacer) 8971 case *TruncateTable: 8972 return a.rewriteRefOfTruncateTable(parent, node, replacer) 8973 case *Union: 8974 return a.rewriteRefOfUnion(parent, node, replacer) 8975 case *UnlockTables: 8976 return a.rewriteRefOfUnlockTables(parent, node, replacer) 8977 case *Update: 8978 return a.rewriteRefOfUpdate(parent, node, replacer) 8979 case *Use: 8980 return a.rewriteRefOfUse(parent, node, replacer) 8981 case *VExplainStmt: 8982 return a.rewriteRefOfVExplainStmt(parent, node, replacer) 8983 case *VStream: 8984 return a.rewriteRefOfVStream(parent, node, replacer) 8985 default: 8986 // this should never happen 8987 return true 8988 } 8989 } 8990 func (a *application) rewriteTableExpr(parent SQLNode, node TableExpr, replacer replacerFunc) bool { 8991 if node == nil { 8992 return true 8993 } 8994 switch node := node.(type) { 8995 case *AliasedTableExpr: 8996 return a.rewriteRefOfAliasedTableExpr(parent, node, replacer) 8997 case *JSONTableExpr: 8998 return a.rewriteRefOfJSONTableExpr(parent, node, replacer) 8999 case *JoinTableExpr: 9000 return a.rewriteRefOfJoinTableExpr(parent, node, replacer) 9001 case *ParenTableExpr: 9002 return a.rewriteRefOfParenTableExpr(parent, node, replacer) 9003 default: 9004 // this should never happen 9005 return true 9006 } 9007 } 9008 func (a *application) rewriteAlgorithmValue(parent SQLNode, node AlgorithmValue, replacer replacerFunc) bool { 9009 if a.pre != nil { 9010 a.cur.replacer = replacer 9011 a.cur.parent = parent 9012 a.cur.node = node 9013 if !a.pre(&a.cur) { 9014 return true 9015 } 9016 } 9017 if a.post != nil { 9018 if a.pre == nil { 9019 a.cur.replacer = replacer 9020 a.cur.parent = parent 9021 a.cur.node = node 9022 } 9023 if !a.post(&a.cur) { 9024 return false 9025 } 9026 } 9027 return true 9028 } 9029 func (a *application) rewriteArgument(parent SQLNode, node Argument, replacer replacerFunc) bool { 9030 if a.pre != nil { 9031 a.cur.replacer = replacer 9032 a.cur.parent = parent 9033 a.cur.node = node 9034 if !a.pre(&a.cur) { 9035 return true 9036 } 9037 } 9038 if a.post != nil { 9039 if a.pre == nil { 9040 a.cur.replacer = replacer 9041 a.cur.parent = parent 9042 a.cur.node = node 9043 } 9044 if !a.post(&a.cur) { 9045 return false 9046 } 9047 } 9048 return true 9049 } 9050 func (a *application) rewriteBoolVal(parent SQLNode, node BoolVal, replacer replacerFunc) bool { 9051 if a.pre != nil { 9052 a.cur.replacer = replacer 9053 a.cur.parent = parent 9054 a.cur.node = node 9055 if !a.pre(&a.cur) { 9056 return true 9057 } 9058 } 9059 if a.post != nil { 9060 if a.pre == nil { 9061 a.cur.replacer = replacer 9062 a.cur.parent = parent 9063 a.cur.node = node 9064 } 9065 if !a.post(&a.cur) { 9066 return false 9067 } 9068 } 9069 return true 9070 } 9071 func (a *application) rewriteListArg(parent SQLNode, node ListArg, replacer replacerFunc) bool { 9072 if a.pre != nil { 9073 a.cur.replacer = replacer 9074 a.cur.parent = parent 9075 a.cur.node = node 9076 if !a.pre(&a.cur) { 9077 return true 9078 } 9079 } 9080 if a.post != nil { 9081 if a.pre == nil { 9082 a.cur.replacer = replacer 9083 a.cur.parent = parent 9084 a.cur.node = node 9085 } 9086 if !a.post(&a.cur) { 9087 return false 9088 } 9089 } 9090 return true 9091 } 9092 func (a *application) rewriteMatchAction(parent SQLNode, node MatchAction, replacer replacerFunc) bool { 9093 if a.pre != nil { 9094 a.cur.replacer = replacer 9095 a.cur.parent = parent 9096 a.cur.node = node 9097 if !a.pre(&a.cur) { 9098 return true 9099 } 9100 } 9101 if a.post != nil { 9102 if a.pre == nil { 9103 a.cur.replacer = replacer 9104 a.cur.parent = parent 9105 a.cur.node = node 9106 } 9107 if !a.post(&a.cur) { 9108 return false 9109 } 9110 } 9111 return true 9112 } 9113 func (a *application) rewriteReferenceAction(parent SQLNode, node ReferenceAction, replacer replacerFunc) bool { 9114 if a.pre != nil { 9115 a.cur.replacer = replacer 9116 a.cur.parent = parent 9117 a.cur.node = node 9118 if !a.pre(&a.cur) { 9119 return true 9120 } 9121 } 9122 if a.post != nil { 9123 if a.pre == nil { 9124 a.cur.replacer = replacer 9125 a.cur.parent = parent 9126 a.cur.node = node 9127 } 9128 if !a.post(&a.cur) { 9129 return false 9130 } 9131 } 9132 return true 9133 } 9134 func (a *application) rewriteRefOfIdentifierCI(parent SQLNode, node *IdentifierCI, replacer replacerFunc) bool { 9135 if node == nil { 9136 return true 9137 } 9138 if a.pre != nil { 9139 a.cur.replacer = replacer 9140 a.cur.parent = parent 9141 a.cur.node = node 9142 if !a.pre(&a.cur) { 9143 return true 9144 } 9145 } 9146 if a.post != nil { 9147 if a.pre == nil { 9148 a.cur.replacer = replacer 9149 a.cur.parent = parent 9150 a.cur.node = node 9151 } 9152 if !a.post(&a.cur) { 9153 return false 9154 } 9155 } 9156 return true 9157 } 9158 func (a *application) rewriteRefOfIdentifierCS(parent SQLNode, node *IdentifierCS, replacer replacerFunc) bool { 9159 if node == nil { 9160 return true 9161 } 9162 if a.pre != nil { 9163 a.cur.replacer = replacer 9164 a.cur.parent = parent 9165 a.cur.node = node 9166 if !a.pre(&a.cur) { 9167 return true 9168 } 9169 } 9170 if a.post != nil { 9171 if a.pre == nil { 9172 a.cur.replacer = replacer 9173 a.cur.parent = parent 9174 a.cur.node = node 9175 } 9176 if !a.post(&a.cur) { 9177 return false 9178 } 9179 } 9180 return true 9181 } 9182 func (a *application) rewriteRefOfRootNode(parent SQLNode, node *RootNode, replacer replacerFunc) bool { 9183 if node == nil { 9184 return true 9185 } 9186 if a.pre != nil { 9187 a.cur.replacer = replacer 9188 a.cur.parent = parent 9189 a.cur.node = node 9190 if !a.pre(&a.cur) { 9191 return true 9192 } 9193 } 9194 if !a.rewriteSQLNode(node, node.SQLNode, func(newNode, parent SQLNode) { 9195 parent.(*RootNode).SQLNode = newNode.(SQLNode) 9196 }) { 9197 return false 9198 } 9199 if a.post != nil { 9200 a.cur.replacer = replacer 9201 a.cur.parent = parent 9202 a.cur.node = node 9203 if !a.post(&a.cur) { 9204 return false 9205 } 9206 } 9207 return true 9208 } 9209 func (a *application) rewriteRefOfTableName(parent SQLNode, node *TableName, replacer replacerFunc) bool { 9210 if node == nil { 9211 return true 9212 } 9213 if a.pre != nil { 9214 a.cur.replacer = replacer 9215 a.cur.parent = parent 9216 a.cur.node = node 9217 if !a.pre(&a.cur) { 9218 return true 9219 } 9220 } 9221 if !a.rewriteIdentifierCS(node, node.Name, func(newNode, parent SQLNode) { 9222 parent.(*TableName).Name = newNode.(IdentifierCS) 9223 }) { 9224 return false 9225 } 9226 if !a.rewriteIdentifierCS(node, node.Qualifier, func(newNode, parent SQLNode) { 9227 parent.(*TableName).Qualifier = newNode.(IdentifierCS) 9228 }) { 9229 return false 9230 } 9231 if a.post != nil { 9232 a.cur.replacer = replacer 9233 a.cur.parent = parent 9234 a.cur.node = node 9235 if !a.post(&a.cur) { 9236 return false 9237 } 9238 } 9239 return true 9240 } 9241 func (a *application) rewriteRefOfVindexParam(parent SQLNode, node *VindexParam, replacer replacerFunc) bool { 9242 if node == nil { 9243 return true 9244 } 9245 if a.pre != nil { 9246 a.cur.replacer = replacer 9247 a.cur.parent = parent 9248 a.cur.node = node 9249 if !a.pre(&a.cur) { 9250 return true 9251 } 9252 } 9253 if !a.rewriteIdentifierCI(node, node.Key, func(newNode, parent SQLNode) { 9254 parent.(*VindexParam).Key = newNode.(IdentifierCI) 9255 }) { 9256 return false 9257 } 9258 if a.post != nil { 9259 a.cur.replacer = replacer 9260 a.cur.parent = parent 9261 a.cur.node = node 9262 if !a.post(&a.cur) { 9263 return false 9264 } 9265 } 9266 return true 9267 }