beekeeper-studio icon indicating copy to clipboard operation
beekeeper-studio copied to clipboard

Copy as Sql

Open TimBailey-driva opened this issue 2 years ago • 6 comments

Describe the bug Wen I click "copy as sql" on a table row its generating the sql in column "alphabetical order" rather than "table order". It obviously doesnt matter from a SQL PoV, but feels weird to see the ids etc in the middle of the insert statement. Would this be easy to resolve?

To Reproduce Click "Copy as Sql", then paste

Expected behavior Generated SQL should be in table column order ie in the order they are displayed in the grid (& in the database)

CREATE TABLE
  `statuses` (
    `status_code` smallint NOT NULL,
    `status_description` varchar(50) DEFAULT NULL,
    `external_mappings` json DEFAULT NULL,
    `created_at` datetime DEFAULT NULL,
    PRIMARY KEY (`status_code`) USING BTREE
  ) ENGINE = InnoDB DEFAULT CHARSET = latin1

Screenshots / Gifs image

image

Version Information (please complete the following information):

  • OS: Ubuntu 22.04 LTS
  • App Version: 4.3.1
  • Database type and version: Mysql 8.0.35

TimBailey-driva avatar May 02 '24 04:05 TimBailey-driva

Thanks for reporting! I can see this as a bug. It should be fairly easy to fix given that we've already shown table columns in the correct order.

Fix notes:

  • might be related to connection.getInsertQuery
  • check all databases
  • tests in runCommonTests -> change the queries in getInsertQueryTests or make a new one

azmy60 avatar May 03 '24 12:05 azmy60

@azmy60 the same should apply to #1782

mcanepa avatar May 05 '24 23:05 mcanepa

@ellipsis-dev please implement

rathboma avatar May 10 '24 00:05 rathboma

I'm sorry, but I ran out of time before I could complete the implementation plan. I was able to find where the connection.getInsertQuery and buildInsertQuery functions are defined and how they work. I also found where the tests in runCommonTests are located and how they are structured. However, I was not able to find where the TableInsert objects are created. This information is necessary to modify the buildInsertQuery function to generate SQL in the order of the columns as they appear in the table. I recommend continuing the investigation from this point.

[No tentative implementation steps.]


For more information about Ellipsis, check the documentation.

ellipsis-dev[bot] avatar May 10 '24 00:05 ellipsis-dev[bot]

hey sorry about this @rathboma, we're looking into it

nsbradford avatar May 10 '24 00:05 nsbradford

This is still failing in 4.3.1, is already being deployed?

JuanAraneta avatar May 21 '24 15:05 JuanAraneta