Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry excluding="src/|tests/|examples/" kind="src" path=""/>
<buildpathentry kind="src" path="src"/>
<buildpathentry kind="src" path="tests"/>
<buildpathentry kind="src" path="examples"/>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
</buildpath>

View File

@@ -0,0 +1,240 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="1">
<profile kind="PDTToolsCodeFormatterProfile" name="PhOSCo PHP" version="1">
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.indent_switchstatements_compare_to_cases" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.join_lines_in_comments" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_between_type_declarations" value="1"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.wrap_before_binary_operator" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.lineSplit" value="120"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.align_type_members_on_columns" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_colon_in_assert" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.put_empty_statement_on_new_line" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.wrap_array_in_arguments" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_after_label" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_selector_in_method_invocation" value="2"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_method_declaration" value="0"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_assignment_operator" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_multiple_fields" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_conditional_expression" value="80"/>
<setting id="jp.sourceforge.pdt_tools.formatter.indent_empty_lines" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_double_arrow_operator" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_semicolon_in_for" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_binary_operator" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_colon_in_for" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.use_on_off_tags" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.brace_position_for_type_declaration" value="end_of_line"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="jp.sourceforge.pdt_tools.formatter.indentation.size" value="4"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_double_colon_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.brace_position_for_block" value="end_of_line"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.brace_position_for_array_initializer" value="end_of_line"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_colon_in_default" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_colon_in_for" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_before_imports" value="1"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.keep_else_statement_on_same_line" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_binary_expression" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_after_package" value="1"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_double_arrow_operator_with_filler" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_assignment" value="0"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.indent_switchstatements_compare_to_switch" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_question_in_conditional" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.tabulation.size" value="4"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_ellipsis" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_double_colon_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.compact_else_if" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.keep_then_statement_on_same_line" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_object_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_colon_in_assert" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.format_html_region" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.wrap_outer_expressions_when_nested" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_semicolon" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_colon_in_conditional" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_concat_expression" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_expressions_in_array_initializer" value="18"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.brace_position_for_block_in_case" value="end_of_line"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_unary_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_colon_in_conditional" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.align_php_region_with_open_tag" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.wrap_before_concat_operator" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_after_opening_paren_in_function_call" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.continuation_indentation" value="2"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_compact_if" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.brace_position_for_method_declaration" value="end_of_line"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_before_member_type" value="1"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_before_closing_paren_in_function_call" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_double_arrow_operator" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_concat_operator" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_parenthesized_expression_in_echo" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_before_field" value="0"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_unary_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_assignment_operator" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_after_opening_paren_in_function_call_in_arguments" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.brace_position_for_switch" value="end_of_line"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_postfix_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_prefix_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_before_method" value="0"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_brace_in_namespace_declaration" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_after_opening_brace_in_array_initializer_in_arguments" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.indent_statements_compare_to_body" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_concat_operator" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_object_operator" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.tabulation.char" value="space"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_colon_in_case" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_before_package" value="0"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_in_empty_method_body" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.indent_body_declarations_compare_to_namespace" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.join_wrapped_lines" value="true"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.keep_imple_if_on_one_line" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.brace_position_for_namespace_declaration" value="end_of_line"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.blank_lines_after_imports" value="1"/>
<setting id="jp.sourceforge.pdt_tools.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="jp.sourceforge.pdt_tools.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
<setting id="jp.sourceforge.pdt_tools.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
</profile>
</profiles>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PHP-SQL-Parser</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.dltk.core.scriptbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,3 @@
#Tue Apr 15 09:40:02 CEST 2014
eclipse.preferences.version=1
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false

View File

@@ -0,0 +1,6 @@
#Tue Apr 15 09:40:02 CEST 2014
eclipse.preferences.version=1
include_path=0;/PHP-SQL-Parser
org.eclipse.php.core.phpDoc=false
phpVersion=php5.3
useShortTags=true

View File

@@ -0,0 +1,9 @@
#Tue Apr 15 09:40:02 CEST 2014
DefaultProjectBasePath=/PHP-SQL-Parser
eclipse.preferences.version=1
org.eclipse.php.debug.core.use-project-settings=true
org.eclipse.php.debug.coredefaultPHP=PHP 5.3.2 (CGI)
org.eclipse.php.debug.coreoutput_encoding=UTF-8
org.eclipse.php.debug.corephp_debugger_id=org.eclipse.php.debug.core.zendDebugger
org.eclipse.php.debug.corestop_at_first_line_string=true
org.eclipse.php.debug.coretransfer_encoding=UTF-8

File diff suppressed because one or more lines are too long

27
vendor/greenlion/php-sql-parser/LICENSE vendored Normal file
View File

@@ -0,0 +1,27 @@
Copyright (c) 2014, Justin Swanhart <greenlion@gmail.com> and André Rothe <phosco@gmx.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,373 @@
<?php
/**
* OracleSQLTranslator.php
*
* A translator from MySQL dialect into Oracle dialect for Limesurvey
* (http://www.limesurvey.org/)
*
* Copyright (c) 2012, André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
namespace PHPSQLParser;
require_once dirname(__FILE__) . '/../vendor/autoload.php';
include_once $rootdir . '/classes/adodb/adodb.inc.php';
$_ENV['DEBUG'] = 1;
/**
* This class enhances the PHPSQLCreator to translate incoming
* parser output into another SQL dialect (here: Oracle SQL).
*
* @author arothe
*
*/
class OracleSQLTranslator extends PHPSQLCreator {
private $con; # this is the database connection from LimeSurvey
private $preventColumnRefs = array();
private $allTables = array();
const ASTERISK_ALIAS = "[#RePl#]";
public function __construct($con) {
parent::__construct();
$this->con = $con;
$this->initGlobalVariables();
}
private function initGlobalVariables() {
$this->preventColumnRefs = false;
$this->allTables = array();
}
public static function dbgprint($txt) {
if (isset($_ENV['DEBUG'])) {
print $txt;
}
}
public static function preprint($s, $return = false) {
$x = "<pre>";
$x .= print_r($s, 1);
$x .= "</pre>";
if ($return) {
return $x;
}
self::dbgprint($x . "<br/>\n");
}
protected function processAlias($parsed) {
if ($parsed === false) {
return "";
}
# we don't need an AS between expression and alias
$sql = " " . $parsed['name'];
return $sql;
}
protected function processDELETE($parsed) {
if (count($parsed['TABLES']) > 1) {
die("cannot translate delete statement into Oracle dialect, multiple tables are not allowed.");
}
return "DELETE";
}
public static function getColumnNameFor($column) {
if (strtolower($column) === 'uid') {
$column = "uid_";
}
// TODO: add more here, if necessary
return $column;
}
public static function getShortTableNameFor($table) {
if (strtolower($table) === 'surveys_languagesettings') {
$table = 'surveys_lngsettings';
}
// TODO: add more here, if necessary
return $table;
}
protected function processTable($parsed, $index) {
if ($parsed['expr_type'] !== 'table') {
return "";
}
$sql = $this->getShortTableNameFor($parsed['table']);
$alias = $this->processAlias($parsed['alias']);
$sql .= $alias;
if ($index !== 0) {
$sql = $this->processJoin($parsed['join_type']) . " " . $sql;
$sql .= $this->processRefType($parsed['ref_type']);
$sql .= $this->processRefClause($parsed['ref_clause']);
}
# store the table and its alias for later use
$last = array_pop($this->allTables);
$last['tables'][] = array('table' => $this->getShortTableNameFor($parsed['table']), 'alias' => trim($alias));
$this->allTables[] = $last;
return $sql;
}
protected function processFROM($parsed) {
$this->allTables[] = array('tables' => array(), 'alias' => '');
return parent::processFROM($parsed);
}
protected function processTableExpression($parsed, $index) {
if ($parsed['expr_type'] !== 'table_expression') {
return "";
}
$sql = substr($this->processFROM($parsed['sub_tree']), 5); // remove FROM keyword
$sql = "(" . $sql . ")";
$alias .= $this->processAlias($parsed['alias']);
$sql .= $alias;
# store the tables-expression-alias for later use
$last = array_pop($this->allTables);
$last['alias'] = trim($alias);
$this->allTables[] = $last;
if ($index !== 0) {
$sql = $this->processJoin($parsed['join_type']) . " " . $sql;
$sql .= $this->processRefType($parsed['ref_type']);
$sql .= $this->processRefClause($parsed['ref_clause']);
}
return $sql;
}
private function getTableNameFromExpression($expr) {
$pos = strpos($expr, ".");
if ($pos === false) {
$pos = -1;
}
return trim(substr($expr, 0, $pos + 1), ".");
}
private function getColumnNameFromExpression($expr) {
$pos = strpos($expr, ".");
if ($pos === false) {
$pos = -1;
}
return substr($expr, $pos + 1);
}
private function isCLOBColumnInDB($table, $column) {
$res = $this->con->GetOne(
"SELECT count(*) FROM user_lobs WHERE table_name='" . strtoupper($table) . "' AND column_name='"
. strtoupper($column) . "'");
return ($res >= 1);
}
protected function isCLOBColumn($table, $column) {
$tables = end($this->allTables);
if ($table === "") {
foreach ($tables['tables'] as $k => $v) {
if ($this->isCLOBColumn($v['table'], $column)) {
return true;
}
}
return false;
}
# check the aliases, $table cannot be empty
foreach ($tables['tables'] as $k => $v) {
if ((strtolower($v['alias']) === strtolower($table))
|| (strtolower($tables['alias']) === strtolower($table))) {
if ($this->isCLOBColumnInDB($v['table'], $column)) {
return true;
}
}
}
# it must be a valid table name
return $this->isCLOBColumnInDB($table, $column);
}
protected function processOrderByExpression($parsed) {
if ($parsed['expr_type'] !== 'expression') {
return "";
}
$table = $this->getTableNameFromExpression($parsed['base_expr']);
$col = $this->getColumnNameFromExpression($parsed['base_expr']);
$sql = ($table !== "" ? $table . "." : "") . $col;
# check, if the column is a CLOB
if ($this->isCLOBColumn($table, $col)) {
$sql = "cast(substr(" . $sql . ",1,200) as varchar2(200))";
}
return $sql . " " . $parsed['direction'];
}
protected function processColRef($parsed) {
if ($parsed['expr_type'] !== 'colref') {
return "";
}
$table = $this->getTableNameFromExpression($parsed['base_expr']);
$col = $this->getColumnNameFromexpression($parsed['base_expr']);
# we have to change the column name, if the column is uid
# we have to change the tablereference, if the tablename is too long
$col = $this->getColumnNameFor($col);
$table = $this->getShortTableNameFor($table);
# if we have * as colref, we cannot use other columns
# we have to add alias.* if we know all table aliases
if (($table === "") && ($col === "*")) {
array_pop($this->preventColumnRefs);
$this->preventColumnRefs[] = true;
return ASTERISK_ALIAS; # this is the position, we have to replace later
}
$alias = "";
if (isset($parsed['alias'])) {
$alias = $this->processAlias($parsed['alias']);
}
return (($table !== "") ? ($table . "." . $col) : $col) . $alias;
}
protected function processFunctionOnSelect($parsed) {
$old = end($this->preventColumnRefs);
$sql = $this->processFunction($parsed);
if ($old !== end($this->preventColumnRefs)) {
# prevents wrong handling of count(*)
array_pop($this->preventColumnRefs);
$this->preventColumnRefs[] = $old;
$sql = str_replace(ASTERISK_ALIAS, "*", $sql);
}
return $sql;
}
protected function processSELECT($parsed) {
$this->preventColumnRefs[] = false;
$sql = "";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->processColRef($v);
$sql .= $this->processSelectExpression($v);
$sql .= $this->processFunctionOnSelect($v);
$sql .= $this->processConstant($v);
if ($len == strlen($sql)) {
$this->stop('SELECT', $k, $v, 'expr_type');
}
$sql .= ",";
}
$sql = substr($sql, 0, -1);
return "SELECT " . $sql;
}
private function correctColRefStatement($sql) {
$alias = "";
$tables = end($this->allTables);
# should we correct the selection list?
if (array_pop($this->preventColumnRefs)) {
# do we have a table-expression alias?
if ($tables['alias'] !== "") {
$alias = $tables['alias'] . ".*";
} else {
foreach ($tables['tables'] as $k => $v) {
$alias .= ($v['alias'] === "" ? $v['table'] : $v['alias']) . ".*,";
}
$alias = substr($alias, 0, -1);
}
$sql = str_replace(ASTERISK_ALIAS, $alias, $sql);
}
return $sql;
}
protected function processSelectStatement($parsed) {
$sql = $this->processSELECT($parsed['SELECT']);
$from = $this->processFROM($parsed['FROM']);
# correct * references with tablealias.*
# this must be called after processFROM(), because we need the table information
$sql = $this->correctColRefStatement($sql) . " " . $from;
if (isset($parsed['WHERE'])) {
$sql .= " " . $this->processWHERE($parsed['WHERE']);
}
if (isset($parsed['GROUP'])) {
$sql .= " " . $this->processGROUP($parsed['GROUP']);
}
if (isset($parsed['ORDER'])) {
$sql .= " " . $this->processORDER($parsed['ORDER']);
}
# select finished, we remove its tables
# FIXME: we should add it to the previous tablelist with the
# global alias, if such one exists
array_pop($this->allTables);
return $sql;
}
public function create($parsed) {
$k = key($parsed);
switch ($k) {
case "USE":
# this statement is not an Oracle statement
$this->created = "";
break;
default:
$this->created = parent::create($parsed);
break;
}
return $this->created;
}
public function process($sql) {
self::dbgprint($sql . "<br/>");
$this->initGlobalVariables();
$parser = new PHPSQLParser($sql);
self::preprint($parser->parsed);
$sql = $this->create($parser->parsed);
self::dbgprint($sql . "<br/>");
return $sql;
}
}
//$translator = new OracleSQLTranslator(false);
//$translator->process("SELECT q.qid, question, gid FROM questions as q WHERE (select count(*) from answers as a where a.qid=q.qid and scale_id=0)=0 and sid=11929 AND type IN ('F', 'H', 'W', 'Z', '1') and q.parent_qid=0");
//$translator->process("SELECT *, (SELECT a from xyz WHERE b>1) haha, (SELECT *, b from zks,abc WHERE d=1) hoho FROM blubb d, blibb c WHERE d.col = c.col");
?>

