Question:
How to add records to the PostgreSql table using SqlRequest function block?
Answer:
Example of adding a record to a PostgreSQL database table using the SqlRequest function block (hereinafter referred to as SqlRequest).
A test project is attached (see PostgreInsert.7z)
1. Create the "distributors" table in the database (hereinafter referred to as DB) (in this example, the DB name is "mps1") by executing the following instruction:
-- Table: public.distributors
DROP TABLE IF EXISTS public.distributors;
CREATE TABLE IF NOT EXISTS public.distributors
(
did integer NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
dname character varying(40) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT distributors_pkey PRIMARY KEY (did),
CONSTRAINT distributors_name_check CHECK (dname::text <> ''::text)
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.distributors
OWNER to postgres;
2. Establish a connection from the MasterScada 4D project to the PostgreSQL server
2.1. Add a Workstation, for example, Workstation1.
2.2. Add the PostgreSQL protocol to Workstation1.
2.3. Configure the Protocol properties for connecting to the DB:
- did, type UDINT;
- dname, type STRING.
5. Add the SqlRequest instance from the local library to the created program.
6. Set the program parameters and link them to the SqlRequest parameters:
8. Set the values for the 'pdid' and 'pdname' parameters.
10. Check the result in the DB
How to add records to the PostgreSql table using SqlRequest function block?
Answer:
Example of adding a record to a PostgreSQL database table using the SqlRequest function block (hereinafter referred to as SqlRequest).
A test project is attached (see PostgreInsert.7z)
1. Create the "distributors" table in the database (hereinafter referred to as DB) (in this example, the DB name is "mps1") by executing the following instruction:
-- Table: public.distributors
DROP TABLE IF EXISTS public.distributors;
CREATE TABLE IF NOT EXISTS public.distributors
(
did integer NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
dname character varying(40) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT distributors_pkey PRIMARY KEY (did),
CONSTRAINT distributors_name_check CHECK (dname::text <> ''::text)
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.distributors
OWNER to postgres;
2. Establish a connection from the MasterScada 4D project to the PostgreSQL server
2.1. Add a Workstation, for example, Workstation1.
2.2. Add the PostgreSQL protocol to Workstation1.
2.3. Configure the Protocol properties for connecting to the DB:
- did, type UDINT;
- dname, type STRING.
5. Add the SqlRequest instance from the local library to the created program.
6. Set the program parameters and link them to the SqlRequest parameters:
8. Set the values for the 'pdid' and 'pdname' parameters.
10. Check the result in the DB
Обсуждение
Log in or register to participate in the discussion.