Bug 139600 - Error when trying to use parameter for LIMIT in a query
Summary: Error when trying to use parameter for LIMIT in a query
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
6.4.5.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-14 10:04 UTC by Diego
Modified: 2023-07-14 05:59 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
"partial" test bench with HSQLDB embedded database (14.96 KB, application/vnd.oasis.opendocument.database)
2021-01-14 11:01 UTC, Diego
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Diego 2021-01-14 10:04:38 UTC
I have a bacula installation (mariadb based) I connect correctely with dbbeaver via JDBC and also with libreofficebase. I finally have to implement this query written via SQL:
SELECT 
   MediaId
  ,VolumeName 
  ,Slot
  ,VolStatus
  ,Enabled
  ,VolBytes
  ,VolFiles
  ,VolRetention
  ,Recycle
  ,MediaType
  ,VolType
  ,VolParts
  ,LastWritten
  ,ExpiresIn FROM 
  (
       SELECT 
	   MediaId
	  ,CAST(VolumeName AS VARCHAR(20)) AS VolumeName
	  ,VolStatus
	  ,Enabled
	  ,VolByte
	  ,VolFiles
	  ,VolRetention
	  ,Recycle
	  ,CONCAT ( CASE
	              WHEN Slot < 13 THEN 'Left '
	              ELSE 'Right '
	            END 
	           , Slot ) AS Slot
	  ,CAST( MediaType AS VARCHAR(10)) AS MediaType
	  ,VolType
	  ,VolParts
	  ,LastWritten
	  ,GREATEST(
             0
            , CAST(UNIX_TIMESTAMP(LastWritten) AS INTEGER)
            + CAST(VolRetention AS INTEGER)
            - CAST(UNIX_TIMESTAMP(NOW()) AS INTEGER)) AS ExpiresIn
	FROM Media WHERE 
	 InChanger = 1
	ORDER by ExpiresIn DESC LIMIT :ask
) AS InsiemeNastri
ORDER BY Slot 

The problem is:
If I save the query "as is" or try to run, it fail with a "SQL Syntax Error". If I substitute the ":ask" parameter with a number (e.g. 6) It works and I can run the query correctly. If I try to view it in "design mode" it fails with "SQL Error". I'm going to port the error in hsqldb so I can add the attachment to this bug
Comment 1 Diego 2021-01-14 11:01:03 UTC
Created attachment 168872 [details]
"partial" test bench with HSQLDB embedded database

Here it is the document I promised... the problem is that Here I have another kind of problem as Here, when I try to run the query obtain:

Accesso negato: GREATEST in statement [SELECT "MediaId", "VolumeName", "Slot", "VolStatus", "Enabled", "VolBytes", "VolFiles", "VolRetention", "Recycle", "MediaType", "VolType", "VolParts", "LastWritten", "ExpiresIn" FROM ( SELECT "MediaId", CAST( "VolumeName" AS VARCHAR ( 20 ) ) AS "VolumeName", "VolStatus", "Enabled", "VolByte", "VolFiles", "VolRetention", "Recycle", CONCAT( CASE WHEN "Slot" < 13 THEN 'Left ' ELSE 'Right ' END, "Slot" ) AS "Slot", CAST( "MediaType" AS VARCHAR ( 10 ) ) AS "MediaType", "VolType", "VolParts", "LastWritten", GREATEST( 0, CAST( UNIX_TIMESTAMP( "LastWritten" ) AS INTEGER ) + CAST( "VolRetention" AS INTEGER ) - CAST( UNIX_TIMESTAMP( NOW( ) ) AS INTEGER ) ) AS "ExpiresIn" FROM "Media2createdmanually" WHERE "InChanger" = 1 ORDER BY "ExpiresIn" DESC LIMIT 6 ) AS "InsiemeNastri" ORDER BY "Slot"]

Other 2 things, here it is the table definition under MariaDB:
CREATE TABLE `Media` (
  `MediaId` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `VolumeName` tinyblob NOT NULL,
  `Slot` int(11) DEFAULT 0,
  `PoolId` int(10) unsigned DEFAULT 0,
  `MediaType` tinyblob NOT NULL,
  `MediaTypeId` int(10) unsigned DEFAULT 0,
  `LabelType` tinyint(4) DEFAULT 0,
  `FirstWritten` datetime DEFAULT NULL,
  `LastWritten` datetime DEFAULT NULL,
  `LabelDate` datetime DEFAULT NULL,
  `VolJobs` int(10) unsigned DEFAULT 0,
  `VolFiles` int(10) unsigned DEFAULT 0,
  `VolBlocks` int(10) unsigned DEFAULT 0,
  `VolMounts` int(10) unsigned DEFAULT 0,
  `VolBytes` bigint(20) unsigned DEFAULT 0,
  `VolType` int(10) unsigned DEFAULT 0,
  `VolErrors` int(10) unsigned DEFAULT 0,
  `VolWrites` bigint(20) unsigned DEFAULT NULL,
  `VolCapacityBytes` bigint(20) unsigned DEFAULT 0,
  `VolStatus` enum('Full','Archive','Append','Recycle','Purged','Read-Only','Disabled','Error','Busy','Used','Cleaning') NOT NULL,
  `Enabled` tinyint(4) DEFAULT 1,
  `Recycle` tinyint(4) DEFAULT 0,
  `ActionOnPurge` tinyint(4) DEFAULT 0,
  `VolRetention` bigint(20) unsigned DEFAULT 0,
  `VolUseDuration` bigint(20) unsigned DEFAULT 0,
  `MaxVolJobs` int(10) unsigned DEFAULT 0,
  `MaxVolFiles` int(10) unsigned DEFAULT 0,
  `MaxVolBytes` bigint(20) unsigned DEFAULT 0,
  `InChanger` tinyint(4) DEFAULT 0,
  `StorageId` int(10) unsigned DEFAULT 0,
  `DeviceId` int(10) unsigned DEFAULT 0,
  `MediaAddressing` tinyint(4) DEFAULT 0,
  `VolReadTime` bigint(20) unsigned DEFAULT 0,
  `VolWriteTime` bigint(20) unsigned DEFAULT 0,
  `EndFile` int(10) unsigned DEFAULT 0,
  `EndBlock` int(10) unsigned DEFAULT 0,
  `LocationId` int(10) unsigned DEFAULT 0,
  `RecycleCount` int(10) unsigned DEFAULT 0,
  `InitialWrite` datetime DEFAULT NULL,
  `ScratchPoolId` int(10) unsigned DEFAULT 0,
  `RecyclePoolId` int(10) unsigned DEFAULT 0,
  `Comment` blob DEFAULT NULL,
  `VolABytes` bigint(20) unsigned DEFAULT 0,
  `VolAPadding` bigint(20) unsigned DEFAULT 0,
  `VolHoleBytes` bigint(20) unsigned DEFAULT 0,
  `VolHoles` int(10) unsigned DEFAULT 0,
  `VolParts` int(11) DEFAULT 0,
  `VolCloudParts` int(11) DEFAULT 0,
  `LastPartBytes` bigint(20) DEFAULT 0,
  `CacheRetention` bigint(20) DEFAULT 0,
  PRIMARY KEY (`MediaId`),
  UNIQUE KEY `inx8` (`VolumeName`(128)),
  KEY `PoolId` (`PoolId`)
) ENGINE=MyISAM AUTO_INCREMENT=121 DEFAULT CHARSET=latin1

And Here it is my translation:
CREATE TABLE "Media" (
  "MediaId" int  GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  "VolumeName" varbinary NOT NULL,
  "Slot" int DEFAULT 0,
  "PoolId" int  DEFAULT 0,
  "MediaType" varbinary NOT NULL,
  "MediaTypeId" int  DEFAULT 0,
  "LabelType" int DEFAULT 0,
  "FirstWritten" datetime DEFAULT NULL,
  "LastWritten" datetime DEFAULT NULL,
  "LabelDate" datetime DEFAULT NULL,
  "VolJobs" int  DEFAULT 0,
  "VolFiles" int DEFAULT 0,
  "VolBlocks" int DEFAULT 0,
  "VolMounts" int DEFAULT 0,
  "VolBytes" bigint  DEFAULT 0,
  "VolType" int  DEFAULT 0,
  "VolErrors" int  DEFAULT 0,
  "VolWrites" bigint  DEFAULT NULL,
  "VolCapacityBytes" bigint  DEFAULT 0,
  "VolStatus" varchar(50)  NOT NULL,
  "Enabled" tinyint DEFAULT 1,
  "Recycle" tinyint DEFAULT 0,
  "ActionOnPurge" tinyint DEFAULT 0,
  "VolRetention" bigint  DEFAULT 0,
  "VolUseDuration" bigint  DEFAULT 0,
  "MaxVolJobs" int  DEFAULT 0,
  "MaxVolFiles" int  DEFAULT 0,
  "MaxVolBytes" bigint  DEFAULT 0,
  "InChanger" tinyint DEFAULT 0,
  "StorageId" int  DEFAULT 0,
  "DeviceId" int  DEFAULT 0,
  "MediaAddressing" tinyint DEFAULT 0,
  "VolReadTime" bigint DEFAULT 0,
  "VolWriteTime" bigint DEFAULT 0,
  "EndFile" int DEFAULT 0,
  "EndBlock" int DEFAULT 0,
  "LocationId" int DEFAULT 0,
  "RecycleCount" int DEFAULT 0,
  "InitialWrite" datetime DEFAULT NULL,
  "ScratchPoolId" int DEFAULT 0,
  "RecyclePoolId" int DEFAULT 0,
  "Comment" varbinary DEFAULT NULL,
  "VolABytes" bigint DEFAULT 0,
  "VolAPadding" bigint DEFAULT 0,
  "VolHoleBytes" bigint DEFAULT 0,
  "VolHoles" int DEFAULT 0,
  "VolParts" int DEFAULT 0,
  "VolCloudParts" int DEFAULT 0,
  "LastPartBytes" bigint DEFAULT 0,
  "CacheRetention" bigint DEFAULT 0,
   Constraint CK_VolStatus CHECK ( "VolStatus" in ('Full','Archive','Append','Recycle','Purged','Read-Only','Disabled','Error','Busy','Used','Cleaning'))
);
Comment 2 Robert Großkopf 2021-07-13 19:43:01 UTC
Have tried it with the attached database. You could get the buggy behavior with this query:

SELECT * FROM "Media2createdmanually" LIMIT :ask

Seems parameter in Base couldn't be used with LIMIT.
LIMIT is introduced in Base GUI with version LO 4.1. Could be the reason the parameter input hasn't been implemented for this function. It will give an error in
/home/buildslave/source/libo-core/dbaccess/source/core/api/SingleSelectQueryComposer.cxx:109

Tested with LO 7.1.5.1 on OpenSUSE 15.2 64bit rpm Linux.
Comment 3 QA Administrators 2023-07-14 03:14:13 UTC Comment hidden (obsolete)
Comment 4 Robert Großkopf 2023-07-14 05:59:58 UTC
Bug still exists in LO 7.6.0.1 on OpenSUS 15.4 64bit rpm Linux