@@ -2955,7 +2955,7 @@ def insert_test1(transaction):
2955
2955
keys , placeholders = get_param_info (
2956
2956
["key" , "create_time" , "expiry_time" ], database_dialect
2957
2957
)
2958
- transaction .execute_sql (
2958
+ transaction .execute_update (
2959
2959
f"""
2960
2960
INSERT INTO IntervalTable (key, create_time, expiry_time)
2961
2961
VALUES ({ placeholders [0 ]} , { placeholders [1 ]} , { placeholders [2 ]} )
@@ -2972,6 +2972,25 @@ def insert_test1(transaction):
2972
2972
},
2973
2973
)
2974
2974
2975
+ def insert_test2 (transaction ):
2976
+ keys , placeholders = get_param_info (["key" , "create_time" , "expiry_time" ], database_dialect )
2977
+ transaction .execute_update (
2978
+ f"""
2979
+ INSERT INTO IntervalTable (key, create_time, expiry_time)
2980
+ VALUES ({ placeholders [0 ]} , { placeholders [1 ]} , { placeholders [2 ]} )
2981
+ """ ,
2982
+ params = {
2983
+ keys [0 ]: "test2" ,
2984
+ keys [1 ]: datetime .datetime (2004 , 8 , 30 , 4 , 53 , 54 , tzinfo = UTC ),
2985
+ keys [2 ]: datetime .datetime (2004 , 12 , 15 , 4 , 53 , 54 , tzinfo = UTC ),
2986
+ },
2987
+ param_types = {
2988
+ keys [0 ]: spanner_v1 .param_types .STRING ,
2989
+ keys [1 ]: spanner_v1 .param_types .TIMESTAMP ,
2990
+ keys [2 ]: spanner_v1 .param_types .TIMESTAMP ,
2991
+ },
2992
+ )
2993
+
2975
2994
def test_computed_columns (transaction ):
2976
2995
keys , placeholders = get_param_info (["key" ], database_dialect )
2977
2996
results = list (
@@ -3003,34 +3022,13 @@ def test_interval_arithmetic(transaction):
3003
3022
assert interval .days == 1
3004
3023
assert interval .nanos == 0
3005
3024
3006
- def insert_test2 (transaction ):
3007
- keys , placeholders = get_param_info (
3008
- ["key" , "create_time" , "expiry_time" ], database_dialect
3009
- )
3010
- transaction .execute_sql (
3011
- f"""
3012
- INSERT INTO IntervalTable (key, create_time, expiry_time)
3013
- VALUES ({ placeholders [0 ]} , { placeholders [1 ]} , { placeholders [2 ]} )
3014
- """ ,
3015
- params = {
3016
- keys [0 ]: "test2" ,
3017
- keys [1 ]: datetime .datetime (2004 , 8 , 30 , 4 , 53 , 54 , tzinfo = UTC ),
3018
- keys [2 ]: datetime .datetime (2004 , 12 , 15 , 4 , 53 , 54 , tzinfo = UTC ),
3019
- },
3020
- param_types = {
3021
- keys [0 ]: spanner_v1 .param_types .STRING ,
3022
- keys [1 ]: spanner_v1 .param_types .TIMESTAMP ,
3023
- keys [2 ]: spanner_v1 .param_types .TIMESTAMP ,
3024
- },
3025
- )
3026
-
3027
3025
def test_interval_timestamp_comparison (transaction ):
3028
3026
timestamp = "2004-11-30T10:23:54+0530"
3029
3027
keys , placeholders = get_param_info (["interval" ], database_dialect )
3030
3028
if database_dialect == DatabaseDialect .POSTGRESQL :
3031
- query = f"SELECT COUNT(*) FROM IntervalTable WHERE create_time < TIMESTAMPTZ %s - { placeholders [0 ]} "
3029
+ query = f"SELECT COUNT(*) FROM IntervalTable WHERE create_time < TIMESTAMPTZ '%s' - { placeholders [0 ]} "
3032
3030
else :
3033
- query = f"SELECT COUNT(*) FROM IntervalTable WHERE create_time < TIMESTAMP(%s ) - { placeholders [0 ]} "
3031
+ query = f"SELECT COUNT(*) FROM IntervalTable WHERE create_time < TIMESTAMP('%s' ) - { placeholders [0 ]} "
3034
3032
3035
3033
results = list (
3036
3034
transaction .execute_sql (
@@ -3042,12 +3040,12 @@ def test_interval_timestamp_comparison(transaction):
3042
3040
assert len (results ) == 1
3043
3041
assert results [0 ][0 ] == 1
3044
3042
3045
- def test_interval_array_param (transaction , database_dialect ):
3043
+ def test_interval_array_param (transaction ):
3046
3044
intervals = [
3047
3045
Interval (months = 14 , days = 3 , nanos = 14706000000000 ),
3048
3046
Interval (),
3049
3047
Interval (months = - 14 , days = - 3 , nanos = - 14706000000000 ),
3050
- Interval () ,
3048
+ None ,
3051
3049
]
3052
3050
keys , placeholders = get_param_info (["intervals" ], database_dialect )
3053
3051
array_type = spanner_v1 .Type (
@@ -3066,26 +3064,20 @@ def test_interval_array_param(transaction, database_dialect):
3066
3064
intervals = row [0 ]
3067
3065
assert len (intervals ) == 4
3068
3066
3069
- # Check first interval
3070
- assert intervals [0 ].valid is True
3071
- assert intervals [0 ].interval .months == 14
3072
- assert intervals [0 ].interval .days == 3
3073
- assert intervals [0 ].interval .nanos == 14706000000000
3067
+ assert intervals [0 ].months == 14
3068
+ assert intervals [0 ].days == 3
3069
+ assert intervals [0 ].nanos == 14706000000000
3070
+
3071
+ assert intervals [1 ].months == 0
3072
+ assert intervals [1 ].days == 0
3073
+ assert intervals [1 ].nanos == 0
3074
3074
3075
- assert intervals [1 ].valid is True
3076
- assert intervals [1 ].interval .months == 0
3077
- assert intervals [1 ].interval .days == 0
3078
- assert intervals [1 ].interval .nanos == 0
3075
+ assert intervals [2 ].months == - 14
3076
+ assert intervals [2 ].days == - 3
3077
+ assert intervals [2 ].nanos == - 14706000000000
3079
3078
3080
- assert intervals [2 ].valid is True
3081
- assert intervals [2 ].interval .months == - 14
3082
- assert intervals [2 ].interval .days == - 3
3083
- assert intervals [2 ].interval .nanos == - 14706000000000
3079
+ assert intervals [3 ] is None
3084
3080
3085
- assert intervals [3 ].valid is True
3086
- assert intervals [3 ].interval .months == 0
3087
- assert intervals [3 ].interval .days == 0
3088
- assert intervals [3 ].interval .nanos == 0
3089
3081
3090
3082
def test_interval_array_cast (transaction ):
3091
3083
results = list (
@@ -3104,17 +3096,15 @@ def test_interval_array_cast(transaction):
3104
3096
intervals = row [0 ]
3105
3097
assert len (intervals ) == 3
3106
3098
3107
- assert intervals [0 ].valid is True
3108
- assert intervals [0 ].interval .months == 14 # 1 year + 2 months
3109
- assert intervals [0 ].interval .days == 3
3110
- assert intervals [0 ].interval .nanos == 14706789123000 # 4h5m6.789123s in nanos
3099
+ assert intervals [0 ].months == 14 # 1 year + 2 months
3100
+ assert intervals [0 ].days == 3
3101
+ assert intervals [0 ].nanos == 14706789123000 # 4h5m6.789123s in nanos
3111
3102
3112
- assert intervals [1 ]. valid is False
3103
+ assert intervals [1 ] is None
3113
3104
3114
- assert intervals [2 ].valid is True
3115
- assert intervals [2 ].interval .months == - 14
3116
- assert intervals [2 ].interval .days == - 3
3117
- assert intervals [2 ].interval .nanos == - 14706789123000
3105
+ assert intervals [2 ].months == - 14
3106
+ assert intervals [2 ].days == - 3
3107
+ assert intervals [2 ].nanos == - 14706789123000
3118
3108
3119
3109
setup_table ()
3120
3110
sessions_database .run_in_transaction (insert_test1 )
0 commit comments