Code Duplication    Length = 13-82 lines in 4 locations

lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php 3 locations

@@ 755-772 (lines=18) @@
752
     *
753
     * @todo Where is this used? Which information should be retrieved?
754
     */
755
    public function getListTableConstraintsSQL($table)
756
    {
757
        $user = '';
758
759
        if (strpos($table, '.') !== false) {
760
            list($user, $table) = explode('.', $table);
761
            $user = $this->quoteStringLiteral($user);
762
            $table = $this->quoteStringLiteral($table);
763
        } else {
764
            $table = $this->quoteStringLiteral($table);
765
        }
766
767
        return "SELECT con.*
768
                FROM   SYS.SYSCONSTRAINT AS con
769
                JOIN   SYS.SYSTAB AS tab ON con.table_object_id = tab.object_id
770
                WHERE  tab.table_name = $table
771
                AND    tab.creator = USER_ID($user)";
772
    }
773
774
    /**
775
     * {@inheritdoc}
@@ 777-858 (lines=82) @@
774
    /**
775
     * {@inheritdoc}
776
     */
777
    public function getListTableForeignKeysSQL($table)
778
    {
779
        $user = '';
780
781
        if (strpos($table, '.') !== false) {
782
            list($user, $table) = explode('.', $table);
783
            $user = $this->quoteStringLiteral($user);
784
            $table = $this->quoteStringLiteral($table);
785
        } else {
786
            $table = $this->quoteStringLiteral($table);
787
        }
788
789
        return "SELECT    fcol.column_name AS local_column,
790
                          ptbl.table_name AS foreign_table,
791
                          pcol.column_name AS foreign_column,
792
                          idx.index_name,
793
                          IF fk.nulls = 'N'
794
                              THEN 1
795
                              ELSE NULL
796
                          ENDIF AS notnull,
797
                          CASE ut.referential_action
798
                              WHEN 'C' THEN 'CASCADE'
799
                              WHEN 'D' THEN 'SET DEFAULT'
800
                              WHEN 'N' THEN 'SET NULL'
801
                              WHEN 'R' THEN 'RESTRICT'
802
                              ELSE NULL
803
                          END AS  on_update,
804
                          CASE dt.referential_action
805
                              WHEN 'C' THEN 'CASCADE'
806
                              WHEN 'D' THEN 'SET DEFAULT'
807
                              WHEN 'N' THEN 'SET NULL'
808
                              WHEN 'R' THEN 'RESTRICT'
809
                              ELSE NULL
810
                          END AS on_delete,
811
                          IF fk.check_on_commit = 'Y'
812
                              THEN 1
813
                              ELSE NULL
814
                          ENDIF AS check_on_commit, -- check_on_commit flag
815
                          IF ftbl.clustered_index_id = idx.index_id
816
                              THEN 1
817
                              ELSE NULL
818
                          ENDIF AS 'clustered', -- clustered flag
819
                          IF fk.match_type = 0
820
                              THEN NULL
821
                              ELSE fk.match_type
822
                          ENDIF AS 'match', -- match option
823
                          IF pidx.max_key_distance = 1
824
                              THEN 1
825
                              ELSE NULL
826
                          ENDIF AS for_olap_workload -- for_olap_workload flag
827
                FROM      SYS.SYSFKEY AS fk
828
                JOIN      SYS.SYSIDX AS idx
829
                ON        fk.foreign_table_id = idx.table_id
830
                AND       fk.foreign_index_id = idx.index_id
831
                JOIN      SYS.SYSPHYSIDX pidx
832
                ON        idx.table_id = pidx.table_id
833
                AND       idx.phys_index_id = pidx.phys_index_id
834
                JOIN      SYS.SYSTAB AS ptbl
835
                ON        fk.primary_table_id = ptbl.table_id
836
                JOIN      SYS.SYSTAB AS ftbl
837
                ON        fk.foreign_table_id = ftbl.table_id
838
                JOIN      SYS.SYSIDXCOL AS idxcol
839
                ON        idx.table_id = idxcol.table_id
840
                AND       idx.index_id = idxcol.index_id
841
                JOIN      SYS.SYSTABCOL AS pcol
842
                ON        ptbl.table_id = pcol.table_id
843
                AND       idxcol.primary_column_id = pcol.column_id
844
                JOIN      SYS.SYSTABCOL AS fcol
845
                ON        ftbl.table_id = fcol.table_id
846
                AND       idxcol.column_id = fcol.column_id
847
                LEFT JOIN SYS.SYSTRIGGER ut
848
                ON        fk.foreign_table_id = ut.foreign_table_id
849
                AND       fk.foreign_index_id = ut.foreign_key_id
850
                AND       ut.event = 'C'
851
                LEFT JOIN SYS.SYSTRIGGER dt
852
                ON        fk.foreign_table_id = dt.foreign_table_id
853
                AND       fk.foreign_index_id = dt.foreign_key_id
854
                AND       dt.event = 'D'
855
                WHERE     ftbl.table_name = $table
856
                AND       ftbl.creator = USER_ID($user)
857
                ORDER BY  fk.foreign_index_id ASC, idxcol.sequence ASC";
858
    }
