diff --git a/uppsrc/ODBC/ODBC.cpp b/uppsrc/ODBC/ODBC.cpp index 20c7312ac..026a9eff4 100644 --- a/uppsrc/ODBC/ODBC.cpp +++ b/uppsrc/ODBC/ODBC.cpp @@ -302,6 +302,10 @@ bool ODBCConnection::IsOk(SQLRETURN ret) const void ODBCConnection::SetParam(int i, const Value& r) { Param& p = param.At(i); + if(IsNull(r)) { + p.li = SQL_NULL_DATA; + return; + } if(IsNumber(r)) { if(r.Is()) { int64 x = r; @@ -312,10 +316,19 @@ void ODBCConnection::SetParam(int i, const Value& r) } else { double x = r; - p.ctype = SQL_C_DOUBLE; - p.sqltype = SQL_DOUBLE; - p.data = String((char *)&x, sizeof(x)); - p.li = sizeof(x); + if(x >= INT_MIN && x < INT_MAX && (int)x == x) { + long int h = (int)x; + p.ctype = SQL_C_SLONG; + p.sqltype = SQL_INTEGER; + p.data = String((char *)&h, sizeof(h)); + p.li = sizeof(h); + } + else { + p.ctype = SQL_C_DOUBLE; + p.sqltype = SQL_DOUBLE; + p.data = String((char *)&x, sizeof(x)); + p.li = sizeof(x); + } } } if(IsString(r)) { @@ -339,8 +352,6 @@ void ODBCConnection::SetParam(int i, const Value& r) p.data = String((char *)&tm, sizeof(tm)); p.li = sizeof(tm); } - if(IsNull(r)) - p.li = SQL_NULL_DATA; } bool ODBCConnection::Execute() diff --git a/uppsrc/Sql/SqlStatement.cpp b/uppsrc/Sql/SqlStatement.cpp index e4e6588f3..110e93b22 100644 --- a/uppsrc/Sql/SqlStatement.cpp +++ b/uppsrc/Sql/SqlStatement.cpp @@ -307,7 +307,9 @@ SqlWith& SqlWith::With(SqlId table) SqlWith& SqlWith::WithRecursive(SqlId table) { - text << (text.GetCount() ? ", " : "with ") << "recursive " << table.Quoted(); + text << (text.GetCount() ? ", " : "with ") + << SqlCase(MSSQL, "")("recursive ") + << table.Quoted(); args = false; return *this; }