Fix query fields being loaded as decimal instead of int

With some DB backends (specifically AWS Postgres RDS) these fields would load as BigDecimal instead of int. This led to
1) versions being displayed as "1.0.2.0" instead of "1.2", and 2) versions with letters (e.g A.0) leading to a 500 error, as BigDecimal#chr doesn't exist
This commit is contained in:
Patrick Skillen 2021-05-06 14:33:16 +01:00
parent 3c66c315c1
commit 74dc3b5b27

View File

@ -199,20 +199,20 @@ class DmsfQuery < Query
scope = Project.select(%{
projects.id AS id,
projects.id AS project_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS revision_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS revision_id,
projects.name AS title,
projects.identifier AS filename,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS size,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS size,
projects.updated_on AS updated,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS major_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS minor_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS major_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS minor_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS workflow,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS workflow_id,
'' AS firstname,
'' AS lastname,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS author,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS author,
'project' AS type,
CAST(0 AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS deleted,
CAST(0 AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS deleted,
0 AS sort #{cf_columns}}).visible
if dmsf_folder_id || deleted
scope.none
@ -230,15 +230,15 @@ class DmsfQuery < Query
scope = DmsfFolder.select(%{
dmsf_folders.id AS id,
dmsf_folders.project_id AS project_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS revision_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS revision_id,
dmsf_folders.title AS title,
NULL AS filename,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS size,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS size,
dmsf_folders.updated_at AS updated,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS major_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS minor_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS major_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS minor_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS workflow,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS workflow_id,
users.firstname AS firstname,
users.lastname AS lastname,
users.id AS author,
@ -275,12 +275,12 @@ class DmsfQuery < Query
dmsf_links.target_id AS revision_id,
dmsf_links.name AS title,
dmsf_folders.title AS filename,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS size,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS size,
COALESCE(dmsf_folders.updated_at, dmsf_links.updated_at) AS updated,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS major_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS minor_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS major_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS minor_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS workflow,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS workflow_id,
users.firstname AS firstname,
users.lastname AS lastname,
users.id AS author,
@ -387,15 +387,15 @@ class DmsfQuery < Query
scope = DmsfLink.select(%{
dmsf_links.id AS id,
dmsf_links.project_id AS project_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS revision_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS revision_id,
dmsf_links.name AS title,
dmsf_links.external_url AS filename,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS size,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS size,
dmsf_links.updated_at AS updated,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS major_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS minor_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow_id,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS major_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS minor_version,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS workflow,
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) AS workflow_id,
users.firstname AS firstname,
users.lastname AS lastname,
users.id AS author,