Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Elegant ideas someone?

 [1/3] from: kpeters:otaksoft at: 11-Aug-2007 16:21


In the function below (intended to be used with Nenad's MySQL driver) the newvalue & keyvalue may need to be framed by single quotes depending on the datatype one passes in. As newbie, I have found a rather dumb and lengthy solution that works. What I am after is an elegant, REBOL-esque way of achieving this? Any takers? Kai update-one-record: func[ "Returns False on error or affected row count on success" tablename [string!] fieldname [string!] newvalue [ block ] keyfieldname [string!] keyvalue [block!]] [ conn-error: try [ mysqlport: open omysql-url insert mysqlport [ { update ? set ? = ? where ? = ? } tablename fieldname newvalue keyfieldname keyvalue ] affected-rows: mysqlport/locals/matched-rows close mysqlport false ; no error if we get here! ] either error? conn-error [ conn-error: disarm conn-error stat-upd sbar reform [ "MySQL-Connection error: " conn-error/arg1 ] false ] [ affected-rows ] ]

 [2/3] from: Tom:Conlin:gmai:l at: 11-Aug-2007 18:39


Kai Peters wrote:
> In the function below (intended to be used with Nenad's MySQL driver) the > newvalue & keyvalue may need to be framed
<<quoted lines omitted: 20>>
> affected-rows ] > ]
with out any testing or real knowledge of what values may/can be passed ... quote: func [b block!][ either word? first b [rejoin ["'" b "'"]] [first b] ] update-one-record: func[ "Returns False on error or affected row count on success" tablename [string!] fieldname [string!] newvalue [block ] keyfieldname [string!] keyvalue [block!] ][ newvalue: quote newvalue keyvalue: quote keyvalue conn-error: try [ mysqlport: open omysql-url insert mysqlport [ { update ? set ? = ? where ? = ? } tablename fieldname newvalue keyfieldname keyvalue ] affected-rows: mysqlport/locals/matched-rows close mysqlport false ; no error if we get here! ] either error? conn-error [conn-error: disarm conn-error stat-upd sbar reform [ "MySQL-Connection error: " conn-error/arg1 ] false ] [affected-rows] ]

 [3/3] from: kpeters::otaksoft::com at: 11-Aug-2007 19:12


Thanks Tom ~ just discovered that I don't need this in this case as the driver is already smart enough but it'll go into my newbie problem solving collection. Just realized that by passing the entire query string as parameter (instead of having part of it hardwired and passing a zillion parameters) things get easier, too ... Thanks again, Kai

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted