diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-08-06 19:10:23 +0200 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-08-06 22:17:23 +0200 |
commit | 89fdead645bf2a777e4d438abe976d759aa48a4b (patch) | |
tree | ed1a42328d889bcdb95c65ecb5d8e31f948d8106 /connectivity | |
parent | c3aaa4e4019edb796cf904dc5777ff49afd0304f (diff) |
Correctly handle varchar. (firebird-sdbc)
Previously SQL_VARYING was cerced to SQL_TEXT which
loses the string length.
Change-Id: I5ab6c0ce2892dcb986282d6bf6fbb770b4fbafeb
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/firebird/PreparedStatement.cxx | 30 | ||||
-rw-r--r-- | connectivity/source/drivers/firebird/Util.cxx | 3 |
2 files changed, 20 insertions, 13 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index aeddb14ed88f..55bba8cb7fdd 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -211,21 +211,29 @@ void SAL_CALL OPreparedStatement::setString(sal_Int32 nParameterIndex, XSQLVAR* pVar = m_pInSqlda->sqlvar + (nParameterIndex - 1); int dtype = (pVar->sqltype & ~1); // drop flag bit for now + + if (str.getLength() > pVar->sqllen) + str = str.copy(0, pVar->sqllen); + switch (dtype) { case SQL_VARYING: - pVar->sqltype = SQL_TEXT; - case SQL_TEXT: - if (str.getLength() > pVar->sqllen) - { // Cut off overflow - memcpy(pVar->sqldata, str.getStr(), pVar->sqllen); - } - else + { + // First 2 bytes indicate string size + if (str.getLength() > (2^16)-1) { - memcpy(pVar->sqldata, str.getStr(), str.getLength()); - // Fill remainder with spaces - // TODO: would 0 be better here for filling? - memset(pVar->sqldata + str.getLength(), ' ', pVar->sqllen - str.getLength()); + str = str.copy(0, (2^16)-1); } + const short nLength = str.getLength(); + memcpy(pVar->sqldata, &nLength, 2); + // Actual data + memcpy(pVar->sqldata + 2, str.getStr(), str.getLength()); + break; + } + case SQL_TEXT: + memcpy(pVar->sqldata, str.getStr(), str.getLength()); + // Fill remainder with spaces + // TODO: would 0 be better here for filling? + memset(pVar->sqldata + str.getLength(), ' ', pVar->sqllen - str.getLength()); break; default: // TODO: sane error message diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx index 90c74fc9d0b7..78c03774dd3b 100644 --- a/connectivity/source/drivers/firebird/Util.cxx +++ b/connectivity/source/drivers/firebird/Util.cxx @@ -196,8 +196,7 @@ void firebird::mallocSQLVAR(XSQLDA* pSqlda) pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen); break; case SQL_VARYING: - pVar->sqltype = SQL_TEXT; - pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen); + pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen + 2); break; case SQL_SHORT: pVar->sqldata = (char *)malloc(sizeof(short)); |