From 0843c6ca7fe604d8c44b9a81b8fcb072ab424172 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 19 May 2017 15:31:46 +0200 Subject: QSqlField: Add a means to see what the tablename is for a given field When you are using a query that pulls from a number of different tables then it can be ambiguous as to which table a particular field belongs to. So this will make it possible to determine the table that a given field belongs to if it is set. Task-number: QTBUG-7170 Change-Id: I49b7890c0523d81272a153df3860df800ff853d5 Reviewed-by: Jesus Fernandez Reviewed-by: Edward Welbourne --- src/plugins/sqldrivers/odbc/qsql_odbc.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/plugins/sqldrivers/odbc/qsql_odbc.cpp') diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index 59ef42d609..c32a29c5e7 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -64,6 +64,7 @@ QT_BEGIN_NAMESPACE #define ODBC_CHECK_DRIVER static const int COLNAMESIZE = 256; +static const SQLSMALLINT TABLENAMESIZE = 128; //Map Qt parameter types to ODBC types static const SQLSMALLINT qParamType[4] = { SQL_PARAM_INPUT, SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, SQL_PARAM_INPUT_OUTPUT }; @@ -730,6 +731,12 @@ static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt, int i, QString *errorMess f.setRequired(false); // else we don't know f.setAutoValue(isAutoValue(hStmt, i)); + QVarLengthArray tableName(TABLENAMESIZE); + SQLSMALLINT tableNameLen; + r = SQLColAttribute(hStmt, i + 1, SQL_DESC_BASE_TABLE_NAME, tableName.data(), + TABLENAMESIZE, &tableNameLen, 0); + if (r == SQL_SUCCESS) + f.setTableName(fromSQLTCHAR(tableName, tableNameLen)); return f; } -- cgit v1.2.3