Sunday, May 1, 2011

Can i reuse bind variable in an 'insert ... on duplicate update ...' statement?

I am attempting to run a query that uses bind variables against a mysql database engine. I am wondering how I can tell the engine to "reset" the bind variable assignments. I'm sure an example will explain much better than my poor brain.

Here is the query:

INSERT INTO site_support_docs
      (
          ASSET_ID,
          TIME_STAMP,
          SITE_NAME,
          DOCUMENT_NAME,

          DOCUMENT_LOCATION,

          DOCUMENT_CONTENT,

          DOCUMENT_LAST_MODIFIED

      )

VALUES (?, ?, ?, ?, ?, ?, STR_TO_DATE(?, '%M %e, %Y %r'))

ON DUPLICATE KEY UPDATE asset_id   = ?,

                        time_stamp   = ?,

                        site_name   = ?,

                        document_name   = ?,

                        document_location   = ?,

                        document_content   = ?,

                        document_last_modified   =

                           STR_TO_DATE(?, '%M %e, %Y %r')

My problem is that the eighth "?" is interpreted as a new bind variable when there are only seven. Anyway, I guess I can revert to using the actual values... but, I'm sure there is a better way.

Thanks for taking your time to look at this with me!

Matt

From stackoverflow

0 comments:

Post a Comment