xref: /trunk/test/smoketestdoc/data/Test_DB.xml (revision a622bb93)
1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
25111cb72SAndrew Rist<!--***********************************************************
35111cb72SAndrew Rist *
45111cb72SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
55111cb72SAndrew Rist * or more contributor license agreements.  See the NOTICE file
65111cb72SAndrew Rist * distributed with this work for additional information
75111cb72SAndrew Rist * regarding copyright ownership.  The ASF licenses this file
85111cb72SAndrew Rist * to you under the Apache License, Version 2.0 (the
95111cb72SAndrew Rist * "License"); you may not use this file except in compliance
105111cb72SAndrew Rist * with the License.  You may obtain a copy of the License at
115111cb72SAndrew Rist *
125111cb72SAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
135111cb72SAndrew Rist *
145111cb72SAndrew Rist * Unless required by applicable law or agreed to in writing,
155111cb72SAndrew Rist * software distributed under the License is distributed on an
165111cb72SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
175111cb72SAndrew Rist * KIND, either express or implied.  See the License for the
185111cb72SAndrew Rist * specific language governing permissions and limitations
195111cb72SAndrew Rist * under the License.
205111cb72SAndrew Rist *
215111cb72SAndrew Rist ***********************************************************-->
225111cb72SAndrew Rist
235111cb72SAndrew Rist
24cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
25cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Test_DB" script:language="StarBasic">REM  *****  Database Test  *****
26cdf0e10cSrcweir
27cdf0e10cSrcweirconst cMessageDatabaseService = &quot;Database Service&quot;
28cdf0e10cSrcweirconst cMessageDatabaseOpen = &quot;Open Database&quot;
29cdf0e10cSrcweirconst cMessageDatabaseInsert = &quot;Insert record into Database&quot;
30cdf0e10cSrcweirconst cMessageDatabaseDelete = &quot;Delete record from Database&quot;
31cdf0e10cSrcweirconst cMessageDatabaseSeek = &quot;Read other record from Database&quot;
32cdf0e10cSrcweirconst cMessageDatabaseClose = &quot;Close Database&quot;
33cdf0e10cSrcweir
34cdf0e10cSrcweirSub TestDB
35cdf0e10cSrcweir
36cdf0e10cSrcweir	Dim oDBConnection as Object, oDataSource as Object, oDBContext as Object
37cdf0e10cSrcweir	Dim sDBName as String, sTable as String, sCurrentMessage as String
38cdf0e10cSrcweir	Dim nRowCount as Integer
39cdf0e10cSrcweir	Dim bResult as Boolean
40cdf0e10cSrcweir	Const sTestString = &quot;Automatical Test&quot;
41cdf0e10cSrcweir
42cdf0e10cSrcweir	On Local Error GoTo DBERROR
43cdf0e10cSrcweir
44cdf0e10cSrcweir	gCurrentTestCase = cLogfileFailed
45cdf0e10cSrcweir	LocalTestLog% = OpenLogDat (GetLogFileName(gCurrentDocTest))
46cdf0e10cSrcweir
47cdf0e10cSrcweir	gCurrentTestCase = cDBService
48cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseService + &quot; &quot; + cUnoDatabaseContext
49cdf0e10cSrcweir
50cdf0e10cSrcweir	oDBContext = CreateUnoService(cUnoDatabaseContext)
51cdf0e10cSrcweir	sDBName=oDBContext.ElementNames(0) &apos;Names of Databases
52cdf0e10cSrcweir
53cdf0e10cSrcweir	gCurrentTestCase = cDBOpen
54cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseOpen
55cdf0e10cSrcweir
56cdf0e10cSrcweir	oDataSource = oDBContext.GetByName(sDBName)
57cdf0e10cSrcweir	sTable=oDataSource.Tables.ElementNames(0)
58cdf0e10cSrcweir	oDBConnection = oDBContext.GetByName(sDBName).GetConnection(&quot;&quot;,&quot;&quot;)
59cdf0e10cSrcweir
60cdf0e10cSrcweir	LogTestResult( &quot;Database &quot;+ cMessageDatabaseOpen, not IsNull (oDBConnection) )
61cdf0e10cSrcweir	if (IsNull(oDBConnection)) then
62cdf0e10cSrcweir   	Close #LocalTestLog%
63cdf0e10cSrcweir		LocalTestLog = 0
64cdf0e10cSrcweir		Exit Sub
65cdf0e10cSrcweir	End If
66cdf0e10cSrcweir
67cdf0e10cSrcweir	&apos; Database is open now
68cdf0e10cSrcweir
69cdf0e10cSrcweir	gCurrentTestCase = cDBService
70cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseService + &quot; &quot; + cUnoRowSet
71cdf0e10cSrcweir	oRowSet = createUnoService(cUnoRowSet)
72cdf0e10cSrcweir
73cdf0e10cSrcweir	if (IsNull(oRowSet)) then
74cdf0e10cSrcweir		LogTestResult( &quot;Database &quot;+ cMessageDatabaseService + &quot; &quot; + cUnoRowSet, not IsNull (oRowSet) )
75cdf0e10cSrcweir		Exit Sub
76cdf0e10cSrcweir	else
77cdf0e10cSrcweir		LogTestResult( &quot;Database &quot;+ cMessageDatabaseService, TRUE )
78cdf0e10cSrcweir	End If
79cdf0e10cSrcweir
80cdf0e10cSrcweir	gCurrentTestCase = cDBInsert
81cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseInsert
82cdf0e10cSrcweir
83cdf0e10cSrcweir	oRowSet.ActiveConnection = oDBConnection
84cdf0e10cSrcweir
85cdf0e10cSrcweir	oRowSet.CommandType = com.sun.star.sdb.CommandType.COMMAND
86cdf0e10cSrcweir	oRowSet.Command = &quot;SELECT * FROM &quot; + sTable
87cdf0e10cSrcweir	oRowSet.execute()
88cdf0e10cSrcweir
89cdf0e10cSrcweir	oRowSet.moveToInsertRow
90cdf0e10cSrcweir	oRowSet.updateString(5, sTestString)
91cdf0e10cSrcweir
92cdf0e10cSrcweir	oRowSet.insertRow()
93cdf0e10cSrcweir	nRowCount=oRowSet.RowCount
94cdf0e10cSrcweir
95cdf0e10cSrcweir	oRowSet.moveToCurrentRow()
96cdf0e10cSrcweir
97cdf0e10cSrcweir	bResult = (oRowSet.getString(5) = sTestString)
98cdf0e10cSrcweir	LogTestResult( &quot;Database &quot;+ cMessageDatabaseInsert, bResult )
99cdf0e10cSrcweir
100cdf0e10cSrcweir	&apos;delete only if insert passed
101cdf0e10cSrcweir
102cdf0e10cSrcweir	if (bResult) Then
103cdf0e10cSrcweir		gCurrentTestCase = cDBDelete
104cdf0e10cSrcweir		sCurrentMessage = cMessageDatabaseDelete
105cdf0e10cSrcweir		oRowSet.deleteRow()
106cdf0e10cSrcweir		bResult = (nRowCount - oRowSet.RowCount = 0)
107cdf0e10cSrcweir		if ( bResult ) Then
108cdf0e10cSrcweir			oRowSet.next()
109cdf0e10cSrcweir			bResult = (nRowCount - oRowSet.RowCount = 1)
110cdf0e10cSrcweir		End If
111cdf0e10cSrcweir		LogTestResult( &quot;Database &quot;+ cMessageDatabaseDelete, bResult )
112cdf0e10cSrcweir	End If
113cdf0e10cSrcweir
114cdf0e10cSrcweir	&apos; read other record
115cdf0e10cSrcweir
116cdf0e10cSrcweir	gCurrentTestCase = cDBSeek
117cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseSeek
118cdf0e10cSrcweir	oRowSet.first()
119cdf0e10cSrcweir	bResult = not (oRowSet.getString(5) = sTestString)
120cdf0e10cSrcweir	LogTestResult( &quot;Database &quot;+ cMessageDatabaseSeek, bResult )
121cdf0e10cSrcweir
122cdf0e10cSrcweir	gCurrentTestCase = cDBClose
123cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseClose
124cdf0e10cSrcweir	oDBConnection.Dispose()
125cdf0e10cSrcweir	LogTestResult( &quot;Database &quot;+ cMessageDatabaseClose, True )
126cdf0e10cSrcweir
127cdf0e10cSrcweir	Print #LocalTestLog, &quot;---&quot;
128cdf0e10cSrcweir	Close #LocalTestLog%
129cdf0e10cSrcweir	LocalTestLog = 0
130cdf0e10cSrcweir	Exit Sub &apos; Without error
131cdf0e10cSrcweir
132cdf0e10cSrcweir	DBERROR:
133cdf0e10cSrcweir	If ( gCurrentTestCase = cLogfileFailed ) then
134cdf0e10cSrcweir		LogTestResult( &quot; &quot;, False )
135cdf0e10cSrcweir		Exit Sub
136cdf0e10cSrcweir	else
137cdf0e10cSrcweir		LogTestResult( &quot;Database &quot;+ sCurrentMessage, FALSE )
138cdf0e10cSrcweir		Close #LocalTestLog%
139cdf0e10cSrcweir		LocalTestLog = 0
140cdf0e10cSrcweir	End If
141cdf0e10cSrcweir	Exit Sub &apos; With error
142cdf0e10cSrcweirEnd Sub
143cdf0e10cSrcweir</script:module>
144