Skip to content

H2Command: Unprocessed variable bug in prepared statement #5

Description

@GoogleCodeExporter
What steps will reproduce the problem?
1. H2Command updateCommand = new H2Command("UPDATE MyTable SET MyCol1 = @var1, 
MyCol2 = @var2 WHERE MyCol3 = @var3", connection);

What is the expected output? What do you see instead?

EXPECTED:
UPDATE MyTable SET MyCol1 = ?, MyCol2 = ? WHERE MyCol3 = ?

ACTUAL:
UPDATE MyTable SET MyCol1 = ?, MyCol2 = ? WHERE MyCol3 =

(notice the missing last "?")

What version of the product are you using? On what operating system?
H2 1.3.160
h2sharp as downloaded from the svn trunk last week (r24)
Windows 7 64bit
Visual C# Express 2010

Please provide any additional information below.

Here's the fix:
In H2Command.cs, function 
private PreparedTemplate CreateNameTemplate()

add the following after the "for" loop

if (name.Length > 0)
{
  // This is the last param that was left unprocessed
  command.Append('?');
  string paramName = name.ToString();
  int paramIndex = collection.FindIndex(delegate(H2Parameter p) { return p.ParameterName == paramName; });
  if (paramIndex == -1) { throw new H2Exception(string.Format("Missing Parameter: {0}", paramName)); }
  list.Add(paramIndex);
}

This is basically a copy/paste of the code in the above loop. Probably it can 
be optimized but I just wanted to get unblocked asap.

Original issue reported on code.google.com by androidd...@gmail.com on 29 Oct 2011 at 8:56

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions