1 'encoding UTF-8 Do not remove or change this line!
2 '**************************************************************************
3 ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 ' Copyright 2000, 2010 Oracle and/or its affiliates.
7 ' OpenOffice.org - a multi-platform office productivity suite
9 ' This file is part of OpenOffice.org.
11 ' OpenOffice.org is free software: you can redistribute it and/or modify
12 ' it under the terms of the GNU Lesser General Public License version 3
13 ' only, as published by the Free Software Foundation.
15 ' OpenOffice.org is distributed in the hope that it will be useful,
16 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ' GNU Lesser General Public License version 3 for more details
19 ' (a copy is included in the LICENSE file that accompanied this code).
21 ' You should have received a copy of the GNU Lesser General Public License
22 ' version 3 along with OpenOffice.org. If not, see
23 ' <http://www.openoffice.org/license.html>
24 ' for a copy of the LGPLv3 License.
26 '/************************************************************************
28 '* owner : marc.neumann@oracle.com
30 '* short description : Tools for Tables
32 '************************************************************************
34 ' #1 fCloseRelationDesign
35 ' #1 fCloseTableDesign
37 ' #1 fCompareMatrixValues
43 ' #1 fOpenRelationDesign
44 ' #1 fOpenNew TableDesign
48 '\***********************************************************************
49 '------------------------------------------------------------------------------
50 function tCompareMatrixValues(sDSName as string, sRefFileUrl as string, cTable_or_Query as string, sTableName as string, iRowPos as integer, iColPos as integer, sWordSeperator as string) as integer
51 'sDSName = data source name f.e. Bibliography
52 'sRefFileUrl = URL to your reference file (os indipendent - extension .ttr) f.e. base\optional\input\reference_tables\test.ttr
53 'cTable_or_Query = differ between comparing reference file with a table (t) or a query-table (q)
54 'sTableName = name of table or query-table to compare with f.e. Table1
55 'iRowPos,iColPos = row and column amount of reference and comparing table (must have the same size ; begin with 1 ; 0 is leftout, but has to be added)
58 dim j as integer 'counter'
59 dim aMatrix(iRowPos, iColPos) as string
62 if cTable_or_Query = "t" then printlog "--- Compare Table with Reference Table ---"
63 if cTable_or_Query = "q" then printlog "--- Compare Query with Reference Table ---"
65 call fReadFile(sRefFileUrl, aMatrix(), sWordSeperator)
69 '/// open Beamer and open datasource
72 printlog "open database beamer"
74 '/// switch between table and querie search
75 dim bfind_ok as boolean 'placeholder
76 if cTable_or_Query = "t" then
77 bfind_ok = ffindTableInBeamer(sDSName,sTableName)
78 printlog "found proper Table: " & sTableName
80 if cTable_or_Query = "q" then
81 bfind_ok = ffindQuery(sDSName, sTableName)
82 printlog "found proper Query: " & sTableName
86 '/// Choosing for the right table
88 Kontext "DatabaseSelection"
89 DatabaseSelection.TypeKeys "<MOD1 SHIFT E>",TRUE ' # type CTRL + SHIFT + E to go from the DatabaseSelection to the TableView'
91 printlog "found and opened proper table"
92 '/// comparing data in table with reference table
93 printlog "start comparing data in table with reference table"
95 dim ivalue_ok as integer
97 TableView.TypeKeys "<TAB>",TRUE
98 TableView.TypeKeys "<HOME>",TRUE
99 TableView.TypeKeys "<HOME>",TRUE
100 for i = 1 to iRowPos -1
101 for j = 1 to iColPos -1
103 'here the values are read out and put in clipboard for comparing
104 TableView.TypeKeys "<MOD1 C>",TRUE
105 TableView.TypeKeys "<TAB>",TRUE
108 'printlog "getClipboard: " & getclipboard()
109 'printlog "matrix: " & aMatrix(i,j)
111 'here the values are compared
112 if getclipboard() <> aMatrix(i,j) then
113 ivalue_ok = ivalue_ok + 1
114 warnlog ivalue_ok & ". fault in pos(row/col): " & i & "/" & j & " - should be: " & aMatrix(i,j) & " but is: " & getclipboard()
116 'printlog ivalue_ok & ". No !!! foult but TEST - should be: " & aMatrix(i,j) & " but is: " & getclipboard()
121 if ivalue_ok = 0 then
122 printlog "** Comparing procedure without faults"
123 tCompareMatrixValues = ivalue_ok
125 warnlog "Comparing procedure went wrong: " + ivalue_ok + " differences found!"
126 tCompareMatrixValues = 1
129 if cTable_or_Query = "t" then warnlog "Table: " + sTableName + " not found - Test aborted"
130 if cTable_or_Query = "q" then warnlog "Query: " + sTableName + " not found - Test aborted"
132 printlog "*** End Testcase"
138 '------------------------------------------------------------------------------
139 function fCreateRefFile(sDSName as string, cTable_or_Query as string, sTableName as string, sWordSeperator as string) as string
140 dim bfind_ok as boolean 'check if right table found
141 dim iNumber as Integer 'needed for open reference file
142 dim iColAmount as integer
143 dim iRowAmount as integer 'counter
144 dim sReadContCol as string
145 dim sContColMem as string 'read out content string and its memo for getting table column ammount
146 dim sCellValue as string
147 dim sCellValueMem as string 'read out content string and its memo for writing in reference table
149 dim sRefTableName as string
150 sRefTableName = ConvertPath("user\work\" & sTableName & ".ttr")
151 dim sRefFileUrl as string
152 sRefFileUrl = gOfficePath & sRefTableName
153 printlog "path for reference table: " & sRefFileUrl
158 '/// open Beamer and open datasource
161 printlog "open database beamer"
163 '/// switch between table and querie search
164 if cTable_or_Query = "t" then
165 printlog "search for proper Table: " & sTableName
166 bfind_ok = ffindTableInBeamer(sDSName,sTableName)
168 if cTable_or_Query = "q" then
169 printlog "search for proper Query: " & sTableName
170 bfind_ok = ffindQuery(sDSName, sTableName)
174 '/// jumping to the right table
176 Kontext "DatabaseSelection"
177 DatabaseSelection.TypeKeys "<MOD1 SHIFT E>",TRUE ' # type CTRL + SHIFT + E to go from the DatabaseSelection to the TableView'
180 '/// check the row and column amount
181 printlog "check the row and column amount"
183 sReadContCol = 1 'init
184 sContColMem = 1 'init
186 iRowAmount = AllRecords.caption()
187 while sReadContCol = sContColMem
188 sContColMem = sReadContCol
189 sReadContCol = CurrentRecord.getText()
190 TableView.TypeKeys "<TAB>",TRUE
191 TableView.TypeKeys "<TAB>",TRUE
192 iColAmount = iColAmount +1
194 iColAmount = iColAmount -1
195 'printlog "sReadContCol: " & sReadContCol
196 printlog "size of table (columns/rows): " & iColAmount & "/" & iRowAmount
197 fCreateRefFile = iColAmount & "," & iRowAmount
198 TableView.TypeKeys "<UP>",TRUE
199 TableView.TypeKeys "<HOME>",TRUE
200 TableView.TypeKeys "<HOME>",TRUE
203 '/// reading out values from table, create a reference table and input values in
204 printlog "start reading out values from table and writing in ref table"
206 dim i as integer 'counter
207 dim j as integer 'counter
208 Open sRefFileUrl for Output as iNumber
209 for i = 1 to iRowAmount
210 for j = 1 to iColAmount
212 TableView.TypeKeys "<MOD1 C>"
213 sCellValue = getclipboard()
214 TableView.TypeKeys "<TAB>"
216 sCellValueMem = sCellValueMem & sWordSeperator
218 sCellValueMem = sCellValueMem & sCellValue
219 'printlog i & j & " inhalt: " & sCellValue
222 print #iNumber, sCellValueMem
228 '/// warning if table not found - without proper table the test make no sense
230 warnlog "Table: " + sTableName + " not found."
239 '------------------------------------------------------------------------------
240 function fReadFile(sRefFileUrl as string, aMatrix() as string, sWordSep as string)
241 'connecting and opening file
242 dim iNumber as Integer
244 'position and content variables
245 dim sColumn As String
246 dim iRowPos as integer
247 dim iColPos as integer
249 dim iPos1 as integer 'pointer for searching position
251 'init position in matrix
255 '/// open reference file and store it into an array (matrix)
256 printlog "search for the reference file, open it and store content in an array"
257 sRefFileUrl = gOfficePath + ConvertPath(sRefFileUrl)
258 Open sRefFileUrl for Input as iNumber
259 while not eof(iNumber)
260 Line Input #iNumber, sColumn
261 iPos1 = 1 'startposition
262 iPos = 1 'startposition
263 while iPos <> 0 'if iPos = 0 then no more sWordSeperator found -> end of column reached
264 iPos = Instr(iPos +1,sColumn,sWordSep) 'check column for sWordSeperator
265 'printlog "iPos: " & iPos
266 'printlog "iPos1: " & iPos1
267 if iPos <> 1 then '<> 1 -> no content found
268 aMatrix(iRowPos,iColPos) = Mid(sColumn,iPos1,iPos - iPos1) 'cut content and put into array
269 'printlog "iRow: " & iRowPos
270 'printlog "iCol: " & iColPos
271 'printlog "aMatrix: " & aMatrix(iRowPos,iColPos)
274 else warnlog "reference file is empty"
280 printlog "**end of reading out reference table"
282 '--------------------------------------------------------------------
283 function fCreateTable(aFieldTypeContent(),sTableName,optional sCatalog,optional sSchema)
284 '/// create a table with the given FieldTypes
285 '/// sSchema and sCatalog are optional.
286 '/// If the optional parameter is not given then it's set to ""
287 '/// <u>parameter:</u>
288 '/// <b>aFieldTypeContent:</b> an arry with the table field data
289 '/// the array have to look like the following
290 '/// array(1,1) = first_field_name
291 '/// array(1,2) = first_field_type
292 '/// array(2,1) = second_field_name
293 '/// array(2,2) = second_field_type
294 '/// ...
295 '/// <b>sTableName:</b> the name of the table
296 '/// <b><i>optional</i> sCatalog:</b> the name of the table catalog
297 '/// <b><i>optional</i> sSchema:</b> the name of the table schema
299 Dim i as integer 'counter
300 Dim iFieldNumber as integer 'counter
301 dim iNoDS as integer 'number of data source in listbox
302 Dim iNumberOfFieldTypes as integer 'field type memory
303 Dim iFieldTypesCounter as integer 'counter
304 Dim iIndex as integer 'counter
305 Dim sFieldType as string 'help var for fieldtypes
306 Dim sTypeName as String 'help var for fieldtypes
308 if ( IsMissing(sCatalog) ) then
312 if ( IsMissing(sSchema) ) then
316 call fDeleteTable(sTableName) ' delete the table if exists
318 call fOpenNewTableDesign
320 Kontext "TableDesignTable"
322 for iFieldNumber = 1 to ubound(aFieldTypeContent) - 1
324 printlog "create field : " + aFieldTypeContent(iFieldNumber,1)
325 Fieldname.TypeKeys aFieldTypeContent(iFieldNumber,1) , TRUE
326 Fieldname.TypeKeys "<RETURN>" , TRUE
328 sTypeName = "[ " + aFieldTypeContent(iFieldNumber,2) + " ]"
329 iNumberOfFieldTypes = FieldType.getitemCount()
330 for iFieldTypesCounter = 1 to iNumberOfFieldTypes
331 sFieldType = FieldType.getitemText(iFieldTypesCounter)
332 iIndex = Instr(sFieldType,sTypeName)
334 printlog "FieldType : " + sFieldType
335 iFieldTypesCounter = iNumberOfFieldTypes ' stops the for loop if proper fieldtype found'
338 '/// choose proper field type
339 FieldType.Select(sFieldType) 'listbox entry nr'
341 FieldType.TypeKeys "<RETURN>" , TRUE
342 Description.TypeKeys "<RETURN>" , TRUE
343 CellDescription.TypeKeys "<RETURN>" , TRUE
344 printlog "-------------------------------"
347 Kontext "TableDesignTable"
348 TableDesignTable.usemenu
349 MenuSelect MenuGetItemId (1)
351 menuselect MenuGetItemId (7)
353 Kontext "DatabaseTableSaveAs"
354 printlog "save table as "+ sTableName
355 TableName.setText sTableName
357 '/// catalog handling
358 if sCatalog <> "" then
359 if Catalog.IsVisible then
360 Catalog.SetText sCatalog
361 printlog "inserting catalog name: " + sCatalog
363 warnlog "The Catalog-Name could not be inserted"
367 if sSchema <> "" then
368 if Schema.IsVisible then
369 Schema.SetText sSchema
370 printlog "inserting schema name: " + sSchema
372 warnlog "The Schema-Name could not be inserted"
375 DatabaseTableSaveAs.OK
378 if Messagebox.Exists(1) then
380 printlog "create a primary key "
384 ' a sql exception appear. Try to get the error text
386 if Messagebox.Exists(1) then
387 MessageBox.Click 5 ' click the more button
388 Kontext "SQLException"
389 if SQLException.exists() then
390 warnlog Errortext.getText()
397 call fCloseTableDesign
400 '--------------------------------------------------------------------
401 function fDeleteTable(sTableName as string)
402 '/// delete the table with the given name
403 '/// <u>parameter:</u>
404 '/// <b>sTableName:</b> the table which shall be deleted
405 if ( fFindTable(sTableName) = true ) then
406 printlog "Table found press delete"
407 Kontext "ContainerView"
408 'TableTree.TypeKeys "<DELETE>" , true
409 Delete ' uno-Slot .uno:DB/Delete
419 '--------------------------------------------------------------------
420 function fOpenTable(sTableName as string)
421 '/// open the table with the given name
422 '/// <u>parameter:</u>
423 '/// <b>sTableName:</b> the table which shall be opened
424 if ( fFindTable(sTableName) = true ) then
425 printlog "Table found -> open"
426 Kontext "ContainerView"
427 OpenTable ' uno-Slot .uno:DB/Open
435 '--------------------------------------------------------------------
436 function fFindTable(sTableName as string)
437 '/// select the table with the given name in the table container
438 '/// <u>parameter:</u>
439 '/// <b>sTableName:</b> the table which shall be selected
441 Dim iNumbersOfTables as integer
444 Kontext "ContainerView"
450 if ( Not TableTree.exists(1) ) then
451 qaerrorlog "The table tree doesn't exists"
452 ' May be a messagebox appear click OK to close it
454 if MessageBox.exists(1) then
455 qaerrorlog MessageBox.getText()
456 while MessageBox.exists() ' sometimes there are more then 1 message boxe
463 iNumbersOfTables = TableTree.getItemCount()
465 ' this select the first entry
466 TableTree.TypeKeys "<HOME>"
467 TableTree.TypeKeys "<UP>"
470 for i = 1 to iNumbersOfTables
472 TableTree.TypeKeys "<ADD>"
474 'printlog "TableName.getItemCount = " + TableTree.getItemCount
475 if TableTree.getItemCount > iNumbersOfTables then
476 iNumbersOfTables = TableTree.getItemCount()
478 'printlog "TableName.getSeltext = " + TableTree.getSeltext
479 if TableTree.getSeltext = sTableName then
483 TableTree.TypeKeys "<DOWN>"
488 '--------------------------------------------------------------------
489 function fInsertIntoTable( aFieldContent(), sTableName)
490 '/// insert data into a table
491 '/// <u>parameter:</u>
492 '/// <b>aFieldContent:</b> an arry with the table data
493 '/// the array have to look like the following
494 '/// array(1,1) = first_value_for_first_record
495 '/// array(1,2) = second_value_for_first_record
496 '/// array(2,1) = first_value_for_second_record
497 '/// array(2,2) = second_value_for_second_record
498 '/// ...
499 '/// <b>sTableName:</b> the name of the table
501 Dim iCounterOfRecords as integer
502 Dim iCounterOfFields as integer
504 Dim iNumberOfRecords as integer
505 Dim iNumberOfFields as integer
507 iNumberOfRecords = ubound(aFieldContent)
508 iNumberOfFields = ubound(aFieldContent,2)
510 call fOpenTable(sTableName)
513 for iCounterOfRecords = 1 to iNumberOfRecords
514 for iCounterOfFields = 1 to iNumberOfFields
515 TableView.TypeKeys aFieldContent(iCounterOfRecords,iCounterOfFields),TRUE
516 TableView.TypeKeys "<TAB>",TRUE
526 '-------------------------------------------------------------------------
527 function fCloseTableDesign(optional bSave)
528 '/// close an open table design
529 '/// <u>parameter:</u>
530 '/// <b><i>optional</i> bSave:</b> if true then the table design is saved
534 Kontext "TableDesignTable"
535 TableDesignTable.UseMenu
536 ' bug file / close close the whole database
537 hMenuSelectNr(1) ' the file menu
538 hMenuSelectNr(4) ' the Close Window
540 'hMenuSelectNr(6) ' the window menu
541 'hMenuSelectNr(1) ' the Close Window
544 if Messagebox.Exists(3) then
548 fCloseTableDesign = true
550 '-------------------------------------------------------------------------
551 function fCloseTableView()
552 '/// close an open table view
553 '/// <u>parameter:</u>
559 ' bug file / close close the whole database
560 'hMenuSelectNr(1) ' the file menu
561 'hMenuSelectNr(4) ' the Close Window
563 hMenuSelectNr(6) ' the window menu
564 hMenuSelectNr(1) ' the Close Window
565 ' if messages box appear because of unsaved record click no in the dialog
567 if Messagebox.Exists(3) then
571 fCloseTableView = true
573 '-------------------------------------------------------------------------
574 function fOpenRelationDesign()
575 '/// open a new relation design
576 '/// <u>parameter:</u>
579 if ( Database.NotExists(3) ) then
580 fOpenRelationDesign = false
584 Database.MouseDown(50,50)
585 Database.MouseUp(50,50)
593 fOpenRelationDesign = true
595 '-------------------------------------------------------------------------
596 function fCloseRelationDesign(optional bSave)
597 '/// close an open relation design
598 '/// <u>parameter:</u>
599 '/// <b><i>optional</i> bSave:</b> if true then the relation design is saved
602 Kontext "RelationDesign"
603 RelationDesign.UseMenu
604 ' bug file / close close the whole database
605 hMenuSelectNr(1) ' the file menu
606 hMenuSelectNr(4) ' the Close Window
608 'hMenuSelectNr(6) ' the window menu
609 'hMenuSelectNr(1) ' the Close Window
612 if Messagebox.Exists(3) then
613 if ( IsMissing( bSave ) ) then
624 fCloseRelationDesign = true
626 '-------------------------------------------------------------------------
627 function fOpenNewTableDesign
628 printlog "fOpenNewTableDesign called"
630 printlog "check if Database exists"
633 Database.MouseDown(50,50)
634 Database.MouseUp(50,50)
636 if ( Database.NotExists(3) ) then
637 fOpenNewTableDesign = false
638 warnlog "The Database windows doesn't exists"
644 printlog "open new table design"
650 fOpenNewTableDesign = true
653 '-------------------------------------------------------------------------
654 function fOpenTableInDesign(sTableName as String)
655 printlog "fOpenTableInDesign called"
657 printlog "check if Database exists"
660 Database.MouseDown(50,50)
661 Database.MouseUp(50,50)
663 if ( Database.NotExists(3) ) then
664 fOpenTableInDesign = false
665 warnlog "The Database windows doesn't exists"
671 printlog "open new table design"
673 call fFindTable(sTableName)
677 Kontext "TableDesignTable"
678 if ( not TableDesignTable.exists(3) ) then
679 warnlog "The Table design doesn't open"
680 fOpenTableInDesign = false
684 fOpenTableInDesign = true
687 '-------------------------------------------------------------------------
688 function fFindTableInBeamer(sDSName1,sTableName1)
689 '/// select a table with the given name in the beamer
690 '/// <u>parameter:</u>
691 '/// <b>sDSName1:</b> the name of the datasource
692 '/// <b>sTableName1:</b> the name of the table
695 dim bfindTable as boolean
697 dim iNoTable as integer
700 Kontext "DatabaseBeamer"
701 Kontext "DatabaseSelection"
703 iNoDS = DatabaseSelection.getItemCount
705 DatabaseSelection.Select i
706 if DatabaseSelection.getText = sDSName1 then
712 if (bfindTable = false) then
713 warnlog "Datasource " + sDSName1 + " not found!"
716 printlog "Datasource " + sDSName1 + " found!"
717 ' I set the bfindTable flag again back to false
718 ' for the next test of the table
723 DatabaseSelection.TypeKeys "<ADD>" , true
725 DatabaseSelection.TypeKeys "<DOWN>" , true
727 DatabaseSelection.TypeKeys "<DOWN>" , true
729 DatabaseSelection.TypeKeys "<ADD>" , true
731 DatabaseSelection.TypeKeys "<DOWN>" , true
735 iNoTable = DatabaseSelection.getItemCount
737 ii = DatabaseSelection.GetSelIndex
738 for i = ii to iNoTable
739 DatabaseSelection.Select i
740 if DatabaseSelection.getText = sTableName1 then
747 fFindTableInBeamer = bfindTable
750 '-------------------------------------------------------------------------
751 function fStartTableWizard()
752 '/// start the table wizard
753 '/// <u>parameter:</u>
756 if ( Database.NotExists(3) ) then
757 fStartTableWizard = false
761 Database.MouseDown(50,50)
762 Database.MouseUp(50,50)
771 fStartTableWizard = true