859
860
    /**
861
     * {@inheritdoc}
@@ 863-911 (lines=49) @@
860
    /**
861
     * {@inheritdoc}
862
     */
863
    public function getListTableIndexesSQL($table, $currentDatabase = null)
864
    {
865
        $user = '';
866
867
        if (strpos($table, '.') !== false) {
868
            list($user, $table) = explode('.', $table);
869
            $user = $this->quoteStringLiteral($user);
870
            $table = $this->quoteStringLiteral($table);
871
        } else {
872
            $table = $this->quoteStringLiteral($table);
873
        }
874
875
        return "SELECT   idx.index_name AS key_name,
876
                         IF idx.index_category = 1
877
                             THEN 1
878
                             ELSE 0
879
                         ENDIF AS 'primary',
880
                         col.column_name,
881
                         IF idx.\"unique\" IN(1, 2, 5)
882
                             THEN 0
883
                             ELSE 1
884
                         ENDIF AS non_unique,
885
                         IF tbl.clustered_index_id = idx.index_id
886
                             THEN 1
887
                             ELSE NULL
888
                         ENDIF AS 'clustered', -- clustered flag
889
                         IF idx.\"unique\" = 5
890
                             THEN 1
891
                             ELSE NULL
892
                         ENDIF AS with_nulls_not_distinct, -- with_nulls_not_distinct flag
893
                         IF pidx.max_key_distance = 1
894
                              THEN 1
895
                              ELSE NULL
896
                          ENDIF AS for_olap_workload -- for_olap_workload flag
897
                FROM     SYS.SYSIDX AS idx
898
                JOIN     SYS.SYSPHYSIDX pidx
899
                ON       idx.table_id = pidx.table_id
900
                AND      idx.phys_index_id = pidx.phys_index_id
901
                JOIN     SYS.SYSIDXCOL AS idxcol
902
                ON       idx.table_id = idxcol.table_id AND idx.index_id = idxcol.index_id
903
                JOIN     SYS.SYSTABCOL AS col
904
                ON       idxcol.table_id = col.table_id AND idxcol.column_id = col.column_id
905
                JOIN     SYS.SYSTAB AS tbl
906
                ON       idx.table_id = tbl.table_id
907
                WHERE    tbl.table_name = $table
908
                AND      tbl.creator = USER_ID($user)
909
                AND      idx.index_category != 2 -- exclude indexes implicitly created by foreign key constraints
910
                ORDER BY idx.index_id ASC, idxcol.sequence ASC";
911
    }
912
913
    /**
914
     * {@inheritdoc}

lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php 1 location

@@ 957-969 (lines=13) @@
954
     *
955
     * @return string
956
     */
957
    private function getTableWhereClause($table, $schemaColumn, $tableColumn)
958
    {
959
        if (strpos($table, ".") !== false) {
960
            list($schema, $table) = explode(".", $table);
961
            $schema = $this->quoteStringLiteral($schema);
962
            $table = $this->quoteStringLiteral($table);
963
        } else {
964
            $schema = "SCHEMA_NAME()";
965
            $table = $this->quoteStringLiteral($table);
966
        }
967
968
        return "({$tableColumn} = {$table} AND {$schemaColumn} = {$schema})";
969
    }
970
971
    /**
972
     * {@inheritDoc}