Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static analysis enhancement #72

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@
"type": "object",
"description": "If set, migrations will be applied for all analyses. If the current file is a migration file, execution will run until the previous migration."
},
"plpgsqlLanguageServer.plpgsqlCheckSchema": {
"scope": "resource",
"type": "string",
"description": "Schema where plpgsql_check is installed."
},
"plpgsqlLanguageServer.enableExecuteFileQueryCommand": {
"scope": "resource",
"type": "boolean",
Expand Down
24 changes: 24 additions & 0 deletions sample/definitions/trigger/static_error_disabled.pgsql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
DROP TABLE IF EXISTS users_2 CASCADE;

CREATE TABLE users_2 (
id integer not null PRIMARY KEY
);

create or replace function update_updated_at_column ()
returns trigger
language plpgsql
as $function$
begin
new.updated_at = NOW();
return new;
end;
$function$;

-- plpgsql-language-server:disable-static
create trigger update_users_2_modtime_disabled -- error silenced
before update on users_2 for each row
execute function update_updated_at_column ();

create trigger update_users_2_modtime -- should raise error
before update on users_2 for each row
execute function update_updated_at_column ();
184 changes: 184 additions & 0 deletions sample/definitions/trigger/static_error_disabled.pgsql.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
[
{
"RawStmt": {
"stmt": {
"DropStmt": {
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "users_2"
}
}
]
}
}
],
"removeType": "OBJECT_TABLE",
"behavior": "DROP_CASCADE",
"missing_ok": true
}
},
"stmt_len": 36
}
},
{
"RawStmt": {
"stmt": {
"CreateStmt": {
"relation": {
"relname": "users_2",
"inh": true,
"relpersistence": "p"
},
"tableElts": [
{
"ColumnDef": {
"colname": "id",
"typeName": {
"names": [
{
"String": {
"str": "pg_catalog"
}
},
{
"String": {
"str": "int4"
}
}
],
"typemod": -1
},
"is_local": true,
"constraints": [
{
"Constraint": {
"contype": "CONSTR_NOTNULL"
}
},
{
"Constraint": {
"contype": "CONSTR_PRIMARY"
}
}
]
}
}
],
"oncommit": "ONCOMMIT_NOOP"
}
},
"stmt_len": 60
}
},
{
"RawStmt": {
"stmt": {
"CreateFunctionStmt": {
"replace": true,
"funcname": [
{
"String": {
"str": "update_updated_at_column"
}
}
],
"returnType": {
"names": [
{
"String": {
"str": "trigger"
}
}
],
"typemod": -1
},
"options": [
{
"DefElem": {
"defname": "language",
"arg": {
"String": {
"str": "plpgsql"
}
},
"defaction": "DEFELEM_UNSPEC"
}
},
{
"DefElem": {
"defname": "as",
"arg": {
"List": {
"items": [
{
"String": {
"str": "\nbegin\n new.updated_at = NOW();\n return new;\nend;\n"
}
}
]
}
},
"defaction": "DEFELEM_UNSPEC"
}
}
]
}
},
"stmt_len": 171
}
},
{
"RawStmt": {
"stmt": {
"CreateTrigStmt": {
"trigname": "update_users_2_modtime_disabled",
"relation": {
"relname": "users_2",
"inh": true,
"relpersistence": "p"
},
"funcname": [
{
"String": {
"str": "update_updated_at_column"
}
}
],
"row": true,
"timing": 2,
"events": 16
}
},
"stmt_len": 195
}
},
{
"RawStmt": {
"stmt": {
"CreateTrigStmt": {
"trigname": "update_users_2_modtime",
"relation": {
"relname": "users_2",
"inh": true,
"relpersistence": "p"
},
"funcname": [
{
"String": {
"str": "update_updated_at_column"
}
}
],
"row": true,
"timing": 2,
"events": 16
}
},
"stmt_len": 148
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
DROP TABLE IF EXISTS users_1 CASCADE;
DROP TABLE IF EXISTS users_2 CASCADE;
DROP TABLE IF EXISTS users_3 CASCADE;

CREATE TABLE users_1 (
id integer not null PRIMARY KEY,
updated_at timestamp with time zone not null DEFAULT now()
);
CREATE TABLE users_2 (
id integer not null PRIMARY KEY
);
CREATE TABLE users_3 (
id integer not null PRIMARY KEY
);

create or replace function update_updated_at_column ()
returns trigger
language plpgsql
as $function$
begin
new.updated_at = NOW();
return new;
end;
$function$;

create trigger update_users_3_modtime -- should raise error
before update on users_3 for each row
execute function update_updated_at_column ();

create trigger update_users_1_modtime
before update on users_1 for each row
execute function update_updated_at_column ();

create trigger update_users_2_modtime -- should raise error
before update on users_2 for each row
execute function update_updated_at_column ();
Loading