1

I have written a small stored procedure to store redmine issue and timelog entries in my private redmine. The procedure is stored, but when I call it, it gives SQL error (1054): Unknown column 'uid' in 'field list' error. The column that the error message mention is exists, the type matches.

Rewrite code, redeploy db

When the second insert removed from SP, it works great.

delimiter $$
DROP PROCEDURE if exists redmine.insert_fingerprint_workday_and_hour $$

CREATE DEFINER=`root`@`%` PROCEDURE `insert_fingerprint_workday_and_hour`(
    IN `userid` INT(11) )
LANGUAGE SQL
NOT DETERMINISTIC
MODIFIES SQL DATA
SQL SECURITY DEFINER
COMMENT ''

BEGIN

set @uid=userid;

INSERT INTO issues (
tracker_id,
project_id,
subject,
description,
due_date,
category_id,
status_id,
assigned_to_id,
priority_id,
fixed_version_id,
author_id,
lock_version,
created_on,
updated_on,
start_date,
done_ratio,
estimated_hours,
parent_id,
root_id,
lft,
rgt,
is_private,
closed_on ) 
 VALUES
(
  "4",                      -- tracker id
  "1",                          -- project id
  "teszt subject",      -- subject  
  "teszt description",  -- description 
  NULL,                         -- due_date
  NULL,                         -- category_id
  "7",                          -- status id
  uid,              -- assigned_to_id
  "2",                          -- priority_id
  NULL,                     -- fixed_version_id
  uid,                  --  author_id
  "0",                          -- lock_version
  NOW(),                    -- created_on
  NOW(),                        -- updated_on
  date(now()),              -- start_date
  "0",                      -- done_ratio
  NULL,                     -- estimated_hours
  NULL,                     -- parent_id
  "1",                      -- root_id
  "1",                      -- lft
  "2",                      -- rgt
  "0",                      -- is_private
  now()                     -- closed_on
  );

  set @ujissue=LAST_INSERT_ID();

  insert into time_entries 
  (project_id,user_id,issue_id,hours,activity_id,spent_on,tyear,tmonth,tweek,created_on,updated_on)
  values
  (
  "1",                      -- project_id
  uid,                  -- user_id
  ujissue,                  -- issue_id
  "8",                      -- hours
  "10",                     -- activity_id
  date(now()),              -- spent_on
  year(now()),              -- tyear
  month(now()),         -- tmonth
  week(now()),              -- tweek
  now(),                        -- created_on
  now()
  );

  END $$

  DELIMITER ;

SQL> CALL redmine.insert_fingerprint_workday_and_hour('7');
/* SQL error (1054): Unknown column 'uid' in 'field list' */

The only input is a number, a user_id. The code should add an issue to a project and log 8 workhours. The first insert adds the issue to the project and a second logs the hours.

After hours of debugging I cannot figure out what can be the problem.

All advice is welcome!

Thanks, Peter

EternalHour
  • 8,308
  • 6
  • 38
  • 57
repi
  • 13
  • 2

1 Answers1

0

In MySQL, variables with the @ sigil are session variables, not local variables. Session variables are different from local variables, even if they have the same name other than the @ sigil.

See also a few of my past answers on this:

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • Thank you, I have rewritten my code based on your clear instructions, now its working. – repi Sep 23 '19 at 22:52