Menu

Update query

2006-10-02
2013-04-03
  • Kern Herskind Hansen

    I need to do an update query, in the form of:

    "UPDATE table SET column = column + (x) WHERE id = (y)"

    I have tried retrieving the object, adding to the count, and then re persist the object. But because the app is running in a web garden setup, the persists overwrite eachother! I tried clearing the cache before reading the values - but that not good enough, because the threads in the app write back there "count" in a syncronized maner (all at the same time).

    Is there a way to construct the described query with the SqlBuilder? (I'm running Gentle.Net 1.1.3 as far as I can tell)

    Best regards,
    Kern Herskind Hansen

     
    • Morten Mertner

      Morten Mertner - 2006-10-10

      First off, you really should upgrade to 1.2.9. It has lots of new features, and lots of bugs have been fixed since 1.1.3.

      The query you mention is, unfortunately, beyond the capabilities of SqlBuilder. However, you may be able to cheat a bit a still reuse some of its work.

      Specifically, assuming you have a class with properties "column" and "id", the latter being the PK, asking SqlBuilder to create an update query will produce an SqlStatement whose SQL liiks something like: "update table set column = @p1 where id = @p2;".

      You can now do "SqlStatement.Command.CommandText = SqlStatement.Command.CommandText.Replace( "column =", "column = column +" );" and still get to use the parameter creation logic, etc.

      Alternatively, write your statement by hand and wrap it in an SqlStatement instance manually.

       

Log in to post a comment.