| 2919 | ) |
| 2920 | |
| 2921 | def check_results(dialect, expected_results, literal): |
| 2922 | eq_( |
| 2923 | len(expected_results), |
| 2924 | 5, |
| 2925 | "Incorrect number of expected results", |
| 2926 | ) |
| 2927 | eq_( |
| 2928 | str(cast(tbl.c.v1, Numeric).compile(dialect=dialect)), |
| 2929 | "CAST(casttest.v1 AS %s)" % expected_results[0], |
| 2930 | ) |
| 2931 | eq_( |
| 2932 | str(tbl.c.v1.cast(Numeric).compile(dialect=dialect)), |
| 2933 | "CAST(casttest.v1 AS %s)" % expected_results[0], |
| 2934 | ) |
| 2935 | eq_( |
| 2936 | str(cast(tbl.c.v1, Numeric(12, 9)).compile(dialect=dialect)), |
| 2937 | "CAST(casttest.v1 AS %s)" % expected_results[1], |
| 2938 | ) |
| 2939 | eq_( |
| 2940 | str(cast(tbl.c.ts, Date).compile(dialect=dialect)), |
| 2941 | "CAST(casttest.ts AS %s)" % expected_results[2], |
| 2942 | ) |
| 2943 | eq_( |
| 2944 | str(cast(1234, Text).compile(dialect=dialect)), |
| 2945 | "CAST(%s AS %s)" % (literal, expected_results[3]), |
| 2946 | ) |
| 2947 | eq_( |
| 2948 | str(cast("test", String(20)).compile(dialect=dialect)), |
| 2949 | "CAST(%s AS %s)" % (literal, expected_results[4]), |
| 2950 | ) |
| 2951 | |
| 2952 | # fixme: shoving all of this dialect-specific stuff in one test |
| 2953 | # is now officially completely ridiculous AND non-obviously omits |
| 2954 | # coverage on other dialects. |
| 2955 | sel = select(tbl, cast(tbl.c.v1, Numeric)).compile(dialect=dialect) |
| 2956 | |
| 2957 | # TODO: another unusual result from disambiguate only: |
| 2958 | # v1__1 vs v1_1 are due to the special meaning |
| 2959 | # WrapsColumnExpression gives to the "_anon_name_label" attribute, |
| 2960 | # where it tries to default to a label name that matches that of |
| 2961 | # the column within. |
| 2962 | |
| 2963 | if isinstance(dialect, type(mysql.dialect())): |
| 2964 | eq_( |
| 2965 | str(sel), |
| 2966 | "SELECT casttest.id, casttest.v1, casttest.v2, " |
| 2967 | "casttest.ts, " |
| 2968 | "CAST(casttest.v1 AS DECIMAL) AS v1__1 \n" |
| 2969 | "FROM casttest", |
| 2970 | ) |
| 2971 | else: |
| 2972 | eq_( |
| 2973 | str(sel), |
| 2974 | "SELECT casttest.id, casttest.v1, casttest.v2, " |
| 2975 | "casttest.ts, CAST(casttest.v1 AS NUMERIC) AS " |
| 2976 | "v1__1 \nFROM casttest", |
| 2977 | ) |
| 2978 | |