@@ -2955,7 +2955,7 @@ def insert_test1(transaction):
29552955 keys , placeholders = get_param_info (
29562956 ["key" , "create_time" , "expiry_time" ], database_dialect
29572957 )
2958- transaction .execute_sql (
2958+ transaction .execute_update (
29592959 f"""
29602960 INSERT INTO IntervalTable (key, create_time, expiry_time)
29612961 VALUES ({ placeholders [0 ]} , { placeholders [1 ]} , { placeholders [2 ]} )
@@ -2972,6 +2972,25 @@ def insert_test1(transaction):
29722972 },
29732973 )
29742974
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+
29752994 def test_computed_columns (transaction ):
29762995 keys , placeholders = get_param_info (["key" ], database_dialect )
29772996 results = list (
@@ -3003,34 +3022,13 @@ def test_interval_arithmetic(transaction):
30033022 assert interval .days == 1
30043023 assert interval .nanos == 0
30053024
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-
30273025 def test_interval_timestamp_comparison (transaction ):
30283026 timestamp = "2004-11-30T10:23:54+0530"
30293027 keys , placeholders = get_param_info (["interval" ], database_dialect )
30303028 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 ]} "
30323030 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 ]} "
30343032
30353033 results = list (
30363034 transaction .execute_sql (
@@ -3042,7 +3040,7 @@ def test_interval_timestamp_comparison(transaction):
30423040 assert len (results ) == 1
30433041 assert results [0 ][0 ] == 1
30443042
3045- def test_interval_array_param (transaction , database_dialect ):
3043+ def test_interval_array_param (transaction ):
30463044 intervals = [
30473045 Interval (months = 14 , days = 3 , nanos = 14706000000000 ),
30483046 Interval (),
@@ -3066,26 +3064,21 @@ def test_interval_array_param(transaction, database_dialect):
30663064 intervals = row [0 ]
30673065 assert len (intervals ) == 4
30683066
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
30743070
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
3071+ assert intervals [1 ].months == 0
3072+ assert intervals [1 ].days == 0
3073+ assert intervals [1 ].nanos == 0
30793074
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
3075+ assert intervals [2 ].months == - 14
3076+ assert intervals [2 ].days == - 3
3077+ assert intervals [2 ].nanos == - 14706000000000
30843078
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
3079+ assert intervals [3 ].months == 0
3080+ assert intervals [3 ].days == 0
3081+ assert intervals [3 ].nanos == 0
30893082
30903083 def test_interval_array_cast (transaction ):
30913084 results = list (
@@ -3104,17 +3097,15 @@ def test_interval_array_cast(transaction):
31043097 intervals = row [0 ]
31053098 assert len (intervals ) == 3
31063099
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
3100+ assert intervals [0 ].months == 14 # 1 year + 2 months
3101+ assert intervals [0 ].days == 3
3102+ assert intervals [0 ].nanos == 14706789123000 # 4h5m6.789123s in nanos
31113103
3112- assert intervals [1 ]. valid is False
3104+ assert intervals [1 ] is None
31133105
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
3106+ assert intervals [2 ].months == - 14
3107+ assert intervals [2 ].days == - 3
3108+ assert intervals [2 ].nanos == - 14706789123000
31183109
31193110 setup_table ()
31203111 sessions_database .run_in_transaction (insert_test1 )
0 commit comments