Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1haSCJ-0004Cu-BA for pgadmin-hackers@arkaria.postgresql.org; Mon, 10 Jun 2019 21:51:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1haSCI-00087P-3Y for pgadmin-hackers@arkaria.postgresql.org; Mon, 10 Jun 2019 21:51:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1haSCH-00085n-QO for pgadmin-hackers@lists.postgresql.org; Mon, 10 Jun 2019 21:51:21 +0000 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1haSCD-0005A9-Oq for pgadmin-hackers@postgresql.org; Mon, 10 Jun 2019 21:51:20 +0000 Received: by mail-qk1-x744.google.com with SMTP id l128so6396507qke.2 for ; Mon, 10 Jun 2019 14:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=hBamZJl3KU9Oq6j34vESDQHU9czagtC24W17sOSigiQ=; b=cZl/kVc1zWoP+QKTvic5ja8lhxtyCergNp/zEhtRx+CdsDj6B8VkQ1sWzkBBNbrvNv KHnsLThEVfXhHLZODjxGIPuVK7gzeDF/N4RiWMIP8+dENCKDfRkHGw30R0ESJl4rrUBm 20ybVbujxeRrHy+D8VhyeoTtHpz38HFZBLV/m0Aq9BqgFUFBNQ4MbNM9FkFbxSqaGKiy 8qNNZYkeTeKZt0sHfxN4exEU7rYEwBTyNlqsYlUYG9D/DA85pdy9BYTUfMXU4XawUZdb rtoWYla20W8dyfHuqNThVcJ12aaBOWByjTQ9b5XW3QqeOFEXztb1x3XP1wFNMKtFrfF1 H5ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=hBamZJl3KU9Oq6j34vESDQHU9czagtC24W17sOSigiQ=; b=tk9BiB0vSLpdQONTZqLCwekwo9zi0RVUignRxzX3ObE0ggL9aW0PEKDvXPePi80mva T4x9578VmQjzdoNylHE++XJxrSe3L/Ue5XXnQj3G6r0w18uZq3RMfgeSjf2TR20nF5oX v3ERfKZw6FSlcZEQI/tEszSGvs8k23dK0r4r1D56wSlGBLavnZa1C59gWjUCqMT6RY2o w46ousOQjWctyQ9l6e2w/IvTFplkKuL7mqCFTDU13eAP+wEc6oy4o8vTL/X1RSvaIPD+ /mPKOMXV//iKm8zofYeajh0CZINnqWkla8Q6Ea+l+DT2RUdU1mvi1Dm3hdWR0/t1tg59 Uc7A== X-Gm-Message-State: APjAAAVXzySKtwudn2lNh6GbW5qJlXzrb1q4X9Sw571i0/9PNMsnhROz bINZFbKk+e2Y+JAZnIXtrx+KdeGv5vjj6KjQnIQRFr63Ndg= X-Google-Smtp-Source: APXvYqzREPDttsj50Y5uvazNjaLlL/0DzmaKDnn3VIdGHIFYD3uUw9UO/47efUGiYODP6gBK0zls54Bo1aJUqpi3FjY= X-Received: by 2002:a37:4e92:: with SMTP id c140mr57605367qkb.48.1560203475656; Mon, 10 Jun 2019 14:51:15 -0700 (PDT) MIME-Version: 1.0 From: Yosry Muhammad Date: Mon, 10 Jun 2019 23:51:04 +0200 Message-ID: Subject: [GSoC] Check if a query resultset is update-able To: pgadmin-hackers@postgresql.org Content-Type: multipart/alternative; boundary="000000000000f1a57b058aff2d8f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000f1a57b058aff2d8f Content-Type: text/plain; charset="UTF-8" Dear all, After some research and review of the code, I have arrived at this method to check whether a query resultset is update-able. I would like to know your feedback before I start implementing this technique: - Query results are not be update-able (initially at least) except if all the primary keys are selected and all the columns belong to the same table (no joins or aggregations). - When the query results is ready (polling is successful) I can check the results in the back-end using the transaction connection cursor. - The transaction cursor description attribute includes a list of Column objects, each of which has attributes pointing to its original table in the system catalog table *pg_class* (if available) and its attribute number within the table. [1] - From this information, the system catalog tables *pg_class, pg_attribute *and *pg_constraint *can be queried to check that all the columns belong to a single table and that all the primary keys are available. [2][3][4] - This can be used as an indicator to whether the resultset is updatable (similar to the View Table mode, where tables are only editable if they have primary keys). I will modify the following parts in the code: 1- *web/tools/sqleditor/command.py* QueryToolCommand class will be modified to contain an attribute indicating whether the query results are update-able for the last successful query. 2- A new file will be added in* web/tools/sqleditor/utils/* containing the function that will check if the query results are update-able. 3- *web/tools/sqleditor/__init__.py * The poll endpoint will be modified to check if the results are update-able (in case the results are ready), then the session object primary keys and the transaction object can_edit attribute will be updated (the primary keys are checked in the frontend, if they exist table modifications are allowed). This is the first step, to check if a query resultset is update-able. The upcoming steps will include switching the mode in the frontend to allow for editing the results and checking what options should be enabled or disabled and any needed modifications (I think allowing for only editing and deleting rows makes sense). Sorry for the long email, looking forward to your feedback! [1] http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.Column [2] https://www.postgresql.org/docs/current/catalog-pg-class.html [3] https://www.postgresql.org/docs/current/catalog-pg-attribute.html [4] https://www.postgresql.org/docs/current/catalog-pg-constraint.html -- *Yosry Muhammad Yosry* Computer Engineering student, The Faculty of Engineering, Cairo University (2021). Class representative of CMP 2021. https://www.linkedin.com/in/yosrym93/ --000000000000f1a57b058aff2d8f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Dear all,

