From 8cdabf074118ab0c86423891cc0b85c9c94939e7 Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Tue, 4 Apr 2000 01:07:54 +0000 Subject: [PATCH] Augment the function call map logic with code from Tom Lane. Should be more robust to overflows. Pass through an unmapped function unchanged, rather than rejecting it. Add a few more functions, but comment out those which can go through as-is. Can be used with contrib/odbc/ package, though that isn't committed yet. --- src/interfaces/odbc/convert.c | 166 ++++++++++++++++++++++++++-------- 1 file changed, 129 insertions(+), 37 deletions(-) diff --git a/src/interfaces/odbc/convert.c b/src/interfaces/odbc/convert.c index 24906e10ff..f87b915779 100644 --- a/src/interfaces/odbc/convert.c +++ b/src/interfaces/odbc/convert.c @@ -58,19 +58,76 @@ typedef signed char SCHAR; extern GLOBAL_VALUES globals; -/* How to map ODBC scalar functions {fn func(args)} to Postgres */ -/* This is just a simple substitution */ -char *mapFuncs[][2] = { - { "CONCAT", "textcat" }, - { "LCASE", "lower" }, - { "LOCATE", "strpos" }, - { "LENGTH", "textlen" }, - { "LTRIM", "ltrim" }, - { "RTRIM", "rtrim" }, - { "SUBSTRING", "substr" }, - { "UCASE", "upper" }, - { "NOW", "now" }, - { 0, 0 } +/* How to map ODBC scalar functions {fn func(args)} to Postgres + * This is just a simple substitution + * List augmented from + * http://www.merant.com/datadirect/download/docs/odbc16/Odbcref/rappc.htm + * - thomas 2000-04-03 + */ +char *mapFuncs[][2] = { +// { "ASCII", "ascii" }, + { "CHAR", "ichar" }, + { "CONCAT", "textcat" }, +// { "DIFFERENCE", "difference" }, +// { "INSERT", "insert" }, + { "LCASE", "lower" }, + { "LEFT", "ltrunc" }, + { "LOCATE", "strpos" }, + { "LENGTH", "char_length"}, +// { "LTRIM", "ltrim" }, + { "RIGHT", "rtrunc" }, +// { "REPEAT", "repeat" }, +// { "REPLACE", "replace" }, +// { "RTRIM", "rtrim" }, +// { "SOUNDEX", "soundex" }, + { "SUBSTRING", "substr" }, + { "UCASE", "upper" }, + +// { "ABS", "abs" }, +// { "ACOS", "acos" }, +// { "ASIN", "asin" }, +// { "ATAN", "atan" }, +// { "ATAN2", "atan2" }, + { "CEILING", "ceil" }, +// { "COS", "cos" }, +// { "COT", "cot" }, +// { "DEGREES", "degrees" }, +// { "EXP", "exp" }, +// { "FLOOR", "floor" }, + { "LOG", "ln" }, + { "LOG10", "log" }, +// { "MOD", "mod" }, +// { "PI", "pi" }, + { "POWER", "pow" }, +// { "RADIANS", "radians" }, + { "RAND", "random" }, +// { "ROUND", "round" }, +// { "SIGN", "sign" }, +// { "SIN", "sin" }, +// { "SQRT", "sqrt" }, +// { "TAN", "tan" }, +// { "TRUNCATE", "truncate" }, + +// { "CURDATE", "curdate" }, +// { "CURTIME", "curtime" }, +// { "DAYNAME", "dayname" }, +// { "DAYOFMONTH", "dayofmonth" }, +// { "DAYOFWEEK", "dayofweek" }, +// { "DAYOFYEAR", "dayofyear" }, +// { "HOUR", "hour" }, +// { "MINUTE", "minute" }, +// { "MONTH", "month" }, +// { "MONTHNAME", "monthname" }, +// { "NOW", "now" }, +// { "QUARTER", "quarter" }, +// { "SECOND", "second" }, +// { "WEEK", "week" }, +// { "YEAR", "year" }, + +// { "DATABASE", "database" }, + { "IFNULL", "coalesce" }, + { "USER", "odbc_user" }, + { 0, 0 } }; char *mapFunction(char *func); @@ -584,7 +641,7 @@ int copy_statement_with_parameters(StatementClass *stmt) { static char *func="copy_statement_with_parameters"; -unsigned int opos, npos; +unsigned int opos, npos, oldstmtlen; char param_string[128], tmp[256], cbuf[TEXT_FIELD_SIZE+5]; int param_number; Int2 param_ctype, param_sqltype; @@ -629,14 +686,17 @@ int lobj_fd, retval; param_number = -1; - for (opos = 0; opos < strlen(old_statement); opos++) { + oldstmtlen = strlen(old_statement); + + for (opos = 0; opos < oldstmtlen; opos++) { // Squeeze carriage-returns/linfeed pairs to linefeed only - if (old_statement[opos] == '\r' && opos+1