[pgAdmin][RM4381] Problem with data editing when using "View/Edit Data" to tables with OID

Aditya Toshniwal <[email protected]>
Newsgroups gmane.comp.db.postgresql.pgadmin.devel
Message-ID <CAM9w-_=i4rqeCLgsN90WXtrMqS+zCYudHVhOeCbhaPr9Ys+-9A@mail.gmail.com>
Hi Hackers,

Attached is the patch to fix an issue where, oid column should not be
pasted when copy/paste row is used on query output containing the oid
column.

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"
RM4381.patch (application/octet-stream, 2.5 KB)
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index 82ceb3f5..905f8422 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -3712,6 +3712,10 @@ define('tools.querytool', [
             new_row.is_row_copied = true;
             self.temp_new_rows.push(count);
             new_row[self.client_primary_key] = _key;
+            if(self.has_oids && new_row.oid) {
+              new_row.oid = null;
+            }
+
             dataView.addItem(new_row);
             self.data_store.added[_key] = {
               'err': false,
diff --git a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py
index 12df12e4..cdfdc211 100644
--- a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py
+++ b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py
@@ -98,7 +98,6 @@ def save_changed_data(changed_data, columns_info, conn, command_obj,
             # of not null which is set by default.
             column_data = {}
             pk_names, primary_keys = command_obj.get_primary_keys()
-            has_oids = 'oid' in column_type
 
             for each_row in added_index:
                 # Get the row index to match with the added rows
@@ -109,6 +108,10 @@ def save_changed_data(changed_data, columns_info, conn, command_obj,
                 data.pop(client_primary_key, None)
                 data.pop('is_row_copied', None)
 
+                # Remove oid col
+                if command_obj.has_oids():
+                    data.pop('oid', None)
+
                 # Update columns value with columns having
                 # not_null=False and has no default value
                 column_data.update(data)
@@ -122,7 +125,7 @@ def save_changed_data(changed_data, columns_info, conn, command_obj,
                     nsp_name=command_obj.nsp_name,
                     data_type=column_type,
                     pk_names=pk_names,
-                    has_oids=has_oids
+                    has_oids=command_obj.has_oids()
                 )
 
                 select_sql = render_template(
@@ -130,7 +133,7 @@ def save_changed_data(changed_data, columns_info, conn, command_obj,
                     object_name=command_obj.object_name,
                     nsp_name=command_obj.nsp_name,
                     primary_keys=primary_keys,
-                    has_oids=has_oids
+                    has_oids=command_obj.has_oids()
                 )
 
                 list_of_sql[of_type].append({
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.