@@ -2868,6 +2868,7 @@ end;
2868
2868
},
2869
2869
},
2870
2870
2871
+ // Nested Triggers
2871
2872
{
2872
2873
Name : "double nested triggers referencing multiple tables" ,
2873
2874
SetUpScript : []string {
@@ -2941,7 +2942,6 @@ for each row
2941
2942
},
2942
2943
},
2943
2944
},
2944
-
2945
2945
{
2946
2946
Name : "triple nested delete triggers referencing multiple tables" ,
2947
2947
SetUpScript : []string {
@@ -3024,7 +3024,6 @@ for each row
3024
3024
},
3025
3025
},
3026
3026
},
3027
-
3028
3027
{
3029
3028
Name : "triple nested insert triggers referencing multiple tables" ,
3030
3029
SetUpScript : []string {
@@ -3117,7 +3116,6 @@ for each row
3117
3116
},
3118
3117
},
3119
3118
},
3120
-
3121
3119
{
3122
3120
Name : "triple nested update triggers referencing multiple tables" ,
3123
3121
SetUpScript : []string {
@@ -3227,6 +3225,170 @@ for each row
3227
3225
},
3228
3226
},
3229
3227
},
3228
+
3229
+ // Triggers with subqueries
3230
+ {
3231
+ Name : "insert trigger with subquery projections" ,
3232
+ SetUpScript : []string {
3233
+ "create table t (i int primary key, j int);" ,
3234
+ `
3235
+ create trigger trig1 before insert on t
3236
+ for each row
3237
+ begin
3238
+ set @a = (select 10 * new.i);
3239
+ set @b = (select 20 * new.j);
3240
+ end;
3241
+ ` ,
3242
+ `
3243
+ create trigger trig2 after insert on t
3244
+ for each row
3245
+ begin
3246
+ set @c = (select 30 * new.i);
3247
+ set @d = (select 40 * new.j);
3248
+ end;
3249
+ ` ,
3250
+ },
3251
+ Assertions : []ScriptTestAssertion {
3252
+ {
3253
+ Query : "select @a, @b, @c, @d;" ,
3254
+ Expected : []sql.Row {
3255
+ {nil , nil , nil , nil },
3256
+ },
3257
+ },
3258
+ {
3259
+ Query : "insert into t values (1, 2);" ,
3260
+ Expected : []sql.Row {
3261
+ {types.OkResult {RowsAffected : 1 }},
3262
+ },
3263
+ },
3264
+ {
3265
+ Query : "select @a, @b, @c, @d;" ,
3266
+ Expected : []sql.Row {
3267
+ {10 , 40 , 30 , 80 },
3268
+ },
3269
+ },
3270
+ {
3271
+ Query : "insert into t values (1, 200);" ,
3272
+ ExpectedErrStr : "duplicate primary key given: [1]" ,
3273
+ },
3274
+ {
3275
+ Query : "select @a, @b, @c, @d;" ,
3276
+ Expected : []sql.Row {
3277
+ {10 , 4000 , 30 , 80 },
3278
+ },
3279
+ },
3280
+ },
3281
+ },
3282
+ {
3283
+ Name : "delete trigger with subquery projections" ,
3284
+ SetUpScript : []string {
3285
+ "create table t (i int primary key, j int);" ,
3286
+ "insert into t values (1, 2), (3, 4);" ,
3287
+ `
3288
+ create trigger trig1 before delete on t
3289
+ for each row
3290
+ begin
3291
+ set @a = (select 10 * old.i);
3292
+ set @b = (select 20 * old.j);
3293
+ end;
3294
+ ` ,
3295
+ `
3296
+ create trigger trig2 after delete on t
3297
+ for each row
3298
+ begin
3299
+ set @c = (select 30 * old.i);
3300
+ set @d = (select 40 * old.j);
3301
+ end;
3302
+ ` ,
3303
+ },
3304
+ Assertions : []ScriptTestAssertion {
3305
+ {
3306
+ Query : "select @a, @b, @c, @d;" ,
3307
+ Expected : []sql.Row {
3308
+ {nil , nil , nil , nil },
3309
+ },
3310
+ },
3311
+ {
3312
+ Query : "delete from t where i = 1;" ,
3313
+ Expected : []sql.Row {
3314
+ {types.OkResult {RowsAffected : 1 }},
3315
+ },
3316
+ },
3317
+ {
3318
+ Query : "select @a, @b, @c, @d;" ,
3319
+ Expected : []sql.Row {
3320
+ {10 , 40 , 30 , 80 },
3321
+ },
3322
+ },
3323
+ {
3324
+ Query : "delete from t where j = 4;" ,
3325
+ Expected : []sql.Row {
3326
+ {types.OkResult {RowsAffected : 1 }},
3327
+ },
3328
+ },
3329
+ {
3330
+ Query : "select @a, @b, @c, @d;" ,
3331
+ Expected : []sql.Row {
3332
+ {30 , 80 , 90 , 160 },
3333
+ },
3334
+ },
3335
+ },
3336
+ },
3337
+ {
3338
+ Name : "update trigger with subquery projections" ,
3339
+ SetUpScript : []string {
3340
+ "create table t (i int primary key, j int);" ,
3341
+ "insert into t values (1, 2), (3, 4);" ,
3342
+ `
3343
+ create trigger trig1 before update on t
3344
+ for each row
3345
+ begin
3346
+ set @a = (select 10 * old.i + new.i);
3347
+ set @b = (select 20 * old.j + new.j);
3348
+ end;
3349
+ ` ,
3350
+ `
3351
+ create trigger trig2 after update on t
3352
+ for each row
3353
+ begin
3354
+ set @c = (select 30 * old.i + new.i);
3355
+ set @d = (select 40 * old.j + new.j);
3356
+ end;
3357
+ ` ,
3358
+ },
3359
+ Assertions : []ScriptTestAssertion {
3360
+ {
3361
+ Query : "select @a, @b, @c, @d;" ,
3362
+ Expected : []sql.Row {
3363
+ {nil , nil , nil , nil },
3364
+ },
3365
+ },
3366
+ {
3367
+ Query : "update t set i = i * 10 where i = 1;" ,
3368
+ Expected : []sql.Row {
3369
+ {types.OkResult {RowsAffected : 1 , Info : plan.UpdateInfo {Matched : 1 , Updated : 1 }}},
3370
+ },
3371
+ },
3372
+ {
3373
+ Query : "select @a, @b, @c, @d;" ,
3374
+ Expected : []sql.Row {
3375
+ {20 , 42 , 40 , 82 },
3376
+ },
3377
+ },
3378
+ {
3379
+ Query : "update t set j = i * 10 where j = 4;" ,
3380
+ Expected : []sql.Row {
3381
+ {types.OkResult {RowsAffected : 1 , Info : plan.UpdateInfo {Matched : 1 , Updated : 1 }}},
3382
+ },
3383
+ },
3384
+ {
3385
+ Query : "select @a, @b, @c, @d;" ,
3386
+ Expected : []sql.Row {
3387
+ {33 , 110 , 93 , 190 },
3388
+ },
3389
+ },
3390
+ },
3391
+ },
3230
3392
}
3231
3393
3232
3394
var TriggerCreateInSubroutineTests = []ScriptTest {
0 commit comments