[Libreoffice-commits] core.git: 2 commits - connectivity/source
Andrzej J.R. Hunt
andrzej at ahunt.org
Tue Aug 6 13:20:19 PDT 2013
connectivity/source/drivers/firebird/DatabaseMetaData.cxx | 43 +++----------
connectivity/source/drivers/firebird/PreparedStatement.cxx | 30 +++++----
connectivity/source/drivers/firebird/Util.cxx | 3
3 files changed, 31 insertions(+), 45 deletions(-)
New commits:
commit 89fdead645bf2a777e4d438abe976d759aa48a4b
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Tue Aug 6 19:10:23 2013 +0200
Correctly handle varchar. (firebird-sdbc)
Previously SQL_VARYING was cerced to SQL_TEXT which
loses the string length.
Change-Id: I5ab6c0ce2892dcb986282d6bf6fbb770b4fbafeb
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index aeddb14..55bba8c 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 90c74fc..78c0377 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));
commit c3aaa4e4019edb796cf904dc5777ff49afd0304f
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Tue Aug 6 14:55:48 2013 +0200
Simpligy getTablePrivileges. (firebird-sdbc)
Change-Id: I3a858fc3c94bbf6c32cc7fdae60d0ee45acb3cf2
diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index c30ba43..cc19be6 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -1602,7 +1602,6 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
"priv.RDB$PRIVILEGE, " // 4
"priv.RDB$GRANT_OPTION " // 5 is Grantable
"FROM RDB$USER_PRIVILEGES priv ");
- // "WHERE (priv.RDB$USER = ?????????)"
if (!sTableNamePattern.isEmpty())
{
@@ -1624,45 +1623,25 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW );
ODatabaseMetaDataResultSet::ORows aResults;
+ ODatabaseMetaDataResultSet::ORow aRow(8);
+ aRow[0] = new ORowSetValueDecorator(); // Unused
+ aRow[1] = new ORowSetValueDecorator(); // TABLE_CAT unsupported
+ aRow[2] = new ORowSetValueDecorator(); // TABLE_SCHEM unussported.
+
while( rs->next() )
{
- // TODO: avoid reallocations
- ODatabaseMetaDataResultSet::ORow aCurrentRow;
- aCurrentRow.reserve(7);
-
- // 1. TABLE_CAT
- aCurrentRow.push_back(new ORowSetValueDecorator());
- // 2. TABLE_SCHEM
- aCurrentRow.push_back(new ORowSetValueDecorator());
-
// 3. TABLE_NAME
{
OUString sTableName = xRow->getString(1);
sanitizeIdentifier(sTableName);
- aCurrentRow.push_back(new ORowSetValueDecorator(sTableName));
- }
- // 4. GRANTOR
- {
- OUString sGrantor = xRow->getString(2);
- aCurrentRow.push_back(new ORowSetValueDecorator(sGrantor));
- }
- // 5. GRANTEE
- {
- OUString sGrantee = xRow->getString(3);
- aCurrentRow.push_back(new ORowSetValueDecorator(sGrantee));
- }
- // 6. Privilege
- {
- OUString sPrivilege = xRow->getString(4);
- aCurrentRow.push_back(new ORowSetValueDecorator(sPrivilege));
- }
- // 7. IS_GRANTABLE
- {
- sal_Bool bIsGrantable = xRow->getBoolean(5);
- aCurrentRow.push_back(new ORowSetValueDecorator(bIsGrantable));
+ aRow[3] = new ORowSetValueDecorator(sTableName);
}
+ aRow[4] = new ORowSetValueDecorator(xRow->getString(2)); // 4. GRANTOR
+ aRow[5] = new ORowSetValueDecorator(xRow->getString(3)); // 5. GRANTEE
+ aRow[6] = new ORowSetValueDecorator(xRow->getString(4)); // 6. Privilege
+ aRow[7] = new ORowSetValueDecorator(xRow->getBoolean(5)); // 7. Is Grantable
- aResults.push_back(aCurrentRow);
+ aResults.push_back(aRow);
}
pResultSet->setRows( aResults );
More information about the Libreoffice-commits
mailing list