Looks good.
On Sat, Nov 04, 2006 at 10:46:40PM +0100, pharvey@stripped wrote:
> Modified:
> trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp
> trunk/Tools/Shell/MYODBCShell.cpp
> trunk/Tools/Shell/MYODBCShell.h
> trunk/Tools/Shell/main.cpp
> Log:
> ENH: Added support for SQLStatistics to MYODBCShell.
>
> Modified: trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp
> ===================================================================
> --- trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp 2006-11-04 03:31:40 UTC (rev 650)
> +++ trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp 2006-11-04 21:46:38 UTC (rev 651)
> @@ -696,6 +696,7 @@
> getDiagnostic()->doAppend( MDiagnostic::STATE_01000, 0, QString(
> "Unhandled index type (%1)" ).arg( stringType ) );
> nType = SQL_INDEX_OTHER;
> }
> +printf( "[PAH][%s][%s][%d] %s\n", __FILE__, __FUNCTION__, __LINE__, pRow[9] );
>
> /*! \note as i recall we can get FILTER_CONDITION from COMMENT - but not
> 100% of the time so perhaps forget it or perhaps try to be smart? */
> doAppendStatistics( pRow[4], // catalog - we put MySQL schema in
> here
>
> Modified: trunk/Tools/Shell/MYODBCShell.cpp
> ===================================================================
> --- trunk/Tools/Shell/MYODBCShell.cpp 2006-11-04 03:31:40 UTC (rev 650)
> +++ trunk/Tools/Shell/MYODBCShell.cpp 2006-11-04 21:46:38 UTC (rev 651)
> @@ -216,6 +216,8 @@
> return doTables( stringCommand );
> else if ( stringCommand.startsWith( "SQLColumns" ) )
> return doColumns( stringCommand );
> + else if ( stringCommand.startsWith( "SQLStatistics" ) )
> + return doStatistics( stringCommand );
> else
> return doSubmit( stringCommand );
>
> @@ -409,7 +411,7 @@
>
> if ( stringlist.count() != 6 )
> {
> - *pstreamStdErr << QString( "[%1][%2][ERROR] SQLTables must be provided
> exactly 4 filter elements." ).arg( __FILE__ ).arg( __LINE__ ) << endl;
> + *pstreamStdErr << QString( "[%1][%2][ERROR] %3 filter elements provide
> but 6 expected." ).arg( __FILE__ ).arg( __LINE__ ).arg( stringlist.count() ) <<
> endl;
> return false;
> }
>
> @@ -488,7 +490,7 @@
>
> if ( stringlist.count() != 6 )
> {
> - *pstreamStdErr << QString( "[%1][%2][ERROR] SQLColumns must be
> provided exactly 4 filter elements." ).arg( __FILE__ ).arg( __LINE__ ) << endl;
> + *pstreamStdErr << QString( "[%1][%2][ERROR] %3 filter elements provide
> but 6 expected." ).arg( __FILE__ ).arg( __LINE__ ).arg( stringlist.count() ) <<
> endl;
> return false;
> }
>
> @@ -537,6 +539,87 @@
> return true;
> }
>
> +/*!
> + \brief Process a SQLStatictics command.
> +
> + The command should start with "SQLStatistics " and be followed by a
> filter specification.
> +
> + Example;
> +
> + SQLStatistics |||categories|
> +*/
> +bool MYODBCShell::doStatistics( const QString &stringCommand )
> +{
> + SQLWCHAR * psCatalog = NULL;
> + SQLWCHAR * psSchema = NULL;
> + SQLWCHAR * psTable = NULL;
> + SQLSMALLINT nCatalog = 0;
> + SQLSMALLINT nSchema = 0;
> + SQLSMALLINT nTable = 0;
> +
> + // init
> + if ( !hDbc )
> + {
> + *pstreamStdErr << QString( "[%1][%2][ERROR] Function sequence error."
> ).arg( __FILE__ ).arg( __LINE__ ) << endl;
> + return false;
> + }
> +
> + if ( !SQL_SUCCEEDED( SQLAllocHandle( SQL_HANDLE_STMT, hDbc, &hStm ) ) )
> + {
> + if ( bVerbose ) doErrors( hEnv, hDbc, NULL );
> + *pstreamStdErr << QString( "[%1][%2][ERROR] Could not allocate
> SQL_HANDLE_STMT." ).arg( __FILE__ ).arg( __LINE__ ) << endl;
> + hStm = NULL;
> + return false;
> + }
> +
> + QStringList stringlist = stringCommand.split( '|' );
> +
> + if ( stringlist.count() != 5 )
> + {
> + *pstreamStdErr << QString( "[%1][%2][ERROR] %3 filter elements provide
> but 5 expected." ).arg( __FILE__ ).arg( __LINE__ ).arg( stringlist.count() ) <<
> endl;
> + return false;
> + }
> +
> + QString stringCatalog = stringlist.at( 1 );
> + QString stringSchema = stringlist.at( 2 );
> + QString stringTable = stringlist.at( 3 );
> + QString stringColumn = stringlist.at( 4 );
> +
> + if ( stringCatalog != "NULL" && !stringCatalog.isNull() )
> + {
> + psCatalog = (SQLWCHAR*)stringCatalog.utf16();
> + nCatalog = stringCatalog.length();
> + }
> + if ( stringSchema != "NULL" && !stringSchema.isNull() )
> + {
> + psSchema = (SQLWCHAR*)stringSchema.utf16();
> + nSchema = stringSchema.length();
> + }
> + if ( stringTable != "NULL" && !stringTable.isNull() )
> + {
> + psTable = (SQLWCHAR*)stringTable.utf16();
> + nTable = stringTable.length();
> + }
> +
> + if ( !SQL_SUCCEEDED( SQLStatistics( hStm, psCatalog, nCatalog, psSchema,
> nSchema, psTable, nTable, SQL_INDEX_ALL, 0 ) ) )
> + {
> + if ( bVerbose ) doErrors( hEnv, hDbc, hStm );
> + *pstreamStdErr << QString( "[%1][%2][ERROR] Could not SQLStatistics."
> ).arg( __FILE__ ).arg( __LINE__ ) << endl;
> + SQLFreeHandle( SQL_HANDLE_STMT, hStm );
> + hStm = NULL;
> + return false;
> + }
> +
> + // process results (if any)
> + doResults();
> +
> + // fini
> + SQLFreeHandle( SQL_HANDLE_STMT, hStm );
> + hStm = NULL;
> +
> + return true;
> +}
> +
> bool MYODBCShell::doResults()
> {
> SQLSMALLINT nCols;
>
> Modified: trunk/Tools/Shell/MYODBCShell.h
> ===================================================================
> --- trunk/Tools/Shell/MYODBCShell.h 2006-11-04 03:31:40 UTC (rev 650)
> +++ trunk/Tools/Shell/MYODBCShell.h 2006-11-04 21:46:38 UTC (rev 651)
> @@ -110,6 +110,7 @@
> bool doHelp( const QString &stringCommand );
> bool doTables( const QString &stringCommand );
> bool doColumns( const QString &stringCommand );
> + bool doStatistics( const QString &stringCommand );
>
> bool doResults();
>
>
> Modified: trunk/Tools/Shell/main.cpp
> ===================================================================
> --- trunk/Tools/Shell/main.cpp 2006-11-04 03:31:40 UTC (rev 650)
> +++ trunk/Tools/Shell/main.cpp 2006-11-04 21:46:38 UTC (rev 651)
> @@ -148,6 +148,7 @@
> *pShell->pstreamStdOut << "| help [table_name]" << endl;
> *pShell->pstreamStdOut << "| SQLTables
> |catalog|schema|table|table_type|" << endl;
> *pShell->pstreamStdOut << "| SQLColumns
> |catalog|schema|table|column|" << endl;
> + *pShell->pstreamStdOut << "| SQLStatistics |catalog|schema|table|"
> << endl;
> *pShell->pstreamStdOut << "| quit" << endl;
> *pShell->pstreamStdOut << "|" << endl;
> *pShell->pstreamStdOut << "| NOTE: Blank line causes buffered text"
> << endl;
>
>
> --
> MySQL Code Commits Mailing List
> For list archives: http://lists.mysql.com/commits
> To unsubscribe: http://lists.mysql.com/commits?unsub=1
--
Jess Balint, Developer
MySQL Inc, www.mysql.com
Office: +1 773 915 3175
Are you MySQL certified? www.mysql.com/certification