CommandHelper

CommandHelper

46.5k Downloads

query() dropping first result value from its returned array.

LadyCailinBot opened this issue ยท 2 comments

commented

CMDHELPER-2825 - Reported by CyaNox

{code:title=alias}
/testsql2 = >>>
@key = '123testing'
@value = 'some123value'
@Result = query('testing', 'REPLACE INTO storage SET key=?, value=?', @key, @value)
console(@Result)
@Result = query('testing', 'SELECT value FROM storage WHERE key=?', @key)
console(@Result)
@Result = query('testing', 'SELECT * FROM storage WHERE key=?', @key)
console(@Result)
<<<

{code:title=Actual console output}
>testsql2
20:22:37 [INFO] CH: Running original command from a MCCommandSender ----> /testsql2
20:22:37 [INFO] CommandHelper: null
20:22:37 [INFO] CommandHelper: {{}}
20:22:37 [INFO] CommandHelper: {{key: 123testing}}

{code:title=Expected console output}

testsql2
20:22:37 [INFO] CH: Running original command from a MCCommandSender ----> /testsql2
20:22:37 [INFO] CommandHelper: null
20:22:37 [INFO] CommandHelper: {{value: some123value}}
20:22:37 [INFO] CommandHelper: {{key: 123testing, value: some123value}}


I believe the following line in the source code is in error:
https://github.com/sk89q/commandhelper/blob/master/src/main/java/com/laytonsmith/core/functions/SQL.java#L117

for(int i = 1; i <= md.getColumnCount(); i++){

and probably should be:

for(int i = 1; i < md.getColumnCount(); i++){

I may be wrong though, but this looks to me the most obvious line that could cause the misbehavior.
commented

Comment by LadyCailin

No, that line has to do with the columns, not the rows. This appears to be working for me, so I need more information. Do "mysql -D --user= --password --execute 'SELECT value FROM storage WHERE key="123testing";'" from the command line, then immediately run it from CH and see if they're the same value or not. Regardless, it seems to be working for me.

commented

Comment by CyaNox

A column is what is missing not a row so I think the highlighted line is probably the cause.

As per request the test:

Direct mysql query:

# echo 'SELECT `value` FROM storage WHERE `key`="123testing";'|mysql -D newmc --user=newmc --password=...; date
value
some123value
Mon Nov 25 18:12:21 CET 2013

Alias:

/testsql2 = >>>
  @key = '123testing'
  @result = query('testing', 'SELECT `value` FROM `storage` WHERE `key`=?', @key)
  console(@result)
<<<

Results:

>testsql2
18:12:26 [INFO] CH: Running original command from a MCCommandSender ----> /testsql2
18:12:26 [INFO] CommandHelper: {{}}

Table structure:

CREATE TABLE IF NOT EXISTS `storage` (
  `key` varchar(255) CHARACTER SET utf8 NOT NULL,
  `value` text CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `storage` (`key`, `value`) VALUES
('123testing', 'some123value');