Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b24b2a5

Browse files
author
Hiroshi Inoue
committed
Add casting for numeric/float4/float8 type value
automatically to compensate the lack of automatic conversion functionality of PostgreSQL server. For example if there's a numeric type binding 1.2567 --> 1.2567::numeric. I hope this change would enable the use of numeric type in MS-Access etc. Thanks Hiroki Kataoka for his checking my code.
1 parent f65ebad commit b24b2a5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/interfaces/odbc/convert.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,33 @@ int lobj_fd, retval;
10651065
/* because of no conversion operator for bool and int4, SQL_BIT */
10661066
/* must be quoted (0 or 1 is ok to use inside the quotes) */
10671067

1068+
case SQL_REAL:
1069+
if (buf)
1070+
my_strcpy(param_string, sizeof(param_string), buf, used);
1071+
sprintf(tmp, "'%s'::float4", param_string);
1072+
strcpy(&new_statement[npos], tmp);
1073+
npos += strlen(tmp);
1074+
break;
1075+
case SQL_FLOAT:
1076+
case SQL_DOUBLE:
1077+
if (buf)
1078+
my_strcpy(param_string, sizeof(param_string), buf, used);
1079+
sprintf(tmp, "'%s'::float8", param_string);
1080+
strcpy(&new_statement[npos], tmp);
1081+
npos += strlen(tmp);
1082+
break;
1083+
case SQL_NUMERIC:
1084+
if (buf)
1085+
{
1086+
cbuf[0] = '\'';
1087+
my_strcpy(cbuf + 1, sizeof(cbuf) - 12, buf, used); /* 12 = 1('\'') + strlen("'::numeric") + 1('\0') */
1088+
strcat(cbuf, "'::numeric");
1089+
}
1090+
else
1091+
sprintf(cbuf, "'%s'::numeric", param_string);
1092+
my_strcpy(&new_statement[npos], sizeof(stmt->stmt_with_params) - npos - 1, cbuf, strlen(cbuf));
1093+
npos += strlen(&new_statement[npos]);
1094+
break;
10681095
default: /* a numeric type or SQL_BIT */
10691096
if (param_sqltype == SQL_BIT)
10701097
new_statement[npos++] = '\''; /* Open Quote */

0 commit comments

Comments
 (0)