After some researc= h and review of the code, I have arrived at this method to check whether a = query resultset is update-able. I would like to know your feedback before I= start implementing this technique:

- Query result= s are not be update-able (initially at least) except if all the primary key= s are selected and all the columns belong to the same table (no joins or ag= gregations).
- When the query results is ready (polling is succes= sful) I can check the results in the back-end using the transaction connect= ion cursor.
- The transaction cursor description attribute includ= es a list of Column objects, each of which has attributes pointing to its o= riginal table in the system catalog table pg_class (if available) an= d its attribute number within the table. [1]
- From this informat= ion, the system catalog tables pg_class, pg_attribute and pg_cons= traint can be queried to check that all the columns belong to a single = table and that all the primary keys are available. [2][3][4]
= - This can be used as an indicator to whether the resultset is updatable (s= imilar to the View Table mode, where tables are only editable if they have = primary keys).

I will modify the following par= ts in the code:
1- web/tools/sqleditor/command.py
QueryToolCommand class will be modified to contain an attribute indic= ating whether the query results are update-able for the last successful que= ry.

2- A new file will be added in web/tools/sq= leditor/utils/ containing the function that will check if the query res= ults are update-able.

3- web/tools/sqleditor/__= init__.py
The poll endpoint will be modified to check if= the results are update-able (in case the results are ready), then the sess= ion object primary keys and the transaction object can_edit attribute will = be updated (the primary keys are checked in the frontend, if they exist tab= le modifications are allowed).

This is the first s= tep, to check if a query resultset is update-able. The upcoming steps will = include switching the mode in the frontend to allow for editing the results= and checking what options should be enabled or disabled and any needed mod= ifications (I think allowing for only editing and deleting rows makes sense= ).

Sorry for the long email, looking forward to yo= ur feedback!

[3] https://www.postgresql.org/docs/current/catalog-pg-attribute.html

--
Yosry Muhammad Yosry

Com= puter Engineering student,
The Faculty= of Engineering,
Cairo University (2021= ).
Class representative of CMP 2021.
--000000000000f1a57b058aff2d8f--