Work on bugs - phppgadmin

    One of our clients set a task - the database dump is not poured through phpPgAdmin. Messages such as: ERROR: relation "public". "Company" does not exists are displayed in the error log.

    There is a public schema available, no company table. During the search, it turns out that through the console the same dump is poured without problems. If you upload to a web-form in phpPgAdmin, then everything also works. But if you load this dump into the same phpPgAdmin as a file, then there are errors.

    Here is the abbreviated contents of the database dump:

    DROP TABLE IF EXISTS "public"."company";
    CREATE TABLE "public"."company" (
    "id" int4 NOT NULL,
    "name" varchar(255) COLLATE "default" NOT NULL,
    "address" varchar(255) COLLATE "default",
    COMMENT ON COLUMN "public"."company"."name" IS 'название';
    COMMENT ON COLUMN "public"."company"."address" IS 'адрес';
    -- ----------------------------
    -- Records of company
    -- ----------------------------
    INSERT INTO "public"."company" VALUES ('1', 'Колхоз "Знамя Ильича"', 'Московская область, Коломенский район, с. Нелепецино');

    The unusual location of the semicolon after the command to create the table catches the eye - on a separate line.

    If you transfer it from a separate line to a line with the end of the CREATE TABLE command, then processing the file with a database dump will work without problems.

    Searching the phpPgAdmin code leads us to the /classes/database/Postgres.php file executeScript function

    This function is called to parse the downloaded file with SQL script. It contains a bug with braces in if. And in the end, pg_query did not execute if the line started with a semicolon. Corrected the code, tested it - everything works.

    Now you need to report the found bug to the phpPgAdmin author. phppgadmin is on the github, so it’s very easy to do:

    Go / register on
    We look at the open pull request and see that we are not alone.
    There are other people who have encountered this bug, but, in my opinion, incorrectly approached to fix it.
    Therefore, we will offer our solution to the problem.

    Press the Fork button on the right and wait a little while the github copies the project to you.
    We are now cloning a project on our own
    git clone

    We fix the bug, commit, push (enter your login details for github) and admire our own fork phppgadmin with the bug fixed.

    After stopping in, we click on the green button “Compare, review, create a pull request”. The github creates a request for changes to the main project, and here comes the most difficult thing - to write a detailed comment for your patch.

    I got something like this:

    Also popular now: