Parse the part relative to the WHERE clause of the SQL query.
(sql, example, anonymize_values)
| 664 | |
| 665 | |
| 666 | def _parse_where(sql, example, anonymize_values): |
| 667 | """Parse the part relative to the WHERE clause of the SQL query.""" |
| 668 | successful_copy = True |
| 669 | for item in sql: |
| 670 | if item.ttype == sqlparse.tokens.Text.Whitespace: |
| 671 | continue |
| 672 | |
| 673 | if _is_keyword(item) and item.value.lower() in ('where',): |
| 674 | _add_simple_step(item, example) |
| 675 | continue |
| 676 | |
| 677 | if _is_comparison(item): |
| 678 | successful_copy = _parse_comparison(item, example, |
| 679 | anonymize_values) and successful_copy |
| 680 | continue |
| 681 | |
| 682 | if _is_comparison_operator(item): |
| 683 | _add_simple_step(item, example) |
| 684 | continue |
| 685 | |
| 686 | if _is_identifier(item): |
| 687 | successful_copy = _parse_identifier(item, example, |
| 688 | anonymize_values) and successful_copy |
| 689 | continue |
| 690 | |
| 691 | if _is_identifier_list(item): |
| 692 | successful_copy = _parse_identifier_list( |
| 693 | item, example, anonymize_values) and successful_copy |
| 694 | continue |
| 695 | |
| 696 | if _is_keyword(item) and item.value.lower() in ('between', 'and', 'or'): |
| 697 | _add_simple_step(item, example) |
| 698 | continue |
| 699 | |
| 700 | if _is_keyword(item) and item.value.lower() in ('not', 'in', 'intersect'): |
| 701 | _add_simple_step(item, example) |
| 702 | continue |
| 703 | |
| 704 | if _is_keyword(item) and item.value.lower() in ('distinct',): |
| 705 | _add_simple_step(item, example) |
| 706 | continue |
| 707 | |
| 708 | if _is_integer(item): |
| 709 | prev_len = len(example.gold_sql_query.actions) |
| 710 | successful_copy = _add_simple_value(item, example, |
| 711 | anonymize_values) and successful_copy |
| 712 | if len(example.gold_sql_query.actions) == prev_len: |
| 713 | raise ValueError( |
| 714 | 'Gold query did not change length when adding simple value!') |
| 715 | continue |
| 716 | |
| 717 | # Like '%asd%' |
| 718 | if _is_keyword(item) and item.value.lower() in ('like',): |
| 719 | _add_simple_step(item, example) |
| 720 | continue |
| 721 | |
| 722 | if _is_literal(item): |
| 723 | prev_len = len(example.gold_sql_query.actions) |
no test coverage detected
searching dependent graphs…