summaryrefslogtreecommitdiff
path: root/testautomation/dbaccess/tools/dbtools.inc
blob: 2b3ee43557214a7833c3de06e121174f922c5084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
'encoding UTF-8  Do not remove or change this line!
'**************************************************************************
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'/************************************************************************
'*
'* owner : marc.neumann@sun.com
'*
'* short description : Helper Routines for Base tests.
'*
'***************************************************************************************
'*
' #1 fSelectDatasourceInBeamer
' #1 fConnectToDatasourceInBeamer
' #1 fSelectSchemaInTableFilter
' #1 fOpenNewDataBase
' #1 fOpenDataBase
' #1 fCloseDatabase
' #1 tools_dbtools_fgetMySQLDatabaseProperties
'*
'\***********************************************************************************
'--------------------------------------------------------------------
function fSelectDatasourceInBeamer(sDSName1)
	'/// select a datasource in the beamer with the given name
    '/// <u>parameter:</u>
    '/// <b>sDSName1:</b> the name of the datasource which shall be seleced
            
	dim i as integer
	dim bfindDS as boolean
	dim iNoDS as integer    
    
    bfindDS = false
	Kontext "DatabaseBeamer"
    Kontext "DatabaseSelection"
		
    iNoDS = DatabaseSelection.getItemCount	
	for i = 1 to iNoDS
		DatabaseSelection.Select i
		if DatabaseSelection.getText = sDSName1 then
			i = iNoDS
            bfindDS = TRUE
		endif
	next i	
	
    fSelectDatasourceInBeamer = bfindDS
	
    sleep(1)
    
end function
'--------------------------------------------------------------------
function fConnectToDatasourceInBeamer(sDSName , sPWD, optional bNewDoc)
    
    if ( isMissing (bNewDoc) )then
        bNewDoc = false
    endif
    
    if (bNewDoc) then
        call hNewDocument()
        ViewCurrentDatabase
    endif
    
    sleep(1)
    dim bConnect as boolean 
    bConnect = false
    if fFindDatasource(sDSName) = true then
        DatabaseSelection.TypeKeys "<ADD>"
        DatabaseSelection.TypeKeys "<DOWN>"
        DatabaseSelection.TypeKeys "<DOWN>"
        DatabaseSelection.TypeKeys "<DOWN>"
        DatabaseSelection.TypeKeys "<ADD>"                
        Kontext "LoginDialog"
            if LoginDialog.Exists(3) then
                Password.SetText sPWD
                LoginDialog.OK                
            end if
        bConnect = true    
    else
        warnlog "Could not found the datasource " + sDSName
    endif
    
    if (bNewDoc) then
        call hCloseDocument
    endif
    
    fConnectToDatasource = bConnect
    
end function
'--------------------------------------------------------------------
function fSelectSchemaInTableFilter(sSchema as String)
	'/// select the given schema in the table filter dialog in an open database
	'/// <u>parameter:</u>
	'/// <b>sSchema:</b> the name of the schema
    dim bOK as boolean
    bOK = false
    
    dim iRem as integer
	iRem = 0
    Kontext "DATABASE"
        Database.useMenu
        hMenuSelectNr 5
        hMenuSelectNr 3
    
     
    Kontext "TablesFilter"
        printlog Tables.getItemCount
        TablesFilter.OK
        
    fSelectSchemaInTableFilter = true
    
end function
'-------------------------------------------------------------------------
function fOpenNewDataBase ( sSaveFileName )    
    '/// open a database window and sabe it to the given name
    '/// <u>parameter:</u>
    '/// <b>sSaveFileName:</b> the file name for the database file
    FileOpen "FileName", "private:factory/sdatabase" , "FrameName", "_blank" , "SynchronMode" ,True
    
    sleep(2)
    
    Kontext "SpeichernDlg"
        Dateiname.setText Convertpath(gOfficePath + "/user/work/" + sSaveFileName)    
        Speichern.click
        sleep(1)
        
    Kontext "MessageBox" 
        if MessageBox.exists then
            MessageBox.yes
        end if
        
    sleep(5)

end function
'-------------------------------------------------------------------------
function fOpenDataBase ( sFileName , optional sPassword)    
    '/// open a database file with the given name and try to connect
    '/// <u>parameter:</u>
    '/// <b>sFileName:</b> the file name which shall be open
    '/// <b><i>optional</i>sFileName:</b> the password for connecting                

    Dim bOK as boolean
    bOK = true
    
    Dim DieDatei as String
    DieDatei = ConvertPath ( sFileName )
    '/// open the File Open dialog
    printlog "open the File Open dialog"
    FileOpen
    sleep (1)
    Kontext "OeffnenDlg"
    '/// open the given file
    printlog "open the given file: " + sFileName
    Dateiname.SetText DieDatei
    sleep (3)
    Oeffnen.Click
    sleep (3)
    
    'click on the main window to get the focus
    Kontext "DATABASE"    
    Database.MouseDown(50,50)
    Database.MouseUp(50,50) 
    
    ViewTables
    sleep(1)
    
    Kontext "DATABASE"
    '/// if the password is given add the password    
    if ( Not IsMissing(sPassword) ) then
        printlog "set password : " + sPassword
        Kontext "LoginDialog"
        if LoginDialog.Exists then
         	Password.setText sPassword
         	LoginDialog.OK
            sleep(1)
        endif
    endif
    Kontext "MessageBox"
    if (MessageBox.exists(2)) then
        'an error occurr    
        bOK = false
        dim iNrTexts as integer
        Dim i as integer
        iNrtexts = MessageBox.getFixedtextCount
        for i = 1 to iNrtexts
            qaerrorlog MessageBox.getFixedtext(i)
        next
        MessageBox.OK
        ' try again to close the dialog if exists
        if (MessageBox.exists(2)) then 	       
    	    MessageBox.OK
    	endif
        call fCloseDatabase
    endif
    
    fOpenDataBase = bOK
    
