home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmVBADOCreateCube
- Caption = "Form1"
- ClientHeight = 1095
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 2640
- LinkTopic = "Form1"
- ScaleHeight = 1095
- ScaleWidth = 2640
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton cmdCreateCubeFromDatabase
- Caption = "Create Cube from Database"
- Height = 645
- Left = 135
- TabIndex = 0
- Top = 225
- Width = 2325
- End
- Attribute VB_Name = "frmVBADOCreateCube"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private Sub cmdCreateCubeFromDatabase_Click()
- Dim cnCube As ADODB.Connection
- Dim s As String
- Dim strProvider As String
- Dim strDataSource As String
- Dim strSourceDSN As String
- Dim strSourceDSNSuffix As String
- Dim strCreateCube As String
- Dim strInsertInto As String
- On Error GoTo Error_cmdCreateCubeFromDatabase_Click
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '* To build a cube file the CREATE CUBE statement is used to define the cubes structure and this structure
- '* is passed as the connection string for processing. The connection string is a concatenated set of keyword=value
- '* pairs, delimited with semicolons. The order of the keyword=value pairs is not important as long as all pairs
- '* necessary are present. The code to follow is a sample of a connection string against a DSN which is based
- '* on the Sample FoodMart Microsoft Access database.
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '* Add Provider, the name of the engine that will process the connection string.
- '*----------------------------------------------------------------------------------------------------------------------------------------
- strProvider = "PROVIDER=MSOLAP"
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '* Add DataSource, the name of the cube file (.cub) that will be created.
- '*----------------------------------------------------------------------------------------------------------------------------------------
- strDataSource = "DATA SOURCE=c:\CreateCubeSample.cub"
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '* Add Source DSN, the connection string for where the data comes from.
- '* We need to quote the value so it is parsed as one value.
- '* This can either be an ODBC connection string or an OLE DB connection string.
- '* (As returned by the Data Source Locator component.)
- '* strSourceDSN = "SOURCE_DSN=DRIVER=Microsoft Access Driver (*.mdb);DBQ=\\platoue1\Samples\Sales.MDB;"
- '*----------------------------------------------------------------------------------------------------------------------------------------
- strSourceDSN = "SOURCE_DSN=FoodMart"
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '* We may have some other parameters that we want applied at run time, but
- '* not stored in the cube file, or returned in the output string.
- '* Example:
- '* strSourceDSNSuffix = "UID=;PWD="
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '* Add CREATE CUBE. This defines the structure of the cube, but not the data in it.
- '* The BNF for this is somewhere in the documentation.
- '* Note: The names are quoted with square brackets.
- '*----------------------------------------------------------------------------------------------------------------------------------------
- strCreateCube = "CREATECUBE=CREATE CUBE Sample( "
- strCreateCube = strCreateCube & "DIMENSION [Product],"
- strCreateCube = strCreateCube & "LEVEL [All Products] TYPE ALL,"
- strCreateCube = strCreateCube & "LEVEL [Product Family] ,"
- strCreateCube = strCreateCube & "LEVEL [Product Department] ,"
- strCreateCube = strCreateCube & "LEVEL [Product Category] ,"
- strCreateCube = strCreateCube & "LEVEL [Product Subcategory] ,"
- strCreateCube = strCreateCube & "LEVEL [Brand Name] ,"
- strCreateCube = strCreateCube & "LEVEL [Product Name] ,"
- strCreateCube = strCreateCube & "DIMENSION [Store],"
- strCreateCube = strCreateCube & "LEVEL [All Stores] TYPE ALL,"
- strCreateCube = strCreateCube & "LEVEL [Store Country] ,"
- strCreateCube = strCreateCube & "LEVEL [Store State] ,"
- strCreateCube = strCreateCube & "LEVEL [Store City] ,"
- strCreateCube = strCreateCube & "LEVEL [Store Name] ,"
- strCreateCube = strCreateCube & "DIMENSION [Store Type],"
- strCreateCube = strCreateCube & "LEVEL [All Store Type] TYPE ALL,"
- strCreateCube = strCreateCube & "LEVEL [Store Type] ,"
- strCreateCube = strCreateCube & "DIMENSION [Time] TYPE TIME,"
- strCreateCube = strCreateCube & "HIERARCHY [Column],"
- strCreateCube = strCreateCube & "LEVEL [All Time] TYPE ALL,"
- strCreateCube = strCreateCube & "LEVEL [Year] TYPE YEAR,"
- strCreateCube = strCreateCube & "LEVEL [Quarter] TYPE QUARTER,"
- strCreateCube = strCreateCube & "LEVEL [Month] TYPE MONTH,"
- strCreateCube = strCreateCube & "LEVEL [Week] TYPE WEEK,"
- strCreateCube = strCreateCube & "LEVEL [Day] TYPE DAY,"
- strCreateCube = strCreateCube & "HIERARCHY [Formula],"
- strCreateCube = strCreateCube & "LEVEL [All Formula Time] TYPE ALL,"
- strCreateCube = strCreateCube & "LEVEL [Year] TYPE YEAR,"
- strCreateCube = strCreateCube & "LEVEL [Quarter] TYPE QUARTER,"
- strCreateCube = strCreateCube & "LEVEL [Month] TYPE MONTH OPTIONS (SORTBYKEY) ,"
- strCreateCube = strCreateCube & "DIMENSION [Warehouse],"
- strCreateCube = strCreateCube & "LEVEL [All Warehouses] TYPE ALL,"
- strCreateCube = strCreateCube & "LEVEL [Country] ,"
- strCreateCube = strCreateCube & "LEVEL [State Province] ,"
- strCreateCube = strCreateCube & "LEVEL [City] ,"
- strCreateCube = strCreateCube & "LEVEL [Warehouse Name] ,"
- strCreateCube = strCreateCube & "MEASURE [Store Invoice] "
- strCreateCube = strCreateCube & "Function Sum "
- strCreateCube = strCreateCube & "Format '#.#',"
- strCreateCube = strCreateCube & "MEASURE [Supply Time] "
- strCreateCube = strCreateCube & "Function Sum "
- strCreateCube = strCreateCube & "Format '#.#',"
- strCreateCube = strCreateCube & "MEASURE [Warehouse Cost] "
- strCreateCube = strCreateCube & "Function Sum "
- strCreateCube = strCreateCube & "Format '#.#',"
- strCreateCube = strCreateCube & "MEASURE [Warehouse Sales] "
- strCreateCube = strCreateCube & "Function Sum "
- strCreateCube = strCreateCube & "Format '#.#',"
- strCreateCube = strCreateCube & "MEASURE [Units Shipped] "
- strCreateCube = strCreateCube & "Function Sum "
- strCreateCube = strCreateCube & "Format '#.#',"
- strCreateCube = strCreateCube & "MEASURE [Units Ordered] "
- strCreateCube = strCreateCube & "Function Sum "
- strCreateCube = strCreateCube & "Format '#.#')"
- 'strCreateCube = strCreateCube & ","
- 'strCreateCube = strCreateCube & " COMMAND [CREATE MEMBER [MEASURE].[Warehouse Profit] "
- 'strCreateCube = strCreateCube & "AS '[MEASURE].[Warehouse Sales] - [MEASURE].[Warehouse Cost]'])"
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '*Add INSERT INTO. This defines where the data comes from, and how it maps
- '* into the already-defined cube structure.
- '* Note:The SELECT clause might just be passed through to the relational database.
- '* So I could pass in a stored procedure, for example.
- '* Note: Columns in the SELECT can be in any order. One merely has to
- '* adjust the ordering of the list of level/measure names to match the SELECT ordering.
- '*----------------------------------------------------------------------------------------------------------------------------------------
- strInsertInto = strInsertInto & "INSERTINTO=INSERT INTO Sample( Product.[Product Family], Product.[Product Department],"
- strInsertInto = strInsertInto & "Product.[Product Category], Product.[Product Subcategory],"
- strInsertInto = strInsertInto & "Product.[Brand Name], Product.[Product Name],"
- strInsertInto = strInsertInto & "Store.[Store Country], Store.[Store State], Store.[Store City],"
- strInsertInto = strInsertInto & "Store.[Store Name], [Store Type].[Store Type], [Time].[Column],"
- strInsertInto = strInsertInto & "[Time].Formula.Year, [Time].Formula.Quarter, [Time].Formula.Month.[Key],"
- strInsertInto = strInsertInto & "[Time].Formula.Month.Name, Warehouse.Country, Warehouse.[State Province],"
- strInsertInto = strInsertInto & "Warehouse.City, Warehouse.[Warehouse Name], Measures.[Store Invoice],"
- strInsertInto = strInsertInto & "Measures.[Supply Time], Measures.[Warehouse Cost], Measures.[Warehouse Sales],"
- strInsertInto = strInsertInto & "Measures.[Units Shipped], Measures.[Units Ordered] )"
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '* Add some options to the INSERT INTO if we need to.
- '* These can control if the SELECT clause is analyzed or just passed through,
- '* and if the storage mode is MOLAP or ROLAP (DEFER_DATA).
- '* Example:
- '* strInsertInto = strInsertInto & " OPTIONS ATTEMPT_ANALYSIS"
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '* Add the SELECT clause of the INSERT INTO statement.
- '* Note: SELECT is merely concatenated onto the end of the INSERT INTO statement.
- '* OLAP Service will pass this through to the source database if unable to parse it.
- '* Note: that for OLAP Service to analyze the SELECT clause, each column must be
- '* qualified with the table name.
- '*----------------------------------------------------------------------------------------------------------------------------------------
- strInsertInto = strInsertInto & "SELECT product_class.product_family AS Col1,"
- strInsertInto = strInsertInto & "product_class.product_department AS Col2,"
- strInsertInto = strInsertInto & "product_class.product_category AS Col3,"
- strInsertInto = strInsertInto & "product_class.product_subcategory AS Col4,"
- strInsertInto = strInsertInto & "product.brand_name AS Col5,"
- strInsertInto = strInsertInto & "product.product_name AS Col6,"
- strInsertInto = strInsertInto & "store.store_country AS Col7,"
- strInsertInto = strInsertInto & "store.store_state AS Col8,"
- strInsertInto = strInsertInto & "store.store_city AS Col9,"
- strInsertInto = strInsertInto & "store.store_name AS Col10,"
- strInsertInto = strInsertInto & "store.store_type AS Col11,"
- strInsertInto = strInsertInto & "time_by_day.the_date AS Col12,"
- strInsertInto = strInsertInto & "time_by_day.the_year AS Col13,"
- strInsertInto = strInsertInto & "time_by_day.quarter AS Col14,"
- strInsertInto = strInsertInto & "time_by_day.month_of_year AS Col15,"
- strInsertInto = strInsertInto & "time_by_day.the_month AS Col16,"
- strInsertInto = strInsertInto & "warehouse.warehouse_country AS Col17,"
- strInsertInto = strInsertInto & "warehouse.warehouse_state_province AS Col18,"
- strInsertInto = strInsertInto & "warehouse.warehouse_city AS Col19,"
- strInsertInto = strInsertInto & "warehouse.warehouse_name AS Col20,"
- strInsertInto = strInsertInto & "inventory_fact_1997.store_invoice AS Col21,"
- strInsertInto = strInsertInto & "inventory_fact_1997.supply_time AS Col22,"
- strInsertInto = strInsertInto & "inventory_fact_1997.warehouse_cost AS Col23,"
- strInsertInto = strInsertInto & "inventory_fact_1997.warehouse_sales AS Col24,"
- strInsertInto = strInsertInto & "inventory_fact_1997.units_shipped AS Col25,"
- strInsertInto = strInsertInto & "inventory_fact_1997.units_ordered AS Col26 "
- strInsertInto = strInsertInto & "From [inventory_fact_1997], [product], [product_class], [time_by_day], [store], [warehouse] "
- strInsertInto = strInsertInto & "Where [inventory_fact_1997].[product_id] = [product].[product_id] And "
- strInsertInto = strInsertInto & "[product].[product_class_id] = [product_class].[product_class_id] And "
- strInsertInto = strInsertInto & "[inventory_fact_1997].[time_id] = [time_by_day].[time_id] And "
- strInsertInto = strInsertInto & "[inventory_fact_1997].[store_id] = [store].[store_id] And "
- strInsertInto = strInsertInto & "[inventory_fact_1997].[warehouse_id] = [warehouse].[warehouse_id]"
- '*----------------------------------------------------------------------------------------------------------------------------------------
- '* Note:Since the cube is not created anywhere, when the connection object is opened the cube is built on
- '* the fly with the information in the connection string
- '* Set a New ADODB Connection Object
- '* Create the cube by passing concatenated connection string to Open method of the connection object.
- '*----------------------------------------------------------------------------------------------------------------------------------------
- MsgBox strDataSource & "; "
- MsgBox strSourceDSN & "; "
- MsgBox strCreateCube & "; "
- MsgBox strInsertInto & ";"
- Set cnCube = New ADODB.Connection
- s = strProvider & ";" & strDataSource & ";" & strSourceDSN & ";" & strCreateCube & ";" & strInsertInto & ";"
- Screen.MousePointer = vbHourglass
- cnCube.Open s
- Screen.MousePointer = vbDefault
- Exit Sub
- Error_cmdCreateCubeFromDatabase_Click:
- Screen.MousePointer = vbDefault
- MsgBox Err.Description
- If Err.Number <> 0 Then
- Msg = "Error # " & Str(Err.Number) & " was generated by " _
- & Err.Source & Chr(13) & Err.Description
- MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
- End If
- End Sub
-