home *** CD-ROM | disk | FTP | other *** search
- //-----------------------------------------------------------------------------
- // Microsoft OLE DB QLAPDEMO Sample
- // Copyright (C) 1995-1998 Microsoft Corporation
- //
- // File: OLAPDemo.cpp
- //
- // This file contains the main function for OlapDemo
- //
- //-----------------------------------------------------------------------------
-
- #include <conio.h>
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- // Initilaizes OLEDB Guids / Constants
- // There should one and only one file in the project which #defines those
- #define DBINITCONSTANTS 1
- #define INITGUID 1
- #define OLEDBVER 0x0200
-
- #include "OLAP.h"
-
- extern void PrintPrompt( OLAPApp* app );
-
- BOOL g_CtrlC = FALSE;
-
- //////////////////////////////////////////////////////////////////////////////////////
- BOOL WINAPI ConsoleHandlerRoutine( DWORD dwCtrlType )
-
- // Handle events on console
- //////////////////////////////////////////////////////////////////////////////////////
- {
- switch ( dwCtrlType )
- {
- case CTRL_C_EVENT:
- g_CtrlC = TRUE;
- return TRUE;
- }
-
- return FALSE;
- }
-
- //////////////////////////////////////////////////////////////////////////////////////
- int main(int a_argc, char** a_argv)
-
- // Process console commands.
- //////////////////////////////////////////////////////////////////////////////////////
- {
- int argc; // number of arguments
- TCHAR** argv; // argument array
-
- #ifdef UNICODE
- // Create the unicode version of the command line
- argv = CommandLineToArgvW( GetCommandLineW(), &argc);
-
- #else
- argc = a_argc;
- argv = a_argv;
- #endif
-
- // Set some console parameters
- SetConsoleTitle( TEXT("OlapDemo - Microsoft Sample for OLE DB for OLAP") );
- SetConsoleCtrlHandler( ConsoleHandlerRoutine, TRUE );
-
- // Create and init olap application.
- OLAPApp app;
- OLAPTab tab;
-
- if ( FAILED(app.Init()) )
- goto quit;
-
- TCHAR string[OLAP_APP_MAX_STRING_LEN];
-
- while ( TRUE ) {
- PrintPrompt(&app);
-
- memset( string, 0, sizeof(string) );
- _getts(string);
-
- if ( g_CtrlC ) {
- goto quit;
- }
-
- if ( *string == 0 ) {
- continue;
- }
-
- // Process MDX statement. Rather than have the special keyword meaning "MDX query" we
- // just look into the first word. We make sure no other keyword in this demo program
- // is equal to these MDX keywords
- if ( !OLAP_strcmp(string,6,_TEXT("Select"),6) ||
- !OLAP_strcmp(string,4,_TEXT("With"),4) ||
- !OLAP_strcmp(string,4,_TEXT("Drop"),4) ||
- !OLAP_strcmp(string,6,_TEXT("Create"),6) ) {
- if ( FAILED(app.ExecQuery(string)) ) {
- tab.PrintError();
- }
- continue;
- }
-
- // Process other commands
-
- if ( !tab.Set(string) ) {
- _tprintf(TEXT("\nUnknown command!"));
- continue;
- }
-
- for ( LONG i = 0, count = tab.GetColumns(); i < count; i++ ) {
- LONG length = tab.GetColumnLength(i);
- TCHAR* text = tab.GetColumnString(i);
-
- if ( !OLAP_strcmp(text,length,_TEXT("Exit"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("E"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("Quit"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("q"),OLAP_ALL) ) {
- // Close application
- app.Disconnect();
- goto quit;
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Disconnect"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("D"),OLAP_ALL) ) {
- // Disconnect from server
- if ( FAILED(app.Disconnect()) ) {
- tab.PrintError();
- break;
- }
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Connect"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("C"),OLAP_ALL) ) {
- // Connect to server
- if ( FAILED(app.Connect(&string[length+1])) ) {
- tab.PrintError();
- break;
- }
- break;
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Use"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("U"),OLAP_ALL) ) {
- // Open DataBase
- if ( FAILED(app.OpenDataBase(&string[length+1])) ) {
- tab.PrintError();
- break;
- }
- break;
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Properties"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("P"),OLAP_ALL) ) {
- // Print properties
- DWORD flags = 0;
- OLAPTab table(NULL,TEXT(':'));
-
- length = tab.GetColumnLength(++i);
- text = tab.GetColumnString(i);
-
- while ( length && text ) {
- if ( !OLAP_strcmp(text,length,_TEXT("/NotSupported"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/n"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_NOTSUPPORTED;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Column"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/C"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_COLUMN;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/DataSource"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/DS"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_DATASOURCE;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/DataSourceCreate"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/DSC"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_DATASOURCECREATE;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/DataSourceInfo"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/DSI"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_DATASOURCEINFO;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Init"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/I"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_DBINIT;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Index"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/Idx"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_INDEX;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Rowset"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/Row"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_ROWSET;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Session"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/S"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_SESSION;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Table"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/T"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_TABLE;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Read"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/R"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_READ;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Write"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/W"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_WRITE;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Required"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/Rq"),OLAP_ALL) ) {
- flags |= DBPROPFLAGS_REQUIRED;
- }
- if ( !OLAP_strcmp(text,length,_TEXT("/Format"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/F"),OLAP_ALL) ) {
- table.Set(tab.GetColumnString(++i));
- }
- length = tab.GetColumnLength(++i);
- text = tab.GetColumnString(i);
- }
- if ( FAILED(table.PrintPropertiesInfo(app.GetSource(),(flags) ? flags : -1)) ) {
- table.PrintError();
- break;
- }
- break;
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("schema"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("S"),OLAP_ALL) ) {
- // Print schema rowset
- OLAPTab table(NULL,TEXT(':'));
- TCHAR* schema = NULL;
-
- length = tab.GetColumnLength(++i);
- text = tab.GetColumnString(i);
-
- while ( length && text ) {
- if ( !OLAP_strcmp(text,length,_TEXT("/Format"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/f"),OLAP_ALL) ) {
- table.Set(tab.GetColumnString(++i));
- }
- else if ( *text == TEXT('/') ) {
- schema = text + 1;
- }
- length = tab.GetColumnLength(++i);
- text = tab.GetColumnString(i);
- }
-
- if ( FAILED(table.PrintSchemaRowset(app.GetSession(),schema)) ) {
- table.PrintError();
- break;
- }
- break;
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Axis"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("A"),OLAP_ALL) ) {
- // Print axis rowset
- OLAPTab table(NULL,TEXT(':'));
- TCHAR* name = NULL;
-
- length = tab.GetColumnLength(++i);
- text = tab.GetColumnString(i);
-
- while ( length && text ) {
- if ( !OLAP_strcmp(text,length,_TEXT("/Format"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/f"),OLAP_ALL) ) {
- table.Set(tab.GetColumnString(++i));
- }
- else if ( *text == TEXT('/') ) {
- name = text + 1;
- }
- length = tab.GetColumnLength(++i);
- text = tab.GetColumnString(i);
- }
-
- if ( FAILED(table.PrintAxisRowset(app.GetDataset(),OLAP_ALL,name)) ) {
- tab.PrintError();
- break;
- }
- break;
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Cells"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("CS"),OLAP_ALL) ) {
- // Print cells of query
- OLAPTab table(NULL,TEXT(':'));
- TCHAR* schema = NULL;
-
- length = tab.GetColumnLength(++i);
- text = tab.GetColumnString(i);
-
- while ( length && text ) {
- if ( !OLAP_strcmp(text,length,_TEXT("/Format"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("/f"),OLAP_ALL) ) {
- table.Set(tab.GetColumnString(++i));
- }
- else if ( *text == TEXT('/') ) {
- schema = text;
- }
- length = tab.GetColumnLength(++i);
- text = tab.GetColumnString(i);
- }
-
- if ( !OLAP_strcmp(schema,OLAP_ALL,_TEXT("/Query"),OLAP_ALL) ||
- !OLAP_strcmp(schema,OLAP_ALL,_TEXT("/q"),OLAP_ALL) ) {
- if ( FAILED(table.PrintQuery(app.GetDataset())) ) {
- table.PrintError();
- break;
- }
- }
- else if ( FAILED(table.PrintDataset(app.GetDataset())) ) {
- table.PrintError();
- break;
- }
- break;
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Help"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("?"),OLAP_ALL) ) {
- // Help
- OLAPTab table(NULL,TEXT(':'));
- TCHAR* help = NULL;
-
- length = tab.GetColumnLength(++i);
- text = tab.GetColumnString(i);
-
- if ( !length || !text ) {
- _tprintf(TEXT("\n\nFor more information on a specific command, type HELP command-name."));
- _tprintf(TEXT("\n[AXIS][A] Print schema rowset."));
- _tprintf(TEXT("\n[CELLS][CS] Print query result."));
- _tprintf(TEXT("\n[CONNECT][C] Connect to OLAP Server."));
- _tprintf(TEXT("\nCreate MDX statement."));
- _tprintf(TEXT("\n[DISCONNECT][D] Disconnect from OLAP server."));
- _tprintf(TEXT("\nDrop MDX statement."));
- _tprintf(TEXT("\n[EXIT][E][QUIT][Q] Quits the OlapDemo.EXE program (OLAP Demo Application)."));
- _tprintf(TEXT("\n[PROPERTIES][P] Print properties list."));
- _tprintf(TEXT("\nSelect MDX statement."));
- _tprintf(TEXT("\n[SCHEMA][S] Print schema rowset."));
- _tprintf(TEXT("\n[USE][U] Change current OLAP database."));
- _tprintf(TEXT("\nWith MDX statement."));
- _tprintf(TEXT("\n"));
- break;
- }
-
- if ( !OLAP_strcmp(text,length,_TEXT("Exit"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("E"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("Quit"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("Q"),OLAP_ALL) ) {
- // Close application
- _tprintf(TEXT("\nQuits the OlapDemo.EXE program (OLAP Demo Application)."));
- _tprintf(TEXT("\n\n[EXIT][E][QUIT][Q]"));
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Disconnect"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("D"),OLAP_ALL) ) {
- // Disconnect from server
- _tprintf(TEXT("\nDisconnect from OLAP server."));
- _tprintf(TEXT("\n\n[DISCONNECT][D]"));
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Connect"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("C"),OLAP_ALL) ) {
- // Connect to server
- _tprintf(TEXT("\nConnect to OLAP Server."));
- _tprintf(TEXT("\n\n[CONNECT][C] [servername][filename]"));
- _tprintf(TEXT("\n\nservername Specifies the machine name of the server to connect."));
- _tprintf(TEXT("\nfilename Specifies the path and name to DCube file to open."));
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Use"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("U"),OLAP_ALL) ) {
- // Open DataBase
- _tprintf(TEXT("\nChange current OLAP database."));
- _tprintf(TEXT("\n\n[USE][U] databasename"));
- _tprintf(TEXT("\n\ndatabase Specifies the name of the database changed to active."));
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Properties"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("P"),OLAP_ALL) ) {
- // Print properties
- _tprintf(TEXT("\nPrint properties list."));
- _tprintf(TEXT("\n\n[PROPERTIES][P]"));
- _tprintf(TEXT(" [/notsupported][/n]"));
- _tprintf(TEXT(" [/column][/c]"));
- _tprintf(TEXT("\n [/datasource][/ds]"));
- _tprintf(TEXT(" [/datasourcecreate][/dsc]"));
- _tprintf(TEXT(" [/datasourceinfo][/dsi]"));
- _tprintf(TEXT("\n [/init][/i]"));
- _tprintf(TEXT(" [/index][/idx]"));
- _tprintf(TEXT(" [/rowset][/row]"));
- _tprintf(TEXT(" [/session][/s]"));
- _tprintf(TEXT(" [/table][/t]"));
- _tprintf(TEXT("\n [/read][/r]"));
- _tprintf(TEXT(" [/write][/w]"));
- _tprintf(TEXT(" [/required][/rq]"));
- _tprintf(TEXT("\n [/format][/f][c1:c2:c3...]"));
- _tprintf(TEXT("\n\n example: p /ds /f 17:0:11"));
- _tprintf(TEXT("\n\nnotsupported Specifies print not supported properties."));
- _tprintf(TEXT("\ncolumn Specifies print column properties."));
- _tprintf(TEXT("\ndatasource Specifies print datasource properties."));
- _tprintf(TEXT("\ndatasourcecreate Specifies print datasource create properties."));
- _tprintf(TEXT("\ndatasourceinfo Specifies print datasource info properties."));
- _tprintf(TEXT("\ninit Specifies print init properties."));
- _tprintf(TEXT("\nindex Specifies print index properties."));
- _tprintf(TEXT("\nrowset Specifies print rowset properties."));
- _tprintf(TEXT("\nsession Specifies print session properties."));
- _tprintf(TEXT("\ntable Specifies print table properties."));
- _tprintf(TEXT("\nread Specifies print read properties."));
- _tprintf(TEXT("\nwrite Specifies print write properties."));
- _tprintf(TEXT("\nrequired Specifies print required properties."));
- _tprintf(TEXT("\nformat Use specified number of characters for column then print."));
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("schema"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("S"),OLAP_ALL) ) {
- // Print schema rowset
- _tprintf(TEXT("\nPrint schema rowset."));
- _tprintf(TEXT("\n\n[SCHEMA][S] schemaname"));
- _tprintf(TEXT("\n [/format][/f][c1:c2:c3...]"));
- _tprintf(TEXT("\n\n examples: s /c /f 0:20"));
- _tprintf(TEXT("\n s /cub /f 0:0:0:20:15:0:0:0:0:0:0"));
- _tprintf(TEXT("\n s /dim /f 0:0:0:25:20"));
- _tprintf(TEXT("\n s /h /f 0:0:0:25:25:0"));
- _tprintf(TEXT("\n s /l /f 0:0:0:25:25:25:20:0:0:20:0:0"));
- _tprintf(TEXT("\n s /mem /f 0:0:0:10:20:0:30:0:0:20:50:0:0:0:0:0"));
- _tprintf(TEXT("\n s /p /f 0:0:0:0:0:0:0:0:15:15:0:10:0:0:0:0"));
- _tprintf(TEXT("\n\nschemaname Specifies name of schema for print."));
- _tprintf(TEXT("\n [/catalogs][/c],"));
- _tprintf(TEXT("\n [/cubes][/cub],"));
- _tprintf(TEXT("\n [/dimensions][/dim],"));
- _tprintf(TEXT("\n [/hierarchies][/h],"));
- _tprintf(TEXT("\n [/levels][/l],"));
- _tprintf(TEXT("\n [/measures][/m],"));
- _tprintf(TEXT("\n [/members][/mem],"));
- _tprintf(TEXT("\n [/properties][/p]."));
- //_tprintf(TEXT("\n [/schemas][/s]."));
- _tprintf(TEXT("\nformat Use specified number of characters for column then print."));
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Axis"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("A"),OLAP_ALL) ) {
- // Print axis rowset
- _tprintf(TEXT("\nPrint axis rowset."));
- _tprintf(TEXT("\n\n[AXIS][A] axisname"));
- _tprintf(TEXT("\n [/format][/f][c1:c2:c3...]"));
- _tprintf(TEXT("\n\n example: a /0 /f 0:15:35:30:30:0:0"));
- _tprintf(TEXT("\n\nquery Specifies print not supported properties."));
- _tprintf(TEXT("\n\naxisname Specifies name of axis for print."));
- _tprintf(TEXT("\n [/columns][/0],"));
- _tprintf(TEXT("\n [/rows][/1],"));
- _tprintf(TEXT("\n [/2],"));
- _tprintf(TEXT("\n [/3],"));
- _tprintf(TEXT("\n [/4],"));
- _tprintf(TEXT("\n [/5],"));
- _tprintf(TEXT("\n [/6],"));
- _tprintf(TEXT("\n [/7]."));
- _tprintf(TEXT("\nformat Use specified number of characters for column then print."));
- }
- else if ( !OLAP_strcmp(text,length,_TEXT("Cells"),OLAP_ALL) ||
- !OLAP_strcmp(text,length,_TEXT("CS"),OLAP_ALL) ) {
- // Print cells of query
- _tprintf(TEXT("\nPrint query result."));
- _tprintf(TEXT("\n\n[CELLS][CS] [/Query][/q]"));
- _tprintf(TEXT("\n [/format][/f][c1:c2:c3...]"));
- _tprintf(TEXT("\n\n examples: cs /f 20:0"));
- _tprintf(TEXT("\n cs /q"));
- _tprintf(TEXT("\n\nquery Specifies use of axes query result for print."));
- _tprintf(TEXT("\nformat Use specified number of characters for column then print."));
- }
- else {
- _tprintf(TEXT("\nUnknown command!"));
- }
- break;
- }
- else {
- _tprintf(TEXT("\nUnknown command!"));
- break;
- }
- }
- }
-
- quit:
- return 0;
- }
-
- //////////////////////////////////////////////////////////////////////////////////////
- void PrintPrompt( OLAPApp* app )
-
- // Process console commands.
- //////////////////////////////////////////////////////////////////////////////////////
- {
- if ( app && app->IsState(OLAP_APP_CONNECTED) ) {
- VARIANT server;
- VARIANT database;
-
- VariantInit( &server );
- VariantInit( &database );
-
- app->GetProperty( DBPROPSET_DATASOURCEINFO, DBPROP_SERVER_NAME, &server );
- app->GetProperty( DBPROPSET_DATASOURCE, DBPROP_CURRENTCATALOG, &database );
-
- _tprintf(TEXT("\n"));
-
- switch ( V_VT(&server) ) {
- case VT_BSTR:
- case VT_LPSTR:
- case VT_LPWSTR:
- _tprintf(TEXT("%s"), V_BSTR(&server));
- break;
- case VT_BSTR | VT_BYREF:
- case VT_LPSTR | VT_BYREF:
- case VT_LPWSTR | VT_BYREF:
- _tprintf(TEXT("%s"), *V_BSTRREF(&server));
- break;
- default:
- _tprintf(TEXT(" ?"));
- }
-
- switch ( V_VT(&database) ) {
- case VT_BSTR:
- case VT_LPSTR:
- case VT_LPWSTR:
- _tprintf(TEXT(" [%s]"), V_BSTR(&database));
- break;
- case VT_BSTR | VT_BYREF:
- case VT_LPSTR | VT_BYREF:
- case VT_LPWSTR | VT_BYREF:
- _tprintf(TEXT(" (%s)"), *V_BSTRREF(&database));
- break;
- default:
- _tprintf(TEXT(" ?"));
- }
- _tprintf(TEXT(">"));
-
- VariantClear( &server );
- VariantClear( &database );
- return;
- }
- _tprintf(TEXT("\nOlapDemo>"));
- }