end function
'-------------------------------------------------------------------------
function fCloseDatabase(optional bSave)
    '/// close the database
    '/// <u>parameter:</u>
    '/// <b><i>optional</i>bSave:</b> if true the the database is saved if false then the changes are lost
    sleep(1)
 	Kontext "DATABASE"
        Database.MouseDown(50,50)
        Database.MouseUp(50,50)
        Database.useMenu
        hMenuSelectNr 1
        hMenuSelectNr 5    
        
    Kontext "Messagebox"
        if Messagebox.Exists(3) then
            if ( IsMissing( bSave ) ) then
                Messagebox.No
            else
                if bSave then
                    Messagebox.Yes
                else
                    Messagebox.No
                endif
            endif
        end if
        
    sleep(1)        
        
end function
'-------------------------------------------------------------------------
sub sCloseAllToolbars
    
    Kontext "FormControls"
    if FormControls.exists(1) then 
        FormControls.close()
    endif

    Kontext "MoreControls"
    if MoreControls.exists(1) then
        MoreControls.close()
    endif

    Kontext "FormDesignTools"
    if FormDesignTools.exists(1) then
        FormDesignTools.close()
    endif

end sub
'-------------------------------------------------------------------------
function tools_dbtools_fgetMySQLJDBCDatabaseProperties()
    '/// return the databaseserver properties from the environment directory
	'/// <u>parameter:</u>
	'/// <br>
    '/// <u>return:</u>
	'/// the properties as an array
    '/// entry 1 defined (yes or no)
    '/// entry 2 server name 
    '/// entry 3 database name
    '/// entry 4 database port
    '/// entry 5 database user name
    '/// entry 6 database user password        

    dim i as integer
    dim b(10000) as String
    dim c
    c = hGetDataFileSection( gTesttoolPath + gPrivateEnvironmentLocation + "input/base.txt", b(), "mysql_jdbc" , "" , "" )
    
    ' split the string at = and return the right part 
    for i = 1 to 6
        'printlog b(i)
        b(i) = Right(b(i),len(b(i))-Instr(b(i),"="))    
        'printlog b(i)        
    next
    
    tools_dbtools_fgetMySQLJDBCDatabaseProperties = b() 

end function
'-------------------------------------------------------------------------
function tools_dbtools_fgetMySQLODBCDatabaseProperties()
    '/// return the databaseserver properties from the environment directory
	'/// <u>parameter:</u>
	'/// <br>
    '/// <u>return:</u>
	'/// the properties as an array
    '/// entry 1 defined (yes or no)
    '/// entry 2 odbc dsn name
    '/// entry 3 database user name
    '/// entry 4 database user password        

    dim i as integer
    dim b(10000) as String
    dim c
    c = hGetDataFileSection( gTesttoolPath + gPrivateEnvironmentLocation + "input/base.txt", b(), "mysql_odbc" , "" , "" )
    
    ' split the string at = and return the right part 
    for i = 1 to 4
        'printlog b(i)
        b(i) = Right(b(i),len(b(i))-Instr(b(i),"="))    
        'printlog b(i)        
    next
    
    tools_dbtools_fgetMySQLODBCDatabaseProperties = b() 

end function
'-------------------------------------------------------------------------
function tools_dbtools_fgetAdabasDatabaseProperties()
    '/// return the databaseserver properties from the environment directory
	'/// <u>parameter:</u>
	'/// <br>
    '/// <u>return:</u>
	'/// the properties as an array
    '/// entry 1 defined (yes or no)
    '/// entry 2 server name 
    '/// entry 3 database name    
    '/// entry 4 database user name
    '/// entry 5 database user password        

    dim i as integer
    dim b(10000) as String
    dim c
    c = hGetDataFileSection( gTesttoolPath + gPrivateEnvironmentLocation + "input/base.txt", b(), "adabas" , "" , "" )
    
    ' split the string at = and return the right part 
    for i = 1 to 5
        'printlog b(i)
        b(i) = Right(b(i),len(b(i))-Instr(b(i),"="))    
        'printlog b(i)        
    next
    
    tools_dbtools_fgetAdabasDatabaseProperties = b() 

end function