📜 ⬆️ ⬇️

Bug fixes - phppgadmin

One of our clients set the task - do not fill the database dump via phpPgAdmin. Errors are displayed in the error log: ERROR: relation “public.” “Company” does not exist.

The public scheme is available, there is no company table. During the search, it turns out that the same dump is poured through the console without any problems. If you upload to a web form in phpPgAdmin, it also works out everything. But if you upload this dump to the same phpPgAdmin file, 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", ) WITH (OIDS=FALSE) ; 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 semicolon after the command to create a table - on a separate line is striking the eye.
')
If you move it from a separate line to a line with the end of the CREATE TABLE command, then the processing of the file with the database dump passes without problems.

A search by phpPgAdmin code leads us to the file /classes/database/Postgres.php function executeScript

This function is called to parse the loaded file with the SQL script. It has a bug with the arrangement of curly braces in if. As a result, pg_query was not executed if the line began with a semicolon. Corrected the code, tested it - everything works.

Now you need to report the found bug to the author of phpPgAdmin. phppgadmin is on a githaba, so it's very easy to do this:

Go / register at github.com.
Project github.com/phppgadmin/phppgadmin
We look at the open pull request and see that we are not alone.
There are other people who are faced with this bug, but, in my opinion, wrong approach to correcting it.
Therefore, we offer our solution

Click on the right Fork button and wait a bit while the github copies the project to you.
We clone the project from now
 git clone https://github.com/LuckySB/phppgadmin 

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

After they have admired - click on the green button “Compare, review, create a pull request”. Github creates a request for changes to the main project, and here comes the most difficult thing - to write a detailed commentary to your patch.

I did something like this: github.com/phppgadmin/phppgadmin/pull/30

Source: https://habr.com/ru/post/257967/


All Articles