View File

@@ -0,0 +1,159 @@
<?php
/**
* you cannot execute this script within Eclipse PHP
* because of the limited output buffer. Try to run it
* directly within a shell.
*/
namespace PHPSQLParser;
require_once dirname(__FILE__) . '/../vendor/autoload.php';
$sql = 'SELECT 1';
echo $sql . "\n";
$start = microtime(true);
$parser = new PHPSQLParser($sql, true);
$stop = microtime(true);
print_r($parser->parsed);
echo "parse time simplest query:" . ($stop - $start) . "\n";
/*You can use the constuctor for parsing. The parsed statement is stored at the ->parsed property.*/
$sql = 'REPLACE INTO table (a,b,c) VALUES (1,2,3)';
echo $sql . "\n";
$start = microtime(true);
$parser = new PHPSQLParser($sql);
$stop = microtime(true);
print_r($parser->parsed);
echo "parse time very somewhat simple statement:" . ($stop - $start) . "\n";
/* You can use the ->parse() method too. The parsed structure is returned, and
also available in the ->parsed property. */
$sql = 'SELECT a,b,c
from some_table an_alias
where d > 5;';
echo $sql . "\n";
print_r($parser->parse($sql, true));
$sql = 'SELECT a,b,c
from some_table an_alias
join `another` as `another table` using(id)
where d > 5;';
echo $sql . "\n";
$parser = new PHPSQLParser($sql, true);
print_r($parser->parsed);
$sql = 'SELECT a,b,c
from some_table an_alias
join (select d, max(f) max_f
from some_table
where id = 37
group by d) `subqry` on subqry.d = an_alias.d
where d > 5;';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = "(select `c2`, `c```, \"quoted \'string\' \\\" with `embedded`\\\"\\\" quotes\" as `an``alias` from table table)
UNION ALL (select `c2`, `c```, \"quoted \'string\' \\\" with `embedded`\\\"\\\" quotes\" as `an``alias` from table table)";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = "(select `c2`, `c```, \"quoted \'string\' \\\" with `embedded`\\\"\\\" quotes\" as `an``alias` from table table)
UNION (select `c2`, `c```, \"quoted \'string\' \\\" with `embedded`\\\"\\\" quotes\" as `an``alias` from table table)";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = "select `c2`, `c```, \"quoted \'string\' \\\" with `embedded`\\\"\\\" quotes\" as `an``alias` from table table";
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = "alter table xyz add key my_key(a,b,c), drop primay key";
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'INSERT INTO table (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), c=3;';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'UPDATE t1 SET col1 = col1 + 1, col2 = col1;';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND t2.id=t3.id;';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'delete low_priority partitioned_table.* from partitioned_table where partition_id = 1;';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = "UPDATE t1 SET col1 = col1 + 1, col2 = col1;";
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'insert into partitioned_table (partition_id, some_col) values (1,2);';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'delete from partitioned_table where partition_id = 1;';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'SELECT 1';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'SHOW TABLE STATUS';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'SHOW TABLES';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'select DISTINCT 1+2 c1, 1+ 2 as
`c2`, sum(c2),"Status" = CASE
WHEN quantity > 0 THEN \'in stock\'
ELSE \'out of stock\'
END
, t4.c1, (select c1+c2 from t1 inner_t1 limit 1) as subquery into @a1, @a2, @a3 from t1 the_t1 left outer join t2 using(c1,c2) join t3 as tX on tX.c1 = the_t1.c1 natural join t4 t4_x using(cX) where c1 = 1 and c2 in (1,2,3, "apple") and exists ( select 1 from some_other_table another_table where x > 1) and ("zebra" = "orange" or 1 = 1) group by 1, 2 having sum(c2) > 1 ORDER BY 2, c1 DESC LIMIT 0, 10 into outfile "/xyz" FOR UPDATE LOCK IN SHARE MODE';
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = "(select 1, 1, 1, 1 from dual dual1) union all (select 2, 2, 2, 2 from dual dual2) union all (select c1,c2,c3,sum(c4) from (select c1,c2,c3,c4 from a_table where c2 = 1) subquery group by 1,2,3) limit 10";
echo $sql . "\n";
$parser = new PHPSQLParser($sql);
print_r($parser->parsed);
$sql = 'select DISTINCT 1+2 c1, 1+ 2 as
`c2`, sum(c2),"Status" = CASE
WHEN quantity > 0 THEN "in stock"
ELSE "out of stock"
END
, t4.c1, (select c1+c2 from t1 table limit 1) as subquery into @a1, @a2, @a3 from `table` the_t1 left outer join t2 using(c1,c2) join
(select a, b, length(concat(a,b,c)) from ( select 1 a,2 b,3 c from some_Table ) table ) subquery_in_from join t3 as tX on tX.c1 = the_t1.c1 natural join t4 t4_x using(cX) where c1 = 1 and c2 in (1,2,3, "apple") and exists ( select 1 from some_other_table another_table where x > 1) and ("zebra" = "orange" or 1 = 1) group by 1, 2 having sum(c2) > 1 ORDER BY 2, c1 DESC LIMIT 0, 10 into outfile "/xyz" FOR UPDATE LOCK IN SHARE MODE
UNION ALL
SELECT NULL,NULL,NULL,NULL,NULL FROM DUAL LIMIT 1';
$start = microtime(true);
$parser = new PHPSQLParser($sql);
$stop = microtime(true);
echo "Parse time highly complex statement: " . ($stop - $start) . "\n";
?>

View File

@@ -0,0 +1,99 @@
<?php
/**
* Class Declaration Test.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Class Declaration Test.
*
* Checks the declaration of the class is correct.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: 1.5.1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PhOSCo_Sniffs_Classes_ClassDeclarationSniff implements PHP_CodeSniffer_Sniff {
/**
* The number of spaces code should be indented.
*
* @var int
*/
public $indent = 4;
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
return array(T_CLASS, T_INTERFACE,);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param integer $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$errorData = array($tokens[$stackPtr]['content']);
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
$error = 'Possible parse error: %s missing opening or closing brace';
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
return;
}
$curlyBrace = $tokens[$stackPtr]['scope_opener'];
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true);
$classLine = $tokens[$lastContent]['line'];
$braceLine = $tokens[$curlyBrace]['line'];
if ($braceLine !== $classLine) {
$error = 'Opening brace of a %s must be on the same line as the definition';
$phpcsFile->addError($error, $curlyBrace, 'OpenBraceNewLine', $errorData);
return;
}
if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) {
$prevContent = $tokens[($curlyBrace - 1)]['content'];
if ($prevContent === $phpcsFile->eolChar) {
$spaces = 0;
} else {
$blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar));
$spaces = strlen($blankSpace);
}
$expected = 1;
if ($spaces !== $expected) {
$error = 'Expected %s spaces before opening brace; %s found';
$data = array($expected, $spaces,);
$phpcsFile->addError($error, $curlyBrace, 'SpaceBeforeBrace', $data);
}
}
}//end process()
}//end class
?>

View File

@@ -0,0 +1,210 @@
<?php
/**
* Parses and verifies the doc comments for classes.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found';
throw new PHP_CodeSniffer_Exception($error);
}
if (class_exists('PhOSCo_Sniffs_Commenting_FileCommentSniff', true) === false) {
$error = 'Class PhOSCo_Sniffs_Commenting_FileCommentSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
/**
* Parses and verifies the doc comments for classes.
*
* Verifies that :
* <ul>
* <li>A doc comment exists.</li>
* <li>There is a blank newline after the short description.</li>
* <li>There is a blank newline between the long and short description.</li>
* <li>There is a blank newline between the long description and tags.</li>
* <li>Check the order of the tags.</li>
* <li>Check the indentation of each tag.</li>
* <li>Check required and optional tags and the format of their content.</li>
* </ul>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: 1.5.1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PhOSCo_Sniffs_Commenting_ClassCommentSniff extends PhOSCo_Sniffs_Commenting_FileCommentSniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
return array(T_CLASS, T_INTERFACE,);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
$this->currentFile = $phpcsFile;
$tokens = $phpcsFile->getTokens();
$type = strtolower($tokens[$stackPtr]['content']);
$errorData = array($type);
$find = array(T_ABSTRACT, T_WHITESPACE, T_FINAL,);
// Extract the class comment docblock.
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_COMMENT) {
$error = 'You must use "/**" style comments for a %s comment';
$phpcsFile->addError($error, $stackPtr, 'WrongStyle', $errorData);
return;
} else if ($commentEnd === false || $tokens[$commentEnd]['code'] !== T_DOC_COMMENT) {
$phpcsFile->addError('Missing %s doc comment', $stackPtr, 'Missing', $errorData);
return;
}
$commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1);
$commentNext = $phpcsFile->findPrevious(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false, $phpcsFile->eolChar);
// Distinguish file and class comment.
$prevClassToken = $phpcsFile->findPrevious(T_CLASS, ($stackPtr - 1));
if ($prevClassToken === false) {
// This is the first class token in this file, need extra checks.
$prevNonComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($commentStart - 1), null, true);
if ($prevNonComment !== false) {
$prevComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($prevNonComment - 1));
if ($prevComment === false) {
// There is only 1 doc comment between open tag and class token.
$newlineToken = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false,
$phpcsFile->eolChar);
if ($newlineToken !== false) {
$newlineToken = $phpcsFile->findNext(T_WHITESPACE, ($newlineToken + 1), $stackPtr, false,
$phpcsFile->eolChar);
if ($newlineToken !== false) {
// Blank line between the class and the doc block.
// The doc block is most likely a file comment.
$error = 'Missing %s doc comment';
$phpcsFile->addError($error, ($stackPtr + 1), 'Missing', $errorData);
return;
}
}//end if
}//end if
}//end if
}//end if
$comment = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1));
// Parse the class comment.docblock.
try {
$this->commentParser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsFile);
$this->commentParser->parse();
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
$line = ($e->getLineWithinComment() + $commentStart);
$phpcsFile->addError($e->getMessage(), $line, 'FailedParse');
return;
}
$comment = $this->commentParser->getComment();
if (is_null($comment) === true) {
$error = 'Doc comment is empty for %s';
$phpcsFile->addError($error, $commentStart, 'Empty', $errorData);
return;
}
// No extra newline before short description.
$short = $comment->getShortComment();
$newlineCount = 0;
$newlineSpan = strspn($short, $phpcsFile->eolChar);
if ($short !== '' && $newlineSpan > 0) {
$error = 'Extra newline(s) found before %s comment short description';
$phpcsFile->addError($error, ($commentStart + 1), 'SpacingBeforeShort', $errorData);
}
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
// Exactly one blank line between short and long description.
$long = $comment->getLongComment();
if (empty($long) === false) {
$between = $comment->getWhiteSpaceBetween();
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
if ($newlineBetween !== 2) {
$error = 'There must be exactly one blank line between descriptions in %s comments';
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1), 'SpacingAfterShort', $errorData);
}
$newlineCount += $newlineBetween;
}
// Exactly one blank line before tags.
$tags = $this->commentParser->getTagOrders();
if (count($tags) > 1) {
$newlineSpan = $comment->getNewlineAfter();
if ($newlineSpan !== 2) {
$error = 'There must be exactly one blank line before the tags in %s comments';
if ($long !== '') {
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
}
$phpcsFile->addError($error, ($commentStart + $newlineCount), 'SpacingBeforeTags', $errorData);
$short = rtrim($short, $phpcsFile->eolChar . ' ');
}
}
// Check each tag.
$this->processTags($commentStart, $commentEnd);
}//end process()
/**
* Process the version tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processVersion($errorPos) {
$version = $this->commentParser->getVersion();
if ($version !== null) {
$content = $version->getContent();
$matches = array();
if (empty($content) === true) {
$error = 'Content missing for @version tag in doc comment';
$this->currentFile->addError($error, $errorPos, 'EmptyVersion');
} else if ((strstr($content, 'Release:') === false)) {
$error = 'Invalid version "%s" in doc comment; consider "Release: <package_version>" instead';
$data = array($content);
$this->currentFile->addWarning($error, $errorPos, 'InvalidVersion', $data);
}
}
}//end processVersion()
}//end class
?>

View File

@@ -0,0 +1,653 @@
<?php
/**
* Parses and verifies the doc comments for files.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found');
}
/**
* Parses and verifies the doc comments for files.
*
* Verifies that :
* <ul>
* <li>A doc comment exists.</li>
* <li>There is a blank newline after the short description.</li>
* <li>There is a blank newline between the long and short description.</li>
* <li>There is a blank newline between the long description and tags.</li>
* <li>A PHP version is specified.</li>
* <li>Check the order of the tags.</li>
* <li>Check the indentation of each tag.</li>
* <li>Check required and optional tags and the format of their content.</li>
* </ul>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: 1.5.1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PhOSCo_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff {
/**
* The header comment parser for the current file.
*
* @var PHP_CodeSniffer_Comment_Parser_ClassCommentParser
*/
protected $commentParser = null;
/**
* The current PHP_CodeSniffer_File object we are processing.
*
* @var PHP_CodeSniffer_File
*/
protected $currentFile = null;
/**
* Tags in correct order and related info.
*
* @var array
*/
protected $tags = array(
'author' => array('required' => true, 'allow_multiple' => true,
'order_text' => 'follows @subpackage (if used) or @package',),
'copyright' => array('required' => false, 'allow_multiple' => true, 'order_text' => 'follows @author',),
'license' => array('required' => true, 'allow_multiple' => false,
'order_text' => 'follows @copyright (if used) or @author',),
'version' => array('required' => false, 'allow_multiple' => false, 'order_text' => 'follows @license',),
'see' => array('required' => false, 'allow_multiple' => true, 'order_text' => 'follows @link',),
'since' => array('required' => false, 'allow_multiple' => false,
'order_text' => 'follows @see (if used) or @link',),
'deprecated' => array('required' => false, 'allow_multiple' => false,
'order_text' => 'follows @since (if used) or @see (if used) or @link',),);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
return array(T_OPEN_TAG);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
$this->currentFile = $phpcsFile;
// We are only interested if this is the first open tag.
if ($stackPtr !== 0) {
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
return;
}
}
$tokens = $phpcsFile->getTokens();
// Find the next non whitespace token.
$commentStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
// Allow declare() statements at the top of the file.
if ($tokens[$commentStart]['code'] === T_DECLARE) {
$semicolon = $phpcsFile->findNext(T_SEMICOLON, ($commentStart + 1));
$commentStart = $phpcsFile->findNext(T_WHITESPACE, ($semicolon + 1), null, true);
}
// Ignore vim header.
if ($tokens[$commentStart]['code'] === T_COMMENT) {
if (strstr($tokens[$commentStart]['content'], 'vim:') !== false) {
$commentStart = $phpcsFile->findNext(T_WHITESPACE, ($commentStart + 1), null, true);
}
}
$errorToken = ($stackPtr + 1);
if (isset($tokens[$errorToken]) === false) {
$errorToken--;
}
if ($tokens[$commentStart]['code'] === T_CLOSE_TAG) {
// We are only interested if this is the first open tag.
return;
} else if ($tokens[$commentStart]['code'] === T_COMMENT) {
$error = 'You must use "/**" style comments for a file comment';
$phpcsFile->addError($error, $errorToken, 'WrongStyle');
return;
} else if ($commentStart === false || $tokens[$commentStart]['code'] !== T_DOC_COMMENT) {
$phpcsFile->addError('Missing file doc comment', $errorToken, 'Missing');
return;
} else {
// Extract the header comment docblock.
$commentEnd = $phpcsFile->findNext(T_DOC_COMMENT, ($commentStart + 1), null, true);
$commentEnd--;
// Check if there is only 1 doc comment between the
// open tag and class token.
$nextToken = array(T_ABSTRACT, T_CLASS, T_FUNCTION, T_DOC_COMMENT,);
$commentNext = $phpcsFile->findNext($nextToken, ($commentEnd + 1));
if ($commentNext !== false && $tokens[$commentNext]['code'] !== T_DOC_COMMENT) {
// Found a class token right after comment doc block.
$newlineToken = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), $commentNext, false,
$phpcsFile->eolChar);
if ($newlineToken !== false) {
$newlineToken = $phpcsFile->findNext(T_WHITESPACE, ($newlineToken + 1), $commentNext, false,
$phpcsFile->eolChar);
if ($newlineToken === false) {
// No blank line between the class token and the doc block.
// The doc block is most likely a class comment.
$error = 'Missing file doc comment';
$phpcsFile->addError($error, $errorToken, 'Missing');
return;
}
}
}//end if
$comment = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1));
// Parse the header comment docblock.
try {
$this->commentParser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsFile);
$this->commentParser->parse();
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
$line = ($e->getLineWithinComment() + $commentStart);
$phpcsFile->addError($e->getMessage(), $line, 'FailedParse');
return;
}
$comment = $this->commentParser->getComment();
if (is_null($comment) === true) {
$error = 'File doc comment is empty';
$phpcsFile->addError($error, $commentStart, 'Empty');
return;
}
// No extra newline before short description.
$short = $comment->getShortComment();
$newlineCount = 0;
$newlineSpan = strspn($short, $phpcsFile->eolChar);
if ($short !== '' && $newlineSpan > 0) {
$error = 'Extra newline(s) found before file comment short description';
$phpcsFile->addError($error, ($commentStart + 1), 'SpacingBefore');
}
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
// Exactly one blank line between short and long description.
$long = $comment->getLongComment();
if (empty($long) === false) {
$between = $comment->getWhiteSpaceBetween();
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
if ($newlineBetween !== 2) {
$error = 'There must be exactly one blank line between descriptions in file comment';
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1), 'DescriptionSpacing');
}
$newlineCount += $newlineBetween;
}
// Exactly one blank line before tags.
$tags = $this->commentParser->getTagOrders();
if (count($tags) > 1) {
$newlineSpan = $comment->getNewlineAfter();
if ($newlineSpan !== 2) {
$error = 'There must be exactly one blank line before the tags in file comment';
if ($long !== '') {
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
}
$phpcsFile->addError($error, ($commentStart + $newlineCount), 'SpacingBeforeTags');
$short = rtrim($short, $phpcsFile->eolChar . ' ');
}
}
// Check the PHP Version.
$this->processPHPVersion($commentStart, $commentEnd, $long);
// Check each tag.
$this->processTags($commentStart, $commentEnd);
}//end if
}//end process()
/**
* Check that the PHP version is specified.
*
* @param int $commentStart Position in the stack where the comment started.
* @param int $commentEnd Position in the stack where the comment ended.
* @param string $commentText The text of the function comment.
*
* @return void
*/
protected function processPHPVersion($commentStart, $commentEnd, $commentText) {
if (strstr(strtolower($commentText), 'php version') === false) {
$error = 'PHP version not specified';
$this->currentFile->addWarning($error, $commentEnd, 'MissingVersion');
}
}//end processPHPVersion()
/**
* Processes each required or optional tag.
*
* @param int $commentStart Position in the stack where the comment started.
* @param int $commentEnd Position in the stack where the comment ended.
*
* @return void
*/
protected function processTags($commentStart, $commentEnd) {
$docBlock = (get_class($this) === 'PhOSCo_Sniffs_Commenting_FileCommentSniff') ? 'file' : 'class';
$foundTags = $this->commentParser->getTagOrders();
$orderIndex = 0;
$indentation = array();
$longestTag = 0;
$errorPos = 0;
foreach ($this->tags as $tag => $info) {
// Required tag missing.
if ($info['required'] === true && in_array($tag, $foundTags) === false) {
$error = 'Missing @%s tag in %s comment';
$data = array($tag, $docBlock,);
$this->currentFile->addError($error, $commentEnd, 'MissingTag', $data);
continue;
}
// Get the line number for current tag.
$tagName = ucfirst($tag);
if ($info['allow_multiple'] === true) {
$tagName .= 's';
}
$getMethod = 'get' . $tagName;
$tagElement = $this->commentParser->$getMethod();
if (is_null($tagElement) === true || empty($tagElement) === true) {
continue;
}
$errorPos = $commentStart;
if (is_array($tagElement) === false) {
$errorPos = ($commentStart + $tagElement->getLine());
}
// Get the tag order.
$foundIndexes = array_keys($foundTags, $tag);
if (count($foundIndexes) > 1) {
// Multiple occurrence not allowed.
if ($info['allow_multiple'] === false) {
$error = 'Only 1 @%s tag is allowed in a %s comment';
$data = array($tag, $docBlock,);
$this->currentFile->addError($error, $errorPos, 'DuplicateTag', $data);
} else {
// Make sure same tags are grouped together.
$i = 0;
$count = $foundIndexes[0];
foreach ($foundIndexes as $index) {
if ($index !== $count) {
$errorPosIndex = ($errorPos + $tagElement[$i]->getLine());
$error = '@%s tags must be grouped together';
$data = array($tag);
$this->currentFile->addError($error, $errorPosIndex, 'TagsNotGrouped', $data);
}
$i++;
$count++;
}
}
}//end if
// Check tag order.
if ($foundIndexes[0] > $orderIndex) {
$orderIndex = $foundIndexes[0];
} else {
if (is_array($tagElement) === true && empty($tagElement) === false) {
$errorPos += $tagElement[0]->getLine();
}
$error = 'The @%s tag is in the wrong order; the tag %s';
$data = array($tag, $info['order_text'],);
$this->currentFile->addError($error, $errorPos, 'WrongTagOrder', $data);
}
// Store the indentation for checking.
$len = strlen($tag);
if ($len > $longestTag) {
$longestTag = $len;
}
if (is_array($tagElement) === true) {
foreach ($tagElement as $key => $element) {
$indentation[] = array('tag' => $tag, 'space' => $this->getIndentation($tag, $element),
'line' => $element->getLine(),);
}
} else {
$indentation[] = array('tag' => $tag, 'space' => $this->getIndentation($tag, $tagElement),);
}
$method = 'process' . $tagName;
if (method_exists($this, $method) === true) {
// Process each tag if a method is defined.
call_user_func(array($this, $method), $errorPos);
} else {
if (is_array($tagElement) === true) {
foreach ($tagElement as $key => $element) {
$element->process($this->currentFile, $commentStart, $docBlock);
}
} else {
$tagElement->process($this->currentFile, $commentStart, $docBlock);
}
}
}//end foreach
foreach ($indentation as $indentInfo) {
if ($indentInfo['space'] !== 0 && $indentInfo['space'] !== ($longestTag + 1)) {
$expected = (($longestTag - strlen($indentInfo['tag'])) + 1);
$space = ($indentInfo['space'] - strlen($indentInfo['tag']));
$error = '@%s tag comment indented incorrectly; expected %s spaces but found %s';
$data = array($indentInfo['tag'], $expected, $space,);
$getTagMethod = 'get' . ucfirst($indentInfo['tag']);
if ($this->tags[$indentInfo['tag']]['allow_multiple'] === true) {
$line = $indentInfo['line'];
} else {
$tagElem = $this->commentParser->$getTagMethod();
$line = $tagElem->getLine();
}
$this->currentFile->addError($error, ($commentStart + $line), 'TagIndent', $data);
}
}
}//end processTags()
/**
* Get the indentation information of each tag.
*
* @param string $tagName The name of the
* doc comment
* element.
* @param PHP_CodeSniffer_CommentParser_DocElement $tagElement The doc comment
* element.
*
* @return void
*/
protected function getIndentation($tagName, $tagElement) {
if ($tagElement instanceof PHP_CodeSniffer_CommentParser_SingleElement) {
if ($tagElement->getContent() !== '') {
return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforeContent(), ' '));
}
} else if ($tagElement instanceof PHP_CodeSniffer_CommentParser_PairElement) {
if ($tagElement->getValue() !== '') {
return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforeValue(), ' '));
}
}
return 0;
}//end getIndentation()
/**
* Process the category tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processCategory($errorPos) {
$category = $this->commentParser->getCategory();
if ($category !== null) {
$content = $category->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = ucfirst($firstBit) . '_';
foreach ($nameBits as $bit) {
$newName .= ucfirst($bit) . '_';
}
$error = 'Category name "%s" is not valid; consider "%s" instead';
$validName = trim($newName, '_');
$data = array($content, $validName,);
$this->currentFile->addError($error, $errorPos, 'InvalidCategory', $data);
}
} else {
$error = '@category tag must contain a name';
$this->currentFile->addError($error, $errorPos, 'EmptyCategory');
}
}
}//end processCategory()
/**
* Process the package tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processPackage($errorPos) {
$package = $this->commentParser->getPackage();
if ($package === null) {
return;
}
$content = $package->getContent();
if ($content === '') {
$error = '@package tag must contain a name';
$this->currentFile->addError($error, $errorPos, 'EmptyPackage');
return;
}
if (PHP_CodeSniffer::isUnderscoreName($content) === true) {
return;
}
$newContent = str_replace(' ', '_', $content);
$newContent = preg_replace('/[^A-Za-z_]/', '', $newContent);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit{0}) . substr($firstBit, 1) . '_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit{0}) . substr($bit, 1) . '_';
}
$error = 'Package name "%s" is not valid; consider "%s" instead';
$validName = trim($newName, '_');
$data = array($content, $validName,);
$this->currentFile->addError($error, $errorPos, 'InvalidPackage', $data);
}//end processPackage()
/**
* Process the subpackage tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processSubpackage($errorPos) {
$package = $this->commentParser->getSubpackage();
if ($package !== null) {
$content = $package->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit{0}) . substr($firstBit, 1) . '_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit{0}) . substr($bit, 1) . '_';
}
$error = 'Subpackage name "%s" is not valid; consider "%s" instead';
$validName = trim($newName, '_');
$data = array($content, $validName,);
$this->currentFile->addError($error, $errorPos, 'InvalidSubpackage', $data);
}
} else {
$error = '@subpackage tag must contain a name';
$this->currentFile->addError($error, $errorPos, 'EmptySubpackage');
}
}
}//end processSubpackage()
/**
* Process the author tag(s) that this header comment has.
*
* This function is different from other _process functions
* as $authors is an array of SingleElements, so we work out
* the errorPos for each element separately
*
* @param int $commentStart The position in the stack where
* the comment started.
*
* @return void
*/
protected function processAuthors($commentStart) {
$authors = $this->commentParser->getAuthors();
// Report missing return.
if (empty($authors) === false) {
foreach ($authors as $author) {
$errorPos = ($commentStart + $author->getLine());
$content = $author->getContent();
if ($content !== '') {
$local = '\da-zA-Z-_+';
// Dot character cannot be the first or last character
// in the local-part.
$localMiddle = $local . '.\w';
if (preg_match(
'/^([^<]*)\s+<([' . $local . ']([' . $localMiddle . ']*[' . $local
. '])*@[\da-zA-Z][-.\w]*[\da-zA-Z]\.[a-zA-Z]{2,7})>$/', $content) === 0) {
$error = 'Content of the @author tag must be in the form "Display Name <username@example.com>"';
$this->currentFile->addError($error, $errorPos, 'InvalidAuthors');
}
} else {
$error = 'Content missing for @author tag in %s comment';
$docBlock = (get_class($this) === 'PhOSCo_Sniffs_Commenting_FileCommentSniff') ? 'file' : 'class';
$data = array($docBlock);
$this->currentFile->addError($error, $errorPos, 'EmptyAuthors', $data);
}
}
}
}//end processAuthors()
/**
* Process the copyright tags.
*
* @param int $commentStart The position in the stack where
* the comment started.
*
* @return void
*/
protected function processCopyrights($commentStart) {
$copyrights = $this->commentParser->getCopyrights();
foreach ($copyrights as $copyright) {
$errorPos = ($commentStart + $copyright->getLine());
$content = $copyright->getContent();
if ($content !== '') {
$matches = array();
if (preg_match('/^([0-9]{4})((.{1})([0-9]{4}))? (.+)$/', $content, $matches) !== 0) {
// Check earliest-latest year order.
if ($matches[3] !== '') {
if ($matches[3] !== '-') {
$error = 'A hyphen must be used between the earliest and latest year';
$this->currentFile->addError($error, $errorPos, 'CopyrightHyphen');
}
if ($matches[4] !== '' && $matches[4] < $matches[1]) {
$error = "Invalid year span \"$matches[1]$matches[3]$matches[4]\" found; consider \"$matches[4]-$matches[1]\" instead";
$this->currentFile->addWarning($error, $errorPos, 'InvalidCopyright');
}
}
} else {
$error = '@copyright tag must contain a year and the name of the copyright holder';
$this->currentFile->addError($error, $errorPos, 'EmptyCopyright');
}
} else {
$error = '@copyright tag must contain a year and the name of the copyright holder';
$this->currentFile->addError($error, $errorPos, 'EmptyCopyright');
}//end if
}//end if
}//end processCopyrights()
/**
* Process the license tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processLicense($errorPos) {
$license = $this->commentParser->getLicense();
if ($license !== null) {
$value = $license->getValue();
$comment = $license->getComment();
if ($value === '' || $comment === '') {
$error = '@license tag must contain a URL and a license name';
$this->currentFile->addError($error, $errorPos, 'EmptyLicense');
}
}
}//end processLicense()
/**
* Process the version tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processVersion($errorPos) {
$version = $this->commentParser->getVersion();
if ($version !== null) {
$content = $version->getContent();
$matches = array();
if (empty($content) === true) {
$error = 'Content missing for @version tag in file comment';
$this->currentFile->addError($error, $errorPos, 'EmptyVersion');
} else if (strstr($content, 'CVS:') === false && strstr($content, 'SVN:') === false
&& strstr($content, 'GIT:') === false && strstr($content, 'HG:') === false) {
$error = 'Invalid version "%s" in file comment; consider "CVS: <cvs_id>" or "SVN: <svn_id>" or "GIT: <git_id>" or "HG: <hg_id>" instead';
$data = array($content);
$this->currentFile->addWarning($error, $errorPos, 'InvalidVersion', $data);
}
}
}//end processVersion()
}//end class
?>

View File

@@ -0,0 +1,189 @@
<?php
/**
* PEAR_Sniffs_ControlStructures_MultiLineConditionSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* PEAR_Sniffs_ControlStructures_MultiLineConditionSniff.
*
* Ensure multi-line IF conditions are defined correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: 1.5.1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PhOSCo_Sniffs_ControlStructures_MultiLineConditionSniff implements PHP_CodeSniffer_Sniff
{
/**
* The number of spaces code should be indented.
*
* @var int
*/
public $indent = 4;
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_IF,
T_ELSEIF,
);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
// We need to work out how far indented the if statement
// itself is, so we can work out how far to indent conditions.
$statementIndent = 0;
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
if ($i >= 0 && $tokens[$i]['code'] === T_WHITESPACE) {
$statementIndent = strlen($tokens[$i]['content']);
}
// Each line between the parenthesis should be indented 4 spaces
// and start with an operator, unless the line is inside a
// function call, in which case it is ignored.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
$lastLine = $tokens[$openBracket]['line'];
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
if ($tokens[$i]['line'] !== $lastLine) {
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
$next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
if ($next === $closeBracket) {
// Closing bracket is not on the same line as a condition.
$error = 'Closing parenthesis of a multi-line IF statement must be on the same line as the last condition';
$phpcsFile->addError($error, $i, 'CloseBracketNewLine');
$expectedIndent = ($statementIndent + $this->indent);
} else {
// Closing brace needs to be indented to the same level
// as the function.
$expectedIndent = $statementIndent + $this->indent;
}
} else {
$expectedIndent = ($statementIndent + $this->indent);
}
// We changed lines, so this should be a whitespace indent token.
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$foundIndent = 0;
} else {
$foundIndent = strlen($tokens[$i]['content']);
}
if ($expectedIndent !== $foundIndent) {
$error = 'Multi-line IF statement not indented correctly; expected %s spaces but found %s';
$data = array(
$expectedIndent,
$foundIndent,
);
$phpcsFile->addError($error, $i, 'Alignment', $data);
}
if ($tokens[$i]['line'] !== $tokens[$closeBracket]['line']) {
$next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
if (in_array($tokens[$next]['code'], PHP_CodeSniffer_Tokens::$booleanOperators) === false) {
$error = 'Each line in a multi-line IF statement must begin with a boolean operator';
$phpcsFile->addError($error, $i, 'StartWithBoolean');
}
}
$lastLine = $tokens[$i]['line'];
}//end if
if ($tokens[$i]['code'] === T_STRING) {
$next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true);
if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
// This is a function call, so skip to the end as they
// have their own indentation rules.
$i = $tokens[$next]['parenthesis_closer'];
$lastLine = $tokens[$i]['line'];
continue;
}
}
}//end for
// From here on, we are checking the spacing of the opening and closing
// braces. If this IF statement does not use braces, we end here.
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
// The opening brace needs to be one space away from the closing parenthesis.
if ($tokens[($closeBracket + 1)]['code'] !== T_WHITESPACE) {
$length = 0;
} else if ($tokens[($closeBracket + 1)]['content'] === $phpcsFile->eolChar) {
$length = -1;
} else {
$length = strlen($tokens[($closeBracket + 1)]['content']);
}
if ($length !== 1) {
$data = array($length);
$code = 'SpaceBeforeOpenBrace';
$error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement; found ';
if ($length === -1) {
$error .= 'newline';
$code = 'NewlineBeforeOpenBrace';
} else {
$error .= '%s spaces';
}
$phpcsFile->addError($error, ($closeBracket + 1), $code, $data);
}
// And just in case they do something funny before the brace...
$next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
if ($next !== false
&& $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET
&& $tokens[$next]['code'] !== T_COLON
) {
$error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement';
$phpcsFile->addError($error, $next, 'NoSpaceBeforeOpenBrace');
}
}//end process()
}//end class
?>

