You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'create or replace trigger "untitled_table8_autoinc_trg" BEFORE INSERT on "untitled_table8" for each row declare checking number := 1; begin if (:new."' || PK_NAME || '" is null) then while checking >= 1 loop select "untitled_table8_seq".nextval into :new."' || PK_NAME || '" from dual; select count("' || PK_NAME || '") into checking from "untitled_table8" where "' || PK_NAME || '" = :new."' || PK_NAME || '"; end loop; end if; end;'
153
+
);
154
+
155
+
END;
156
+
`,
157
+
{dialect: 'oracle',strict: true},
158
+
);
159
+
constexpected=[
160
+
{
161
+
end: 1043,
162
+
executionType: 'ANON_BLOCK',
163
+
parameters: [],
164
+
start: 11,
165
+
text: 'DECLARE\n PK_NAME VARCHAR(200);\n\n BEGIN\n EXECUTE IMMEDIATE (\'CREATE SEQUENCE "untitled_table8_seq"\');\n\n SELECT\n cols.column_name INTO PK_NAME\n FROM\n all_constraints cons,\n all_cons_columns cols\n WHERE\n cons.constraint_type = \'P\'\n AND cons.constraint_name = cols.constraint_name\n AND cons.owner = cols.owner\n AND cols.table_name = \'untitled_table8\';\n\n execute immediate (\n \'create or replace trigger "untitled_table8_autoinc_trg" BEFORE INSERT on "untitled_table8" for each row declare checking number := 1; begin if (:new."\' || PK_NAME || \'" is null) then while checking >= 1 loop select "untitled_table8_seq".nextval into :new."\' || PK_NAME || \'" from dual; select count("\' || PK_NAME || \'") into checking from "untitled_table8" where "\' || PK_NAME || \'" = :new."\' || PK_NAME || \'"; end loop; end if; end;\'\n );\n\n END;',
166
+
type: 'ANON_BLOCK',
167
+
},
168
+
];
169
+
expect(actual).to.eql(expected);
170
+
});
171
+
172
+
it('should identify a create table then a block',()=>{
'create or replace trigger "untitled_table8_autoinc_trg" BEFORE INSERT on "untitled_table8" for each row declare checking number := 1; begin if (:new."' || PK_NAME || '" is null) then while checking >= 1 loop select "untitled_table8_seq".nextval into :new."' || PK_NAME || '" from dual; select count("' || PK_NAME || '") into checking from "untitled_table8" where "' || PK_NAME || '" = :new."' || PK_NAME || '"; end loop; end if; end;'
200
+
);
201
+
202
+
END;
203
+
`,
204
+
{dialect: 'oracle',strict: false},
205
+
);
206
+
constexpected=[
207
+
{
208
+
end: 167,
209
+
executionType: 'MODIFICATION',
210
+
parameters: [],
211
+
start: 11,
212
+
text: 'create table\n "untitled_table8" (\n "id" integer not null primary key,\n "created_at" varchar(255) not null\n );',
213
+
type: 'CREATE_TABLE',
214
+
},
215
+
{
216
+
end: 1212,
217
+
executionType: 'ANON_BLOCK',
218
+
parameters: [],
219
+
start: 180,
220
+
text: 'DECLARE\n PK_NAME VARCHAR(200);\n\n BEGIN\n EXECUTE IMMEDIATE (\'CREATE SEQUENCE "untitled_table8_seq"\');\n\n SELECT\n cols.column_name INTO PK_NAME\n FROM\n all_constraints cons,\n all_cons_columns cols\n WHERE\n cons.constraint_type = \'P\'\n AND cons.constraint_name = cols.constraint_name\n AND cons.owner = cols.owner\n AND cols.table_name = \'untitled_table8\';\n\n execute immediate (\n \'create or replace trigger "untitled_table8_autoinc_trg" BEFORE INSERT on "untitled_table8" for each row declare checking number := 1; begin if (:new."\' || PK_NAME || \'" is null) then while checking >= 1 loop select "untitled_table8_seq".nextval into :new."\' || PK_NAME || \'" from dual; select count("\' || PK_NAME || \'") into checking from "untitled_table8" where "\' || PK_NAME || \'" = :new."\' || PK_NAME || \'"; end loop; end if; end;\'\n );\n\n END;',
221
+
type: 'ANON_BLOCK',
222
+
},
223
+
];
224
+
expect(actual).to.eql(expected);
225
+
});
226
+
});
227
+
130
228
describe('identifying multiple statements with CTEs',()=>{
131
229
it('should able to detect queries with a CTE in middle query',()=>{
0 commit comments