[REBOL] Elegant ideas someone?
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 ]
]