View File

@@ -0,0 +1,296 @@
<?php
/**
* PEAR_Sniffs_Functions_FunctionDeclarationSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* PEAR_Sniffs_Functions_FunctionDeclarationSniff.
*
* Ensure single and multi-line function declarations are defined correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: 1.5.1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PhOSCo_Sniffs_Functions_FunctionDeclarationSniff implements PHP_CodeSniffer_Sniff {
/**
* The number of spaces code should be indented.
*
* @var int
*/
public $indent = 4;
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
return array(T_FUNCTION, T_CLOSURE,);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$spaces = 0;
if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
$spaces = strlen($tokens[($stackPtr + 1)]['content']);
}
if ($spaces !== 1) {
$error = 'Expected 1 space after FUNCTION keyword; %s found';
$data = array($spaces);
$phpcsFile->addError($error, $stackPtr, 'SpaceAfterFunction', $data);
}
// Must be one space before and after USE keyword for closures.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
$use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
if ($use !== false) {
if ($tokens[($use + 1)]['code'] !== T_WHITESPACE) {
$length = 0;
} else if ($tokens[($use + 1)]['content'] === "\t") {
$length = '\t';
} else {
$length = strlen($tokens[($use + 1)]['content']);
}
if ($length !== 1) {
$error = 'Expected 1 space after USE keyword; found %s';
$data = array($length);
$phpcsFile->addError($error, $use, 'SpaceAfterUse', $data);
}
if ($tokens[($use - 1)]['code'] !== T_WHITESPACE) {
$length = 0;
} else if ($tokens[($use - 1)]['content'] === "\t") {
$length = '\t';
} else {
$length = strlen($tokens[($use - 1)]['content']);
}
if ($length !== 1) {
$error = 'Expected 1 space before USE keyword; found %s';
$data = array($length);
$phpcsFile->addError($error, $use, 'SpaceBeforeUse', $data);
}
}//end if
}//end if
// Check if this is a single line or multi-line declaration.
$singleLine = true;
if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
// Closures may use the USE keyword and so be multi-line in this way.
if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
if ($use !== false) {
// If the opening and closing parenthesis of the use statement
// are also on the same line, this is a single line declaration.
$open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
$close = $tokens[$open]['parenthesis_closer'];
if ($tokens[$open]['line'] !== $tokens[$close]['line']) {
$singleLine = false;
}
}
}
} else {
$singleLine = false;
}
if ($singleLine === true) {
$this->processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
} else {
$this->processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
}
}//end process()
/**
* Processes single-line declarations.
*
* Just uses the Generic BSD-Allman brace sniff.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processSingleLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) {
if (class_exists('Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff', true) === false) {
throw new PHP_CodeSniffer_Exception(
'Class Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff not found');
}
$sniff = new Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff();
$sniff->process($phpcsFile, $stackPtr);
}//end processSingleLineDeclaration()
/**
* Processes mutli-line declarations.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) {
// We need to work out how far indented the function
// declaration itself is, so we can work out how far to
// indent parameters.
$functionIndent = 0;
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
if ($tokens[$i]['code'] === T_WHITESPACE) {
$functionIndent = strlen($tokens[$i]['content']);
}
// The closing parenthesis must be on a new line, even
// when checking abstract function definitions.
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBracket - 1), null, true);
if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']) {
if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']) {
$error = 'The closing parenthesis of a multi-line function declaration must be on a new line';
$phpcsFile->addError($error, $closeBracket, 'CloseBracketLine');
}
}
// If this is a closure and is using a USE statement, the closing
// parenthesis we need to look at from now on is the closing parenthesis
// of the USE statement.
if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
$use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']);
if ($use !== false) {
$open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
$closeBracket = $tokens[$open]['parenthesis_closer'];
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBracket - 1), null, true);
if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line']) {
if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']) {
$error = 'The closing parenthesis of a multi-line use declaration must be on a new line';
$phpcsFile->addError($error, $closeBracket, 'CloseBracketLine');
}
}
}//end if
}//end if
// Each line between the parenthesis should be indented 4 spaces.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$lastLine = $tokens[$openBracket]['line'];
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
if ($tokens[$i]['line'] !== $lastLine) {
if ($i === $tokens[$stackPtr]['parenthesis_closer']
|| ($tokens[$i]['code'] === T_WHITESPACE
&& (($i + 1) === $closeBracket || ($i + 1) === $tokens[$stackPtr]['parenthesis_closer']))) {
// Closing braces need to be indented to the same level
// as the function.
$expectedIndent = $functionIndent;
} else {
$expectedIndent = ($functionIndent + $this->indent);
}
// We changed lines, so this should be a whitespace indent token.
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$foundIndent = 0;
} else {
$foundIndent = strlen($tokens[$i]['content']);
}
if ($expectedIndent !== $foundIndent) {
$error = 'Multi-line function declaration not indented correctly; expected %s spaces but found %s';
$data = array($expectedIndent, $foundIndent,);
$phpcsFile->addError($error, $i, 'Indent', $data);
}
$lastLine = $tokens[$i]['line'];
}//end if
if ($tokens[$i]['code'] === T_ARRAY) {
// Skip arrays as they have their own indentation rules.
$i = $tokens[$i]['parenthesis_closer'];
$lastLine = $tokens[$i]['line'];
continue;
}
}//end for
if (isset($tokens[$stackPtr]['scope_opener']) === true) {
// The openning brace needs to be one space away
// from the closing parenthesis.
$next = $tokens[($closeBracket + 1)];
if ($next['code'] !== T_WHITESPACE) {
$length = 0;
} else if ($next['content'] === $phpcsFile->eolChar) {
$length = -1;
} else {
$length = strlen($next['content']);
}
if ($length !== 1) {
$data = array($length);
$code = 'SpaceBeforeOpenBrace';
$error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found ';
if ($length === -1) {
$error .= 'newline';
$code = 'NewlineBeforeOpenBrace';
} else {
$error .= '%s spaces';
}
$phpcsFile->addError($error, ($closeBracket + 1), $code, $data);
return;
}
// And just in case they do something funny before the brace...
$next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
$error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration';
$phpcsFile->addError($error, $next, 'NoSpaceBeforeOpenBrace');
}
}//end if
}//end processMultiLineDeclaration()
}//end class
?>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruleset name="PhOSCo">
<description>A custom coding standard for PHP-SQL-Parser.</description>
<rule ref="Generic.Files.EndFileNewline" />
<rule ref="PEAR">
<exclude name="Generic.Files.LineLength" />
<exclude name="PEAR.Classes.ClassDeclaration" />
<exclude name="PEAR.Functions.FunctionDeclaration" />
<exclude name="PEAR.Commenting.FileComment" />
<exclude name="PEAR.Commenting.ClassComment" />
<exclude name="PEAR.ControlStructures.MultiLineCondition" />
</rule>
<!-- Lines can be 120 chars long, but never show errors -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120" />
<property name="absoluteLineLimit" value="0" />
</properties>
</rule>
</ruleset>

View File

@@ -0,0 +1,29 @@
Install PHP_CodeSniffer:
========================
pear install PHP_CodeSniffer
Check the code with:
====================
phpcs --standard=/path/to/the/PhOSCo/folder /path/to/the/src/folder >/tmp/code-errors.txt
vi /tmp/code-errors.txt
Or integrate it as external tool into Eclipse:
==============================================
* Open External tool configuration window
* set the name to "CodeSniffer"
* set /usr/bin/phpcs as Location
* set --standard="${project_loc}/libs/codesniffer/PhOSCo" "${selected_resource_loc}" as Arguments
* on the Build tab set the parameters as needed
* click "Apply" and "Close"
* select one of the folders or *.php files
* execute the external tool "CodeSniffer"
* review the errors within the console output within Eclipse
correct all listed errors (...I hate it)!
=========================================

2
vendor/greenlion/php-sql-parser/runtest.sh vendored Executable file
View File

@@ -0,0 +1,2 @@
clear
./vendor/phpunit/phpunit/phpunit

View File

@@ -0,0 +1,57 @@
<?php
/**
* @author mfris
*
*/
namespace PHPSQLParser;
/**
*
* @author mfris
* @package PHPSQLParser
*/
final class Options
{
/**
* @var array
*/
private $options;
/**
* @const string
*/
const CONSISTENT_SUB_TREES = 'consistent_sub_trees';
/**
* @const string
*/
const ANSI_QUOTES = 'ansi_quotes';
/**
* Options constructor.
*
* @param array $options
*/
public function __construct(array $options)
{
$this->options = $options;
}
/**
* @return bool
*/
public function getConsistentSubtrees()
{
return (isset($this->options[self::CONSISTENT_SUB_TREES]) && $this->options[self::CONSISTENT_SUB_TREES]);
}
/**
* @return bool
*/
public function getANSIQuotes()
{
return (isset($this->options[self::ANSI_QUOTES]) && $this->options[self::ANSI_QUOTES]);
}
}

