Edit Databases SQL Query Box Strange Behavior

Ilia,

You mentioned the “integrated phpMyAdmin” here:

So I’ve been testing it – and I noticed a strange behavior when using the “Execute SQL Query” box. I could enter these lines “one at a time” but couldn’t add the entire script all at once or it would fail:

CREATE TABLE `auction_items` (
  `item_id` bigint(20) NOT NULL,
  `item_name` varchar(255) NOT NULL,
  `item_img` varchar(255) DEFAULT NULL,
  `item_desc` text DEFAULT NULL,
  `bid_end` datetime DEFAULT NULL,
  `bid_min` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `auction_items`
  ADD PRIMARY KEY (`item_id`);

ALTER TABLE `auction_items`
  MODIFY COLUMN `item_id` BIGINT(20) NOT NULL AUTO_INCREMENT;

CREATE TABLE `auction_bids` (
  `item_id` bigint(20) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `bid_amount` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `auction_bids`
  ADD PRIMARY KEY (`item_id`, `user_id`),
  ADD KEY `amount` (`bid_amount`);

INSERT INTO `auction_items`
  (`item_name`, `item_img`, `item_desc`, `bid_end`, `bid_min`)
VALUES
  ('An Apple', 'apple.png', 'A very high quality apple, not half eaten.', NULL, '1.5');

Can you tell me why?

Jim

SYSTEM INFORMATION
OS type and version Debian 11
Webmin version Latest
Virtualmin version Latest
Webserver version Apache

Hello,

Did you run it in phpMyAdmin or through Virtualmin?

I got the same issue using Virtualmin not phpMyAdmin.
The solution seems to be save the commands to a .sql file use Run SQL from file.

Seems there is some sort of restriction in the first form as it fails on the second command

ALTER TABLE `auction_items`
  ADD PRIMARY KEY (`item_id`);

Thru Virtualmin…

But, stefan1959 is right… I loaded it from a “file.sql” and it worked.

Because we submit the multiline query as flattened text on a single line and pass it in a single call to the SQL executor, which effectively supports only one statement at a time.


Alright, I’ve dug into the problem and many hours later come up with a solution that works well with both single-line and multi-line queries. It should be much more user-friendly now. Try applying the following patch, give it a try and let me know how it works for you:

webmin patch https://github.com/webmin/webmin/commit/3bd85ab

Worked for me. Nice job.

Thank you so much for putting some care into this issue, I will test it later, I’m under a typhoon at the moment :slight_smile:

Jim