Apostrophe and UPDATE

Paul Foraker paul.foraker at gmail.com
Wed Oct 9 03:55:13 EDT 2013


Stephen,  escaping the single quote with another quote causes the same
error, with the result showing \'\' instead of \'.  I tried it with and
without variable substitution.

Monte, my UPDATE syntax was incorrect. Thanks!

In case anyone else needs something like this, here's the code that worked:

<code>
on testWrap
   put the fldNames of this cd into tFldNames
   delete item 1 of tFldNames -- contact_id
   put getSQLWrappers("contact",tFldNames) into temp
   answer temp
end testWrap

function getSQLwrappers pTableName, pFldNames
   -- takes a list of field names and returns them wrapped for SQL
   -- removes "_" in fld names, prepends "t" and uses CamelCase
   -- so "last_name" becomes tLastName
   put "UPDATE" && pTableName && "SET " into tSQL
   repeat for each item thisOne in pFldNames
      put thisOne &&"= '" & varNameFromFldName(thisOne) & "', " after tSQL
   end repeat
   delete last char of tSQL -- remove last chars
   delete last char of tSQL
   put " WHERE id = '" &tID &"'" after tSQL
   return tSQL
end getSQLwrappers

function varNameFromFldName pFldName
   set itemDelimiter to "_"
   put "t" into varName
   repeat for each item thisOne in pFldName
      put toUpper(char 1 of thisOne) into char 1 of thisOne
      put thisOne after varName
   end repeat
   return varName
end varNameFromFldName
</code>

-- Paul



More information about the use-livecode mailing list