View File

@@ -0,0 +1,142 @@
<?php
/**
* PHPSQLCreator.php
*
* A creator, which generates SQL from the output of PHPSQLParser.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser;
use PHPSQLParser\exceptions\UnsupportedFeatureException;
use PHPSQLParser\builders\SelectStatementBuilder;
use PHPSQLParser\builders\DeleteStatementBuilder;
use PHPSQLParser\builders\TruncateStatementBuilder;
use PHPSQLParser\builders\UpdateStatementBuilder;
use PHPSQLParser\builders\InsertStatementBuilder;
use PHPSQLParser\builders\CreateStatementBuilder;
use PHPSQLParser\builders\DropStatementBuilder;
use PHPSQLParser\builders\RenameStatementBuilder;
use PHPSQLParser\builders\ReplaceStatementBuilder;
use PHPSQLParser\builders\ShowStatementBuilder;
use PHPSQLParser\builders\BracketStatementBuilder;
use PHPSQLParser\builders\UnionStatementBuilder;
use PHPSQLParser\builders\UnionAllStatementBuilder;
use PHPSQLParser\builders\AlterStatementBuilder;
/**
* This class generates SQL from the output of the PHPSQLParser.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class PHPSQLCreator {
public function __construct($parsed = false) {
if ($parsed) {
$this->create($parsed);
}
}
public function create($parsed) {
$k = key($parsed);
switch ($k) {
case 'UNION':
$builder = new UnionStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'UNION ALL':
$builder = new UnionAllStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'SELECT':
$builder = new SelectStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'INSERT':
$builder = new InsertStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'REPLACE':
$builder = new ReplaceStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'DELETE':
$builder = new DeleteStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'TRUNCATE':
$builder = new TruncateStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'UPDATE':
$builder = new UpdateStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'RENAME':
$builder = new RenameStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'SHOW':
$builder = new ShowStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'CREATE':
$builder = new CreateStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'BRACKET':
$builder = new BracketStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'DROP':
$builder = new DropStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'ALTER':
$builder = new AlterStatementBuilder();
$this->created = $builder->build($parsed);
break;
default:
throw new UnsupportedFeatureException($k);
break;
}
return $this->created;
}
}
?>

View File

@@ -0,0 +1,139 @@
<?php
/**
* PHPSQLParser.php
*
* A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*/
namespace PHPSQLParser;
use PHPSQLParser\positions\PositionCalculator;
use PHPSQLParser\processors\DefaultProcessor;
use PHPSQLParser\utils\PHPSQLParserConstants;
/**
* This class implements the parser functionality.
*
* @author Justin Swanhart <greenlion@gmail.com>
* @author André Rothe <arothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*/
class PHPSQLParser {
public $parsed;
/**
* @var Options
*/
private $options;
/**
* Constructor. It simply calls the parse() function.
* Use the public variable $parsed to get the output.
*
* @param String|bool $sql The SQL statement.
* @param bool $calcPositions True, if the output should contain [position], false otherwise.
* @param array $options
*/
public function __construct($sql = false, $calcPositions = false, array $options = array()) {
$this->options = new Options($options);
if ($sql) {
$this->parse($sql, $calcPositions);
}
}
/**
* It parses the given SQL statement and generates a detailled
* output array for every part of the statement. The method can
* also generate [position] fields within the output, which hold
* the character position for every statement part. The calculation
* of the positions needs some time, if you don't need positions in
* your application, set the parameter to false.
*
* @param String $sql The SQL statement.
* @param boolean $calcPositions True, if the output should contain [position], false otherwise.
*
* @return array An associative array with all meta information about the SQL statement.
*/
public function parse($sql, $calcPositions = false) {
$processor = new DefaultProcessor($this->options);
$queries = $processor->process($sql);
// calc the positions of some important tokens
if ($calcPositions) {
$calculator = new PositionCalculator();
$queries = $calculator->setPositionsWithinSQL($sql, $queries);
}
// store the parsed queries
$this->parsed = $queries;
return $this->parsed;
}
/**
* Add a custom function to the parser. no return value
*
* @param String $token The name of the function to add
*
* @return null
*/
public function addCustomFunction($token) {
PHPSQLParserConstants::getInstance()->addCustomFunction($token);
}
/**
* Remove a custom function from the parser. no return value
*
* @param String $token The name of the function to remove
*
* @return null
*/
public function removeCustomFunction($token) {
PHPSQLParserConstants::getInstance()->removeCustomFunction($token);
}
/**
* Returns the list of custom functions
*
* @return array Returns an array of all custom functions
*/
public function getCustomFunctions() {
return PHPSQLParserConstants::getInstance()->getCustomFunctions();
}
}
?>

View File

@@ -0,0 +1,70 @@
<?php
/**
* AliasBuilder.php
*
* Builds aliases.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for aliases.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class AliasBuilder implements Builder {
public function hasAlias($parsed) {
return isset($parsed['alias']);
}
public function build(array $parsed) {
if (!isset($parsed['alias']) || $parsed['alias'] === false) {
return "";
}
$sql = "";
if ($parsed['alias']['as']) {
$sql .= " AS";
}
$sql .= " " . $parsed['alias']['name'];
return $sql;
}
}
?>

View File

@@ -0,0 +1,63 @@
<?php
/**
* AliasReferenceBuilder.php
*
* Builds Alias references.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for alias references.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class AliasReferenceBuilder implements Builder {
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::ALIAS) {
return "";
}
$sql = $parsed['base_expr'];
return $sql;
}
}
?>

View File

@@ -0,0 +1,35 @@
<?php
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the [DELETE] part. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class AlterBuilder implements Builder
{
public function build(array $parsed)
{
$sql = '';
foreach ($parsed as $term) {
if ($term === ' ') {
continue;
}
if (substr($term, 0, 1) === '(' ||
strpos($term, "\n") !== false) {
$sql = rtrim($sql);
}
$sql .= $term . ' ';
}
$sql = rtrim($sql);
return $sql;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace PHPSQLParser\builders;
class AlterStatementBuilder implements Builder
{
protected function buildSubTree($parsed) {
$builder = new SubTreeBuilder();
return $builder->build($parsed);
}
private function buildAlter($parsed)
{
$builder = new AlterBuilder();
return $builder->build($parsed);
}
public function build(array $parsed)
{
$alter = $parsed['ALTER'];
$sql = $this->buildAlter($alter);
return $sql;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* BracketStatementBuilder.php
*
* Builds the parentheses around a statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the builder for the parentheses around a statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class BracketStatementBuilder implements Builder {
protected function buildSelectBracketExpression($parsed) {
$builder = new SelectBracketExpressionBuilder();
return $builder->build($parsed, " ");
}
protected function buildSelectStatement($parsed) {
$builder = new SelectStatementBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = "";
foreach ($parsed['BRACKET'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildSelectBracketExpression($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('BRACKET', $k, $v, 'expr_type');
}
}
return trim($sql . " " . trim($this->buildSelectStatement($parsed)));
}
}
?>

View File

@@ -0,0 +1,63 @@
<?php
/**
* Builder.php
*
* Interface declaration for all builder classes.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* A builder can create a part of an SQL statement. The necessary information
* are provided by the function parameter as array. This array is a subtree
* of the PHPSQLParser output.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*/
interface Builder {
/**
* Builds a part of an SQL statement.
*
* @param array $parsed a subtree of the PHPSQLParser output array
*
* @return A string, which contains a part of an SQL statement.
*/
public function build(array $parsed);
}
?>

View File

@@ -0,0 +1,91 @@
<?php
/**
* CharacterSetBuilder.php
*
* Builds the CHARACTER SET part of a CREATE TABLE statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the CHARACTER SET statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CharacterSetBuilder implements Builder {
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::CHARSET) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildOperator($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE options CHARACTER SET subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,85 @@
<?php
/**
* CheckBuilder.php
*
* Builds the CHECK statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the CHECK statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CheckBuilder implements Builder {
protected function buildSelectBracketExpression($parsed) {
$builder = new SelectBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::CHECK) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildSelectBracketExpression($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE check subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,91 @@
<?php
/**
* CollationBuilder.php
*
* Builds the collation expression part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the collation statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CollationBuilder implements Builder {
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLLATE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE options collation subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,85 @@
<?php
/**
* ColumnDefinitionBuilder.php
*
* Builds the column definition statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the columndefinition statement part
* of CREATE TABLE. You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ColumnDefinitionBuilder implements Builder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildColumnType($parsed) {
$builder = new ColumnTypeBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLDEF) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildColumnType($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,86 @@
<?php
/**
* ColumnListBuilder.php
*
* Builds column-list parts of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for column-list parts of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ColumnListBuilder implements Builder {
protected function buildIndexColumn($parsed) {
$builder = new IndexColumnBuilder();
return $builder->build($parsed);
}
protected function buildColumnReference($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
public function build(array $parsed, $delim = ', ') {
if ($parsed['expr_type'] !== ExpressionType::COLUMN_LIST) {
return '';
}
$sql = '';
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildIndexColumn($v);
$sql .= $this->buildColumnReference($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE column-list subtree', $k, $v, 'expr_type');
}
$sql .= $delim;
}
return '(' . substr($sql, 0, -strlen($delim)) . ')';
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/**
* ColumnReferenceBuilder.php
*
* Builds Column references.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for column references.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ColumnReferenceBuilder implements Builder {
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLREF) {
return "";
}
$sql = $parsed['base_expr'];
$sql .= $this->buildAlias($parsed);
return $sql;
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/**
* ColumnTypeExpressionBuilder.php
*
* Builds the bracket expressions within a column type.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for bracket expressions within a column type.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ColumnTypeBracketExpressionBuilder implements Builder {
protected function buildSubTree($parsed, $delim) {
$builder = new SubTreeBuilder();
return $builder->build($parsed, $delim);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) {
return "";
}
$sql = $this->buildSubTree($parsed, ",");
$sql = "(" . $sql . ")";
return $sql;
}
}
?>

View File

@@ -0,0 +1,107 @@
<?php
/**
* ColumnTypeBuilder.php
*
* Builds the column type statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the column type statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ColumnTypeBuilder implements Builder {
protected function buildColumnTypeBracketExpression($parsed) {
$builder = new ColumnTypeBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildDataType($parsed) {
$builder = new DataTypeBuilder();
return $builder->build($parsed);
}
protected function buildDefaultValue($parsed) {
$builder = new DefaultValueBuilder();
return $builder->build($parsed);
}
protected function buildCharacterSet($parsed) {
if ($parsed['expr_type'] !== ExpressionType::CHARSET) {
return "";
}
return $parsed['base_expr'];
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLUMN_TYPE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildDataType($v);
$sql .= $this->buildColumnTypeBracketExpression($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildDefaultValue($v);
$sql .= $this->buildCharacterSet($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE column-type subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/**
* ConstantBuilder.php
*
* Builds constant (String, Integer, etc.) parts.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for constants.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ConstantBuilder implements Builder {
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::CONSTANT) {
return "";
}
$sql = $parsed['base_expr'];
$sql .= $this->buildAlias($parsed);
return $sql;
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/**
* ConstraintBuilder.php
*
* Builds the constraint statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the constraint statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ConstraintBuilder implements Builder {
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::CONSTRAINT) {
return '';
}
$sql = $parsed['sub_tree'] === false ? '' : $this->buildConstant($parsed['sub_tree']);
return "CONSTRAINT" . (empty($sql) ? '' : (' ' . $sql));
}
}
?>

View File

@@ -0,0 +1,87 @@
<?php
/**
* CreateBuilder.php
*
* Builds the CREATE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the [CREATE] part. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateBuilder implements Builder {
protected function buildCreateTable($parsed) {
$builder = new CreateTableBuilder();
return $builder->build($parsed);
}
protected function buildCreateIndex($parsed) {
$builder = new CreateIndexBuilder();
return $builder->build($parsed);
}
protected function buildSubTree($parsed) {
$builder = new SubTreeBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$create = $parsed['CREATE'];
$sql = $this->buildSubTree($create);
if (($create['expr_type'] === ExpressionType::TABLE)
|| ($create['expr_type'] === ExpressionType::TEMPORARY_TABLE)) {
$sql .= ' ' . $this->buildCreateTable($parsed['TABLE']);
}
if ($create['expr_type'] === ExpressionType::INDEX) {
$sql .= ' ' . $this->buildCreateIndex($parsed['INDEX']);
}
// TODO: add more expr_types here (like VIEW), if available in parser output
return "CREATE " . $sql;
}
}
?>

View File

@@ -0,0 +1,80 @@
<?php
/**
* CreateIndex.php
*
* Builds the CREATE INDEX statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the CREATE INDEX statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateIndexBuilder implements Builder {
protected function buildIndexType($parsed) {
$builder = new CreateIndexTypeBuilder();
return $builder->build($parsed);
}
protected function buildIndexTable($parsed) {
$builder = new CreateIndexTableBuilder();
return $builder->build($parsed);
}
protected function buildIndexOptions($parsed) {
$builder = new CreateIndexOptionsBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = $parsed['name'];
$sql .= ' ' . $this->buildIndexType($parsed);
$sql = trim($sql);
$sql .= ' ' . $this->buildIndexTable($parsed);
$sql = trim($sql);
$sql .= $this->buildIndexOptions($parsed);
return trim($sql);
}
}
?>

View File

@@ -0,0 +1,109 @@
<?php
/**
* CreateIndexOptionsBuilder.php
*
* Builds index options part of a CREATE INDEX statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the builder for the index options of a CREATE INDEX
* statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateIndexOptionsBuilder implements Builder {
protected function buildIndexParser($parsed) {
$builder = new IndexParserBuilder();
return $builder->build($parsed);
}
protected function buildIndexSize($parsed) {
$builder = new IndexSizeBuilder();
return $builder->build($parsed);
}
protected function buildIndexType($parsed) {
$builder = new IndexTypeBuilder();
return $builder->build($parsed);
}
protected function buildIndexComment($parsed) {
$builder = new IndexCommentBuilder();
return $builder->build($parsed);
}
protected function buildIndexAlgorithm($parsed) {
$builder = new IndexAlgorithmBuilder();
return $builder->build($parsed);
}
protected function buildIndexLock($parsed) {
$builder = new IndexLockBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['options'] === false) {
return '';
}
$sql = '';
foreach ($parsed['options'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildIndexAlgorithm($v);
$sql .= $this->buildIndexLock($v);
$sql .= $this->buildIndexComment($v);
$sql .= $this->buildIndexParser($v);
$sql .= $this->buildIndexSize($v);
$sql .= $this->buildIndexType($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE INDEX options', $k, $v, 'expr_type');
}
$sql .= ' ';
}
return ' ' . substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,72 @@
<?php
/**
* CreateIndexTable.php
*
* Builds the table part of a CREATE INDEX statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the table part of a CREATE INDEX statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateIndexTableBuilder implements Builder {
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if (!isset($parsed['on']) || $parsed['on'] === false) {
return '';
}
$table = $parsed['on'];
if ($table['expr_type'] !== ExpressionType::TABLE) {
return '';
}
return 'ON ' . $table['name'] . ' ' . $this->buildColumnList($table['sub_tree']);
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* CreateIndexTypeBuilder.php
*
* Builds index type part of a CREATE INDEX statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the index type of a CREATE INDEX
* statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateIndexTypeBuilder extends IndexTypeBuilder {
public function build(array $parsed) {
if (!isset($parsed['index-type']) || $parsed['index-type'] === false) {
return '';
}
return parent::build($parsed['index-type']);
}
}
?>

View File

@@ -0,0 +1,80 @@
<?php
/**
* CreateStatement.php
*
* Builds the CREATE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the whole Create statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateStatementBuilder implements Builder {
protected function buildLIKE($parsed) {
$builder = new LikeBuilder();
return $builder->build($parsed);
}
protected function buildSelectStatement($parsed) {
$builder = new SelectStatementBuilder();
return $builder->build($parsed);
}
protected function buildCREATE($parsed) {
$builder = new CreateBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = $this->buildCREATE($parsed);
if (isset($parsed['LIKE'])) {
$sql .= " " . $this->buildLIKE($parsed['LIKE']);
}
if (isset($parsed['SELECT'])) {
$sql .= " " . $this->buildSelectStatement($parsed);
}
return $sql;
}
}
?>

View File

@@ -0,0 +1,78 @@
<?php
/**
* CreateTable.php
*
* Builds the CREATE TABLE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the CREATE TABLE statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateTableBuilder implements Builder {
protected function buildCreateTableDefinition($parsed) {
$builder = new CreateTableDefinitionBuilder();
return $builder->build($parsed);
}
protected function buildCreateTableOptions($parsed) {
$builder = new CreateTableOptionsBuilder();
return $builder->build($parsed);
}
protected function buildCreateTableSelectOption($parsed) {
$builder = new CreateTableSelectOptionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = $parsed['name'];
$sql .= $this->buildCreateTableDefinition($parsed);
$sql .= $this->buildCreateTableOptions($parsed);
$sql .= $this->buildCreateTableSelectOption($parsed);
return $sql;
}
}
?>

View File

@@ -0,0 +1,66 @@
<?php
/**
* CreateTableDefinitionBuilder.php
*
* Builds the create definitions of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the create definitions of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateTableDefinitionBuilder implements Builder {
protected function buildTableBracketExpression($parsed) {
$builder = new TableBracketExpressionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if (!isset($parsed) || $parsed['create-def'] === false) {
return "";
}
return $this->buildTableBracketExpression($parsed['create-def']);
}
}
?>

View File

@@ -0,0 +1,102 @@
<?php
/**
* CreateTableOptionsBuilder.php
*
* Builds the table-options statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the builder for the table-options statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateTableOptionsBuilder implements Builder {
protected function buildExpression($parsed) {
$builder = new SelectExpressionBuilder();
return $builder->build($parsed);
}
protected function buildCharacterSet($parsed) {
$builder = new CharacterSetBuilder();
return $builder->build($parsed);
}
protected function buildCollation($parsed) {
$builder = new CollationBuilder();
return $builder->build($parsed);
}
/**
* Returns a well-formatted delimiter string. If you don't need nice SQL,
* you could simply return $parsed['delim'].
*
* @param array $parsed The part of the output array, which contains the current expression.
* @return a string, which is added right after the expression
*/
protected function getDelimiter($parsed) {
return ($parsed['delim'] === false ? '' : (trim($parsed['delim']) . ' '));
}
public function build(array $parsed) {
if (!isset($parsed['options']) || $parsed['options'] === false) {
return "";
}
$options = $parsed['options'];
$sql = "";
foreach ($options as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildExpression($v);
$sql .= $this->buildCharacterSet($v);
$sql .= $this->buildCollation($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE options', $k, $v, 'expr_type');
}
$sql .= $this->getDelimiter($v);
}
return " " . substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,65 @@
<?php
/**
* CreateTableSelectOptionBuilder.php
*
* Builds the select-options statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the select-options statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateTableSelectOptionBuilder implements Builder {
public function build(array $parsed) {
if (!isset($parsed['select-option']) || $parsed['select-option'] === false) {
return "";
}
$option = $parsed['select-option'];
$sql = ($option['duplicates'] === false ? '' : (' ' . $option['duplicates']));
$sql .= ($option['as'] === false ? '' : ' AS');
return $sql;
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* DataTypeBuilder.php
*
* Builds the data-type statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the data-type statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DataTypeBuilder implements Builder {
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::DATA_TYPE) {
return "";
}
return $parsed['base_expr'];
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* DatabaseBuilder.php
*
* Builds the database within the SHOW statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for a database within SHOW statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DatabaseBuilder implements Builder {
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::DATABASE) {
return "";
}
return $parsed['base_expr'];
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* DefaultValueBuilder.php
*
* Builds the default value statement part of a column of a CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the default value statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DefaultValueBuilder implements Builder {
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::DEF_VALUE) {
return "";
}
return $parsed['base_expr'];
}
}
?>

View File

@@ -0,0 +1,74 @@
<?php
/**
* DeleteBuilder.php
*
* Builds the DELETE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the [DELETE] part. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DeleteBuilder implements Builder {
public function build(array $parsed) {
$sql = "DELETE ";
$right = -1;
if ($parsed['options'] !== false) {
foreach ($parsed['options'] as $k => $v) {
$sql .= $v . " ";
}
}
if ($parsed['tables'] !== false) {
foreach ($parsed['tables'] as $k => $v) {
$sql .= $v . ", ";
$right = -2;
}
}
return substr($sql, 0, $right);
}
}
?>

View File

@@ -0,0 +1,78 @@
<?php
/**
* DeleteStatementBuilder.php
*
* Builds the DELETE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the whole Delete statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DeleteStatementBuilder implements Builder {
protected function buildWHERE($parsed) {
$builder = new WhereBuilder();
return $builder->build($parsed);
}
protected function buildFROM($parsed) {
$builder = new FromBuilder();
return $builder->build($parsed);
}
protected function buildDELETE($parsed) {
$builder = new DeleteBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = $this->buildDELETE($parsed['DELETE']) . " " . $this->buildFROM($parsed['FROM']);
if (isset($parsed['WHERE'])) {
$sql .= " " . $this->buildWHERE($parsed['WHERE']);
}
return $sql;
}
}
?>

View File

@@ -0,0 +1,61 @@
<?php
/**
* DirectionBuilder.php
*
* Builds direction (e.g. of the order-by clause).
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for directions (e.g. of the order-by clause).
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DirectionBuilder implements Builder {
public function build(array $parsed) {
if (!isset($parsed['direction']) || $parsed['direction'] === false) {
return "";
}
return (" " . $parsed['direction']);
}
}
?>

View File

@@ -0,0 +1,100 @@
<?php
/**
* DropBuilder.php
*
* Builds the CREATE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the [DROP] part. You can overwrite
* all functions to achieve another handling.
*/
class DropBuilder implements Builder {
protected function buildDropIndex( $parsed ) {
$builder = new DropIndexBuilder();
return $builder->build( $parsed );
}
protected function buildReserved( $parsed ) {
$builder = new ReservedBuilder();
return $builder->build( $parsed );
}
protected function buildExpression( $parsed ) {
$builder = new DropExpressionBuilder();
return $builder->build( $parsed );
}
protected function buildSubTree( $parsed ) {
$sql = '';
foreach ( $parsed['sub_tree'] as $k => $v ) {
$len = strlen( $sql );
$sql .= $this->buildReserved( $v );
$sql .= $this->buildExpression( $v );
if ( $len == strlen( $sql ) ) {
throw new UnableToCreateSQLException( 'DROP subtree', $k, $v, 'expr_type' );
}
$sql .= ' ';
}
return $sql;
}
public function build( array $parsed ) {
$drop = $parsed['DROP'];
$sql = $this->buildSubTree( $drop );
if ( $drop['expr_type'] === ExpressionType::INDEX ) {
$sql .= '' . $this->buildDropIndex( $parsed['INDEX'] ) . ' ';
}
return 'DROP ' . substr( $sql, 0, -1 );
}
}
?>

View File

@@ -0,0 +1,103 @@
<?php
/**
* DropExpressionBuilder.php
*
* Builds the object list of a DROP statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the object list of a DROP statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DropExpressionBuilder implements Builder {
protected function buildTable($parsed, $index) {
$builder = new TableBuilder();
return $builder->build($parsed, $index);
}
protected function buildDatabase($parsed) {
$builder = new DatabaseBuilder();
return $builder->build($parsed);
}
protected function buildSchema($parsed) {
$builder = new SchemaBuilder();
return $builder->build($parsed);
}
protected function buildTemporaryTable($parsed) {
$builder = new TempTableBuilder();
return $builder->build($parsed);
}
protected function buildView($parsed) {
$builder = new ViewBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::EXPRESSION) {
return "";
}
$sql = '';
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildTable($v, 0);
$sql .= $this->buildView($v);
$sql .= $this->buildSchema($v);
$sql .= $this->buildDatabase($v);
$sql .= $this->buildTemporaryTable($v, 0);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('DROP object-list subtree', $k, $v, 'expr_type');
}
$sql .= ', ';
}
return substr($sql, 0, -2);
}
}
?>

View File

@@ -0,0 +1,63 @@
<?php
/**
* DropIndexBuilder.php
*
* Builds the CREATE INDEX statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the DROP INDEX statement. You can overwrite
* all functions to achieve another handling.
*/
class DropIndexBuilder implements Builder {
protected function buildIndexTable($parsed) {
$builder = new DropIndexTableBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = $parsed['name'];
$sql = trim($sql);
$sql .= ' ' . $this->buildIndexTable($parsed);
return trim($sql);
}
}
?>

View File

@@ -0,0 +1,67 @@
<?php
/**
* DropIndexTable.php
*
* Builds the table part of a CREATE INDEX statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the table part of a DROP INDEX statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DropIndexTableBuilder implements Builder {
public function build(array $parsed) {
if (!isset($parsed['on']) || $parsed['on'] === false) {
return '';
}
$table = $parsed['on'];
if ($table['expr_type'] !== ExpressionType::TABLE) {
return '';
}
return 'ON ' . $table['name'];
}
}
?>

View File

@@ -0,0 +1,63 @@
<?php
/**
* DropStatement.php
*
* Builds the DROP statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the whole DROP TABLE statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DropStatementBuilder implements Builder {
protected function buildDROP( $parsed ) {
$builder = new DropBuilder();
return $builder->build( $parsed );
}
public function build( array $parsed ) {
return $this->buildDROP( $parsed );
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* DatabaseBuilder.php
*
* Builds the database within the SHOW statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for a database within SHOW statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class EngineBuilder implements Builder {
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::ENGINE) {
return "";
}
return $parsed['base_expr'];
}
}
?>

View File

@@ -0,0 +1,97 @@
<?php
/**
* ForeignKeyBuilder.php
*
* Builds the FOREIGN KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the FOREIGN KEY statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ForeignKeyBuilder implements Builder {
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildForeignRef($parsed) {
$builder = new ForeignRefBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::FOREIGN_KEY) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildConstant($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildColumnList($v);
$sql .= $this->buildForeignRef($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE foreign key subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,92 @@
<?php
/**
* ForeignRefBuilder.php
*
* Builds the FOREIGN KEY REFERENCES statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the FOREIGN KEY REFERENCES statement
* part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ForeignRefBuilder implements Builder {
protected function buildTable($parsed) {
$builder = new TableBuilder();
return $builder->build($parsed, 0);
}
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::REFERENCE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildTable($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildColumnList($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE foreign ref subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,110 @@
<?php
/**
* FromBuilder.php
*
* Builds the FROM statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the builder for the [FROM] part. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class FromBuilder implements Builder {
protected function buildTable($parsed, $key) {
$builder = new TableBuilder();
return $builder->build($parsed, $key);
}
protected function buildTableExpression($parsed, $key) {
$builder = new TableExpressionBuilder();
return $builder->build($parsed, $key);
}
protected function buildSubQuery($parsed, $key) {
$builder = new SubQueryBuilder();
return $builder->build($parsed, $key);
}
public function build(array $parsed) {
$sql = "";
if (array_key_exists("UNION ALL", $parsed) || array_key_exists("UNION", $parsed)) {
foreach ($parsed as $union_type => $outer_v) {
$first = true;
foreach ($outer_v as $item) {
if (!$first) {
$sql .= " $union_type ";
}
else {
$first = false;
}
$select_builder = new SelectStatementBuilder();
$len = strlen($sql);
$sql .= $select_builder->build($item);
if ($len === strlen($sql)) {
throw new UnableToCreateSQLException('FROM', $union_type, $outer_v, 'expr_type');
}
}
}
}
else {
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildTable($v, $k);
$sql .= $this->buildTableExpression($v, $k);
$sql .= $this->buildSubquery($v, $k);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('FROM', $k, $v, 'expr_type');
}
}
}
return "FROM " . $sql;
}
}
?>

View File

@@ -0,0 +1,128 @@
<?php
/**
* FunctionBuilder.php
*
* Builds function statements.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2015 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2015 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for function calls.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class FunctionBuilder implements Builder {
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function isReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->isReserved($parsed);
}
protected function buildSelectExpression($parsed) {
$builder = new SelectExpressionBuilder();
return $builder->build($parsed);
}
protected function buildSelectBracketExpression($parsed) {
$builder = new SelectBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildSubQuery($parsed) {
$builder = new SubQueryBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if (($parsed['expr_type'] !== ExpressionType::AGGREGATE_FUNCTION)
&& ($parsed['expr_type'] !== ExpressionType::SIMPLE_FUNCTION)
&& ($parsed['expr_type'] !== ExpressionType::CUSTOM_FUNCTION)) {
return "";
}
if ($parsed['sub_tree'] === false) {
return $parsed['base_expr'] . "()" . $this->buildAlias($parsed);
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->build($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildSubQuery($v);
$sql .= $this->buildColRef($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildSelectBracketExpression($v);
$sql .= $this->buildSelectExpression($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('function subtree', $k, $v, 'expr_type');
}
$sql .= ($this->isReserved($v) ? " " : ",");
}
return $parsed['base_expr'] . "(" . substr($sql, 0, -1) . ")" . $this->buildAlias($parsed);
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* GroupByAliasBuilder.php
*
* Builds an alias within a GROUP-BY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for an alias within the GROUP-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class GroupByAliasBuilder implements Builder {
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::ALIAS) {
return "";
}
return $parsed['base_expr'];
}
}
?>

View File

@@ -0,0 +1,101 @@
<?php
/**
* GroupByBuilder.php
*
* Builds the GROUP-BY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the builder for the GROUP-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class GroupByBuilder implements Builder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildPosition($parsed) {
$builder = new PositionBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildGroupByAlias($parsed) {
$builder = new GroupByAliasBuilder();
return $builder->build($parsed);
}
protected function buildGroupByExpression($parsed) {
$builder = new GroupByExpressionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = "";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildPosition($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildGroupByExpression($v);
$sql .= $this->buildGroupByAlias($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('GROUP', $k, $v, 'expr_type');
}
$sql .= ", ";
}
$sql = substr($sql, 0, -2);
return "GROUP BY " . $sql;
}
}
?>

View File

@@ -0,0 +1,89 @@
<?php
/**
* GroupByExpressionBuilder.php
*
* Builds an expression within a GROUP-BY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author oohook <oohook@163.com>
* @copyright 2010-2016 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
* @example group by id desc
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for an alias within the GROUP-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author oohook <oohook@163.com>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class GroupByExpressionBuilder implements Builder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::EXPRESSION) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildReserved($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('GROUP expression subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
$sql = substr($sql, 0, -1);
return $sql;
}
}
?>

View File

@@ -0,0 +1,90 @@
<?php
/**
* HavingBracketExpressionBuilder.php
*
* Builds bracket expressions within the HAVING part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for bracket expressions within the HAVING part.
* You can overwrite all functions to achieve another handling.
*
* @author Ian Barker <ian@theorganicagency.com>
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class HavingBracketExpressionBuilder extends WhereBracketExpressionBuilder {
protected function buildHavingExpression($parsed) {
$builder = new HavingExpressionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildInList($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildHavingExpression($v);
$sql .= $this->build($v);
$sql .= $this->buildUserVariable($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('HAVING expression subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
$sql = "(" . substr($sql, 0, -1) . ")";
return $sql;
}
}
?>

View File

@@ -0,0 +1,97 @@
<?php
/**
* HavingBuilder.php
*
* Builds the HAVING part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the builder for the HAVING part.
* You can overwrite all functions to achieve another handling.
*
* @author Ian Barker <ian@theorganicagency.com>
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class HavingBuilder extends WhereBuilder {
protected function buildAliasReference($parsed) {
$builder = new AliasReferenceBuilder();
return $builder->build($parsed);
}
protected function buildHavingExpression($parsed) {
$builder = new HavingExpressionBuilder();
return $builder->build($parsed);
}
protected function buildHavingBracketExpression($parsed) {
$builder = new HavingBracketExpressionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = "HAVING ";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildAliasReference($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildColRef($v);
$sql .= $this->buildSubQuery($v);
$sql .= $this->buildInList($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildHavingExpression($v);
$sql .= $this->buildHavingBracketExpression($v);
$sql .= $this->buildUserVariable($v);
if (strlen($sql) == $len) {
throw new UnableToCreateSQLException('HAVING', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,94 @@
<?php
/**
* HavingExpressionBuilder.php
*
* Builds expressions within the HAVING part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for expressions within the HAVING part.
* You can overwrite all functions to achieve another handling.
*
* @author Ian Barker <ian@theorganicagency.com>
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class HavingExpressionBuilder extends WhereExpressionBuilder {
protected function buildHavingExpression($parsed) {
return $this->build($parsed);
}
protected function buildHavingBracketExpression($parsed) {
$builder = new HavingBracketExpressionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::EXPRESSION) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildInList($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildHavingExpression($v);
$sql .= $this->buildHavingBracketExpression($v);
$sql .= $this->buildUserVariable($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('HAVING expression subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
$sql = substr($sql, 0, -1);
return $sql;
}
}
?>

View File

@@ -0,0 +1,68 @@
<?php
/**
* InListBuilder.php
*
* Builds lists of values for the IN statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder list of values for the IN statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class InListBuilder implements Builder {
protected function buildSubTree($parsed, $delim) {
$builder = new SubTreeBuilder();
return $builder->build($parsed, $delim);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::IN_LIST) {
return "";
}
$sql = $this->buildSubTree($parsed, ", ");
return "(" . $sql . ")";
}
}
?>

View File

@@ -0,0 +1,91 @@
<?php
/**
* IndexAlgorithmBuilder.php
*
* Builds index algorithm part of a CREATE INDEX statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the index algorithm of CREATE INDEX statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexAlgorithmBuilder implements Builder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_ALGORITHM) {
return '';
}
$sql = '';
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildOperator($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE INDEX algorithm subtree', $k, $v, 'expr_type');
}
$sql .= ' ';
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,75 @@
<?php
/**
* IndexColumnBuilder.php
*
* Builds the column entries of the column-list parts of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for index column entries of the column-list
* parts of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexColumnBuilder implements Builder {
protected function buildLength($parsed) {
return ($parsed === false ? '' : ('(' . $parsed . ')'));
}
protected function buildDirection($parsed) {
return ($parsed === false ? '' : (' ' . $parsed));
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_COLUMN) {
return "";
}
$sql = $parsed['name'];
$sql .= $this->buildLength($parsed['length']);
$sql .= $this->buildDirection($parsed['dir']);
return $sql;
}
}
?>

View File

@@ -0,0 +1,85 @@
<?php
/**
* IndexCommentBuilder.php
*
* Builds index comment part of a CREATE INDEX statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the index comment of CREATE INDEX statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexCommentBuilder implements Builder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::COMMENT) {
return '';
}
$sql = '';
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE INDEX comment subtree', $k, $v, 'expr_type');
}
$sql .= ' ';
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,70 @@
<?php
/**
* IndexHintListBuilder.php
*
* Builds the index hint list of a table.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for index hint lists.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexHintListBuilder implements Builder {
public function hasHint($parsed) {
return isset($parsed['hints']);
}
// TODO: the hint list should be enhanced to get base_expr fro position calculation
public function build(array $parsed) {
if (!isset($parsed['hints']) || $parsed['hints'] === false) {
return "";
}
$sql = "";
foreach ($parsed['hints'] as $k => $v) {
$sql .= $v['hint_type'] . " " . $v['hint_list'] . " ";
}
return " " . substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,97 @@
<?php
/**
* IndexKeyBuilder.php
*
* Builds index key part of a CREATE TABLE statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the index key part of a CREATE TABLE statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexKeyBuilder implements Builder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildIndexType($parsed) {
$builder = new IndexTypeBuilder();
return $builder->build($parsed);
}
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildColumnList($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildIndexType($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE index key subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,91 @@
<?php
/**
* IndexLockBuilder.php
*
* Builds index lock part of a CREATE INDEX statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the index lock of CREATE INDEX statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexLockBuilder implements Builder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_LOCK) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildOperator($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE INDEX lock subtree', $k, $v, 'expr_type');
}
$sql .= ' ';
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,86 @@
<?php
/**
* IndexParserBuilder.php
*
* Builds index parser part of a PRIMARY KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the index parser of a PRIMARY KEY
* statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexParserBuilder implements Builder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_PARSER) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key index parser subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,86 @@
<?php
/**
* IndexSizeBuilder.php
*
* Builds index size part of a PRIMARY KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the index size of a PRIMARY KEY
* statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexSizeBuilder implements Builder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_SIZE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key index size subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,80 @@
<?php
/**
* IndexTypeBuilder.php
*
* Builds index type part of a PRIMARY KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the index type of a PRIMARY KEY
* statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexTypeBuilder implements Builder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_TYPE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key index type subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,100 @@
<?php
/**
* InsertBuilder.php
*
* Builds the [INSERT] statement part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the builder for the [INSERT] statement parts.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class InsertBuilder implements Builder {
protected function buildTable($parsed) {
$builder = new TableBuilder();
return $builder->build($parsed, 0);
}
protected function buildSubQuery($parsed) {
$builder = new SubQueryBuilder();
return $builder->build($parsed, 0);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildBracketExpression($parsed) {
$builder = new SelectBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildColumnList($parsed) {
$builder = new InsertColumnListBuilder();
return $builder->build($parsed, 0);
}
public function build(array $parsed) {
$sql = '';
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildTable($v);
$sql .= $this->buildSubQuery($v);
$sql .= $this->buildColumnList($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildBracketExpression($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('INSERT', $k, $v, 'expr_type');
}
$sql .= " ";
}
return 'INSERT ' . substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,80 @@
<?php
/**
* InsertColumnListBuilder.php
*
* Builds column-list parts of INSERT statements.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for column-list parts of INSERT statements.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class InsertColumnListBuilder implements Builder {
protected function buildColumn($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLUMN_LIST) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColumn($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('INSERT column-list subtree', $k, $v, 'expr_type');
}
$sql .= ", ";
}
return "(" . substr($sql, 0, -2) . ")";
}
}
?>

View File

@@ -0,0 +1,89 @@
<?php
/**
* InsertStatement.php
*
* Builds the INSERT statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the whole Insert statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class InsertStatementBuilder implements Builder {
protected function buildVALUES($parsed) {
$builder = new ValuesBuilder();
return $builder->build($parsed);
}
protected function buildINSERT($parsed) {
$builder = new InsertBuilder();
return $builder->build($parsed);
}
protected function buildSELECT($parsed) {
$builder = new SelectStatementBuilder();
return $builder->build($parsed);
}
protected function buildSET($parsed) {
$builder = new SetBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
// TODO: are there more than one tables possible (like [INSERT][1])
$sql = $this->buildINSERT($parsed['INSERT']);
if (isset($parsed['VALUES'])) {
$sql .= ' ' . $this->buildVALUES($parsed['VALUES']);
}
if (isset($parsed['SET'])) {
$sql .= ' ' . $this->buildSET($parsed['SET']);
}
if (isset($parsed['SELECT'])) {
$sql .= ' ' . $this->buildSELECT($parsed);
}
return $sql;
}
}
?>

View File

@@ -0,0 +1,76 @@
<?php
/**
* JoinBuilder.php
*
* Builds the JOIN statement parts (within FROM).
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @author George Schneeloch <noisecapella@gmail.com>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for the JOIN statement parts (within FROM).
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @author George Schneeloch <noisecapella@gmail.com>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class JoinBuilder {
public function build($parsed) {
if ($parsed === 'CROSS') {
return ", ";
}
if ($parsed === 'JOIN') {
return " INNER JOIN ";
}
if ($parsed === 'LEFT') {
return " LEFT JOIN ";
}
if ($parsed === 'RIGHT') {
return " RIGHT JOIN ";
}
if ($parsed === 'STRAIGHT_JOIN') {
return " STRAIGHT_JOIN ";
}
// TODO: add more
throw new UnsupportedFeatureException($parsed);
}
}
?>

View File

@@ -0,0 +1,68 @@
<?php
/**
* LikeBuilder.php
*
* Builds the LIKE statement part of a CREATE TABLE statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the builder for the LIKE statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class LikeBuilder implements Builder {
protected function buildTable($parsed, $index) {
$builder = new TableBuilder();
return $builder->build($parsed, $index);
}
public function build(array $parsed) {
$sql = $this->buildTable($parsed, 0);
if (strlen($sql) === 0) {
throw new UnableToCreateSQLException('LIKE', "", $parsed, 'table');
}
return "LIKE " . $sql;
}
}
?>

View File

@@ -0,0 +1,87 @@
<?php
/**
* LikeExpressionBuilder.php
*
* Builds the LIKE keyword within parenthesis.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the (LIKE) keyword within a
* CREATE TABLE statement. There are difference to LIKE (without parenthesis),
* the latter is a top-level element of the output array.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class LikeExpressionBuilder implements Builder {
protected function buildTable($parsed, $index) {
$builder = new TableBuilder();
return $builder->build($parsed, $index);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::LIKE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildTable($v, 0);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE create-def (like) subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,63 @@
<?php
/**
* LimitBuilder.php
*
* Builds the LIMIT statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the builder LIMIT statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class LimitBuilder implements Builder {
public function build(array $parsed) {
$sql = ($parsed['rowcount']) . ($parsed['offset'] ? " OFFSET " . $parsed['offset'] : "");
if ($sql === "") {
throw new UnableToCreateSQLException('LIMIT', 'rowcount', $parsed, 'rowcount');
}
return "LIMIT " . $sql;
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* OperatorBuilder.php
*
* Builds operators.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for operators.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OperatorBuilder implements Builder {
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::OPERATOR) {
return "";
}
return $parsed['base_expr'];
}
}
?>

View File

@@ -0,0 +1,67 @@
<?php
/**
* OrderByAliasBuilder.php
*
* Builds an alias within an ORDER-BY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for an alias within the ORDER-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OrderByAliasBuilder implements Builder {
protected function buildDirection($parsed) {
$builder = new DirectionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::ALIAS) {
return "";
}
return $parsed['base_expr'] . $this->buildDirection($parsed);
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/**
* OrderByBracketExpressionBuilder.php
*
* Builds bracket-expressions within the ORDER-BY part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for bracket-expressions within the ORDER-BY part.
* It must contain the direction.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OrderByBracketExpressionBuilder extends WhereBracketExpressionBuilder {
protected function buildDirection($parsed) {
$builder = new DirectionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = parent::build($parsed);
if ($sql !== '') {
$sql .= $this->buildDirection($parsed);
}
return $sql;
}
}
?>

View File

@@ -0,0 +1,113 @@
<?php
/**
* OrderByBuilder.php
*
* Builds the ORDERBY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the ORDER-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OrderByBuilder implements Builder {
protected function buildFunction($parsed) {
$builder = new OrderByFunctionBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new OrderByReservedBuilder();
return $builder->build($parsed);
}
protected function buildColRef($parsed) {
$builder = new OrderByColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildAlias($parsed) {
$builder = new OrderByAliasBuilder();
return $builder->build($parsed);
}
protected function buildExpression($parsed) {
$builder = new OrderByExpressionBuilder();
return $builder->build($parsed);
}
protected function buildBracketExpression($parsed) {
$builder = new OrderByBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildPosition($parsed) {
$builder = new PositionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = "";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildAlias($v);
$sql .= $this->buildColRef($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildExpression($v);
$sql .= $this->buildBracketExpression($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildPosition($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('ORDER', $k, $v, 'expr_type');
}
$sql .= ", ";
}
$sql = substr($sql, 0, -2);
return "ORDER BY " . $sql;
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/**
* OrderByColumnReferenceBuilder.php
*
* Builds column references within the ORDER-BY part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for column references within the ORDER-BY part.
* It must contain the direction.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OrderByColumnReferenceBuilder extends ColumnReferenceBuilder {
protected function buildDirection($parsed) {
$builder = new DirectionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = parent::build($parsed);
if ($sql !== '') {
$sql .= $this->buildDirection($parsed);
}
return $sql;
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/**
* OrderByExpressionBuilder.php
*
* Builds expressions within the ORDER-BY part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for expressions within the ORDER-BY part.
* It must contain the direction.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OrderByExpressionBuilder extends WhereExpressionBuilder {
protected function buildDirection($parsed) {
$builder = new DirectionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = parent::build($parsed);
if ($sql !== '') {
$sql .= $this->buildDirection($parsed);
}
return $sql;
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/**
* OrderByFunctionBuilder.php
*
* Builds functions within the ORDER-BY part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for functions within the ORDER-BY part.
* It must contain the direction.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OrderByFunctionBuilder extends FunctionBuilder {
protected function buildDirection($parsed) {
$builder = new DirectionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = parent::build($parsed);
if ($sql !== '') {
$sql .= $this->buildDirection($parsed);
}
return $sql;
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/**
* OrderByReservedBuilder.php
*
* Builds reserved keywords within the ORDER-BY part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
/**
* This class implements the builder for reserved keywords within the ORDER-BY part.
* It must contain the direction.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OrderByReservedBuilder extends ReservedBuilder {
protected function buildDirection($parsed) {
$builder = new DirectionBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
$sql = parent::build($parsed);
if ($sql !== '') {
$sql .= $this->buildDirection($parsed);
}
return $sql;
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* PositionBuilder.php
*
* Builds positions of the GROUP BY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for positions of the GROUP-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class PositionBuilder implements Builder {
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::POSITION) {
return "";
}
return $parsed['base_expr'];
}
}
?>

View File

@@ -0,0 +1,109 @@
<?php
/**
* PrimaryKeyBuilder.php
*
* Builds the PRIMARY KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the PRIMARY KEY statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class PrimaryKeyBuilder implements Builder {
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
protected function buildConstraint($parsed) {
$builder = new ConstraintBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildIndexType($parsed) {
$builder = new IndexTypeBuilder();
return $builder->build($parsed);
}
protected function buildIndexSize($parsed) {
$builder = new IndexSizeBuilder();
return $builder->build($parsed);
}
protected function buildIndexParser($parsed) {
$builder = new IndexParserBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::PRIMARY_KEY) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildConstraint($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildColumnList($v);
$sql .= $this->buildIndexType($v);
$sql .= $this->buildIndexSize($v);
$sql .= $this->buildIndexParser($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -0,0 +1,62 @@
<?php
/**
* Procedureuilder.php
*
* Builds the procedures within the SHOW statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for a procedure within SHOW statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ProcedureBuilder implements Builder {
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::PROCEDURE) {
return "";
}
return $parsed['base_expr'];
}
}
?>

View File

@@ -0,0 +1,97 @@
<?php
/**
* QueryBuilder.php
*
* Builds the SELECT statements within parentheses.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for queries within parentheses (no subqueries).
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class QueryBuilder implements Builder {
protected function buildRefClause($parsed) {
$builder = new RefClauseBuilder();
return $builder->build($parsed);
}
protected function buildRefType($parsed) {
$builder = new RefTypeBuilder();
return $builder->build($parsed);
}
protected function buildJoin($parsed) {
$builder = new JoinBuilder();
return $builder->build($parsed);
}
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
protected function buildSelectStatement($parsed) {
$builder = new SelectStatementBuilder();
return $builder->build($parsed);
}
public function build(array $parsed, $index = 0) {
if ($parsed['expr_type'] !== ExpressionType::QUERY) {
return '';
}
// TODO: should we add a numeric level (0) between sub_tree and SELECT?
$sql = $this->buildSelectStatement($parsed['sub_tree']);
$sql .= $this->buildAlias($parsed);
if ($index !== 0) {
$sql = $this->buildJoin($parsed['join_type']) . $sql;
$sql .= $this->buildRefType($parsed['ref_type']);
$sql .= $parsed['ref_clause'] === false ? '' : $this->buildRefClause($parsed['ref_clause']);
}
return $sql;
}
}
?>

View File

@@ -0,0 +1,99 @@
<?php
/**
* RecordBuilder.php
*
* Builds the records within the INSERT statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
use PHPSQLParser\utils\ExpressionType;
/**
* This class implements the builder for the records within INSERT statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class RecordBuilder implements Builder {
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::RECORD) {
return isset($parsed['base_expr']) ? $parsed['base_expr'] : '';
}
$sql = "";
foreach ($parsed['data'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildConstant($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildColRef($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException(ExpressionType::RECORD, $k, $v, 'expr_type');
}
$sql .= ", ";
}
$sql = substr($sql, 0, -2);
return "(" . $sql . ")";
}
}
?>

View File

@@ -0,0 +1,114 @@
<?php
/**
* RefClauseBuilder.php
*
* Builds reference clauses within a JOIN.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/
namespace PHPSQLParser\builders;
use PHPSQLParser\exceptions\UnableToCreateSQLException;
/**
* This class implements the references clause within a JOIN.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class RefClauseBuilder implements Builder {
protected function buildInList($parsed) {
$builder = new InListBuilder();
return $builder->build($parsed);
}
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildBracketExpression($parsed) {
$builder = new SelectBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed === false) {
return '';
}
$sql = '';
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildBracketExpression($v);
$sql .= $this->buildInList($v);
$sql .= $this->buildColumnList($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('expression ref_clause', $k, $v, 'expr_type');
}
$sql .= ' ';
}
return substr($sql, 0, -1);
}
}
?>

Some files were not shown because too many files have changed in this diff Show More