Modified:
trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp
trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
trunk/MYSQLPlus/include/MStatement.h
Log:
SQLSpecialColumns done (needs some testing and no faking rowver)
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp 2006-06-28 07:25:08 UTC (rev 409)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp 2006-06-28 08:46:11 UTC (rev 410)
@@ -723,7 +723,7 @@
*/
if ( nNullable != SQL_NO_NULLS )
{
- switch ( nIdentifier )
+ switch ( nIdentifierType )
{
case SQL_BEST_ROWID:
nReturn = doAppendSpecialColumnsRowID( stringCatalog, stringSchema,
stringTable, nScope, nNullable );
@@ -973,24 +973,24 @@
if ( mysql_query( getMySQL(), stringStatement.toUtf8().data() ) )
{
getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, mysql_errno( getMySQL() ),
mysql_error( getMySQL() ) );
- MYODBCDbgReturn3( "%p", stringlistTables );
+ MYODBCDbgReturn3( "%p", stringlistColumns );
}
pResult = mysql_use_result( getMySQL() );
if ( !pResult )
{
getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, mysql_errno( getMySQL() ),
mysql_error( getMySQL() ) );
- MYODBCDbgReturn3( "%p", stringlistTables );
+ MYODBCDbgReturn3( "%p", stringlistColumns );
}
while ( pRow = mysql_fetch_row( pResult ) )
{
- stringlistTables += pRow[0];
+ stringlistColumns += pRow[0];
}
mysql_free_result( pResult );
- MYODBCDbgReturn3( "%p", stringlistTables );
+ MYODBCDbgReturn3( "%p", stringlistColumns );
}
QStringList MResultPlus::getColumnsUniqueIndex( const QString &stringCatalog, const
QString &stringSchema, const QString &stringTable, BOOLEAN bExcludePrimary )
@@ -1011,14 +1011,14 @@
if ( mysql_query( getMySQL(), stringStatement.toUtf8().data() ) )
{
getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, mysql_errno( getMySQL() ),
mysql_error( getMySQL() ) );
- MYODBCDbgReturn3( "%p", stringlistTables );
+ MYODBCDbgReturn3( "%p", stringlistColumns );
}
pResult = mysql_use_result( getMySQL() );
if ( !pResult )
{
getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, mysql_errno( getMySQL() ),
mysql_error( getMySQL() ) );
- MYODBCDbgReturn3( "%p", stringlistTables );
+ MYODBCDbgReturn3( "%p", stringlistColumns );
}
while ( pRow = mysql_fetch_row( pResult ) )
@@ -1028,12 +1028,12 @@
else if ( stringIndexName != pRow[0] )
break;
- stringlistTables += pRow[1];
+ stringlistColumns += pRow[1];
}
mysql_free_result( pResult );
- MYODBCDbgReturn3( "%p", stringlistTables );
+ MYODBCDbgReturn3( "%p", stringlistColumns );
}
SQLRETURN MResultPlus::doAppendTypeInfo( const QVariant &stringTypeName,
@@ -1740,7 +1740,6 @@
MYSQL_RES * pResult = NULL;
unsigned int nFields;
unsigned int nField;
- MYSQL_FIELD * pField;
SQLRETURN nReturn = SQL_SUCCESS;
/*!
@@ -1882,7 +1881,7 @@
unsigned int nField;
MYSQL_FIELD * pField;
SQLRETURN nReturn = SQL_SUCCESS;
- QStringList stringColumns;
+ QStringList stringlistColumns;
/*!
\internal
@@ -1896,10 +1895,10 @@
There may be other ways to get a unique rowid such as "UNIQUE" column attribute -
but
lets avoid tricks where we can.
*/
- stringColumns = getColumnsPrimaryKey( stringCatalog, stringSchema, stringTable );
- if ( !stringColumns.count() )
- stringColumns = getColumnsUniqueIndex( stringCatalog, stringSchema, stringTable
);
- if ( !stringColumns.count() )
+ stringlistColumns = getColumnsPrimaryKey( stringCatalog, stringSchema, stringTable );
+ if ( !stringlistColumns.count() )
+ stringlistColumns = getColumnsUniqueIndex( stringCatalog, stringSchema,
stringTable );
+ if ( !stringlistColumns.count() )
MYODBCDbgReturn( SQL_SUCCESS );
/*!
@@ -1919,7 +1918,7 @@
(lots of rules and assumptions) bit of code isolated and besides, catalog
functions should never
be the 'big hit' for performance due to their nature.
*/
- stringSQL = "SELECT * FROM `" + stringCatalog + "`.`" + stringTable + "` LIMIT 0";
+ stringSQL = "SELECT " + stringlistColumns.join( QChar( ',' ) ) + " FROM `" +
stringCatalog + "`.`" + stringTable + "` LIMIT 0";
if ( mysql_query( getMySQL(), stringSQL.toUtf8().data() ) )
MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000,
mysql_errno( getMySQL() ), mysql_error( getMySQL() ) ) );
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-06-28 07:25:08 UTC (rev 409)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-06-28 08:46:11 UTC (rev 410)
@@ -3045,7 +3045,7 @@
- primary key
- unique index
- SQL_ROWVER
+ SQL_ROWVER (not currently implemented)
The best rowver is chosen by looking for the availability of the following
(in priority order);
@@ -3138,15 +3138,6 @@
/*!
\internal ODBC RULE (DM)
- The SQL_ATTR_METADATA_ID statement attribute was set to SQL_TRUE, and the
SchemaName
- argument was a null pointer.
- */
- if ( getMetadataID() == SQL_TRUE && !psSchema )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY009 ) );
-
- /*!
- \internal ODBC RULE (DM)
-
The value of one of the length arguments was less than 0 but
not equal to SQL_NTS.
*/
@@ -3213,24 +3204,6 @@
MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY097 ) );
}
- /*!
- \internal ODBC RULE
-
- The TableName argument was a null pointer.
- */
- if ( !psTable )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY009 ) );
-
- /*!
- \internal ODBC RULE
-
- The SQL_ATTR_METADATA_ID statement attribute was set to SQL_TRUE, the CatalogName
- argument was a null pointer, and the SQL_CATALOG_NAME InfoType returns that
catalog
- names are supported.
- */
- if ( getMetadataID() == SQL_TRUE && !psCatalog &&
getConnection()->getInfoCatalogName() == "Y" )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY009 ) );
-
/* do it */
QString stringCatalog;
QString stringSchema;
@@ -3243,6 +3216,68 @@
if ( psTable && nLength3 != 0 )
stringTable = QString::fromUtf16( psTable, ( nLength3 == SQL_NTS ? -1 : nLength3
) );
+ if ( getMetadataID() == SQL_TRUE )
+ {
+ SQLRETURN nReturn;
+
+ /*!
+ \internal ODBC RULE
+
+ Setting an identifier argument to a null pointer returns SQL_ERROR and
SQLSTATE HY009 (Invalid use of null
+ pointer), unless the argument is a catalog name and catalogs are not
supported.
+
+ The SQL_ATTR_METADATA_ID statement attribute was set to SQL_TRUE, the
CatalogName
+ argument was a null pointer, and the SQL_CATALOG_NAME InfoType returns that
catalog
+ names are supported.
+ */
+ if ( !psSchema || !psTable || ( getConnection()->getInfoCatalogName() == "Y"
&& !psCatalog ) )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY009 ) );
+
+ /*!
+ \internal ODBC RULE
+
+ If a string in an identifier argument is quoted, the driver removes leading
and trailing blanks and treats
+ literally the string within the quotation marks. If the string is not quoted,
the driver removes trailing
+ blanks and folds the string to uppercase.
+ */
+ nReturn = doIdentifierArgumentMakeNice( stringCatalog );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ nReturn = doIdentifierArgumentMakeNice( stringSchema );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ nReturn = doIdentifierArgumentMakeNice( stringTable );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ }
+ else
+ {
+ /*!
+ \internal ODBC RULE
+
+ When a catalog function string argument is an ordinary argument, it is
treated as a literal string. An
+ ordinary argument accepts neither a string search pattern nor a list of
values. The case of an ordinary
+ argument is significant, and quote characters in the string are taken
literally.
+ */
+ /*!
+ \internal ODBC RULE
+
+ If an ordinary argument is set to a null pointer and the argument is a
required argument, the function
+ returns SQL_ERROR and SQLSTATE HY009 (Invalid use of null pointer). If an
ordinary argument is set to a
+ null pointer and the argument is not a required argument, the argument's
behavior is driver-dependent.
+
+ TableName is required.
+
+ \internal MYODBC RULE
+
+ An empty catalog is set to current catalog.
+ */
+ if ( stringTable.isEmpty() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY009 ) );
+ if ( stringCatalog.isEmpty() )
+ stringCatalog = getConnection()->getCurrentCatalog();
+ }
+
/*!
\internal ODBC RULE
@@ -3250,9 +3285,9 @@
\internal MYODBC RULE
- We can continue if value is; NULL, SQL_ALL_CATALOGS, or "".
+ We can continue if value is; NULL or "".
*/
- if ( getConnection()->getInfoCatalogUsage() == 0 &&
!stringCatalog.isEmpty() && stringCatalog != SQL_ALL_CATALOGS )
+ if ( getConnection()->getInfoCatalogUsage() == 0 &&
!stringCatalog.isEmpty() )
MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HYC00 ) );
/*!
@@ -3262,12 +3297,11 @@
\internal MYODBC RULE
- We can continue if value is; NULL, SQL_ALL_SCHEMAS, or "".
+ We can continue if value is; NULL or "".
*/
- if ( getConnection()->getInfoSchemaUsage() == 0 && !stringSchema.isEmpty()
&& stringSchema != SQL_ALL_SCHEMAS )
+ if ( getConnection()->getInfoSchemaUsage() == 0 && !stringSchema.isEmpty()
)
MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HYC00 ) );
-
/*!
\internal MYODBC RULE
@@ -4479,5 +4513,26 @@
MYODBCDbgReturn( SQL_SUCCESS );
}
+SQLRETURN MStatement::doIdentifierArgumentMakeNice( QString stringIA )
+{
+ MYODBCDbgEnter();
+ QString stringQuotes = "\"'";
+ stringIA = stringIA.trimmed();
+
+ if ( stringIA.isEmpty() )
+ MYODBCDbgReturn3( "%d", true );
+
+ if ( stringQuotes.contains( stringIA.at( 0 ) ) )
+ {
+ if ( stringIA.length() <= 1 )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Identifier Argument invalid.") ) );
+ if ( !stringIA.endsWith( stringIA.at( 0 ) ) )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Identifier Argument missing closing quote.") ) );
+ stringIA = stringIA.mid( 1, stringIA.length() - 2 );
+ }
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
Modified: trunk/MYSQLPlus/include/MStatement.h
===================================================================
--- trunk/MYSQLPlus/include/MStatement.h 2006-06-28 07:25:08 UTC (rev 409)
+++ trunk/MYSQLPlus/include/MStatement.h 2006-06-28 08:46:11 UTC (rev 410)
@@ -167,6 +167,7 @@
/* doers */
SQLRETURN doStateRollBack( STATE nState );
+ SQLRETURN doIdentifierArgumentMakeNice( QString stringIA );
private:
STATE nState; /*!< our current state
*/
| Thread |
|---|
| • Connector/ODBC 5 commit: r410 - in trunk/MYSQLPlus: MYSQLPlusLib include | pharvey | 28 Jun |