visual c++ - How to add handler to the format function of CString -
first have cstring(mfc)
cstring cssql
when format sql string, example
cssql.format( szformat, sztablename, szcolumn, szvalue, intvalue )
i need handle special char in szvalue, need write new class mysqlstring
mysqlcs.formatsql( szformat, sztablename, szcolumn, szvalue, intvalue )
which has functionality
cssql.format( szformat, sztablename, szcolumn, handlespecialchar(szvalue), intvalue )
but because parameter format function accept not fixed. found difficult. there solution?
you don't add handler cstring class.
you write (new) function
cstring formatsqlstring(cstring const& format, cstring const& tablename, cstring const& columnname, cstring const& value) { cstring cssql; return cssql.format(format, tablename, columnname, handlespecialchar(value)); }
and wrap function further (e.g. cstring getupdatestmt(tablename, columnname, value)
) don't have sprinkle format strings on code.
when write code use input sql statement in structured way, collection of functions such proposed, using or creating sqlquerystringbuilder
(made name) class, won't have problem of having shoehorn string formatting doesn't belong there.
Comments
Post a Comment