2010-06-23 06:47:42 -05:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!--**********************************************************************
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
**********************************************************************-->
|
|
|
|
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
|
|
|
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Test_DB" script:language="StarBasic">REM ***** Database Test *****
|
|
|
|
|
|
|
|
const cMessageDatabaseService = "Database Service"
|
|
|
|
const cMessageDatabaseOpen = "Open Database"
|
|
|
|
const cMessageDatabaseInsert = "Insert record into Database"
|
|
|
|
const cMessageDatabaseDelete = "Delete record from Database"
|
|
|
|
const cMessageDatabaseSeek = "Read other record from Database"
|
|
|
|
const cMessageDatabaseClose = "Close Database"
|
|
|
|
|
2011-02-08 05:59:00 -06:00
|
|
|
Sub TestDB
|
2010-06-23 06:47:42 -05:00
|
|
|
|
2011-02-08 05:59:01 -06:00
|
|
|
Dim oDBConnection as Object, oDataSource as Object, oDBContext as Object
|
|
|
|
Dim sDBName as String, sTable as String, sCurrentMessage as String
|
|
|
|
Dim nRowCount as Integer
|
|
|
|
Dim bResult as Boolean
|
|
|
|
Const sTestString = "Automatical Test"
|
2010-06-23 06:47:42 -05:00
|
|
|
|
|
|
|
On Local Error GoTo DBERROR
|
|
|
|
|
2011-02-08 05:59:01 -06:00
|
|
|
g_CurrentTestCase = cLogfileFailed
|
2011-02-08 05:59:00 -06:00
|
|
|
FileChannel% = OpenLogDat (GetLogFileName(g_CurrentDocTest))
|
2010-06-23 06:47:42 -05:00
|
|
|
|
2011-02-08 05:59:01 -06:00
|
|
|
g_CurrentTestCase = cDBService
|
2010-06-23 06:47:42 -05:00
|
|
|
sCurrentMessage = cMessageDatabaseService + " " + cUnoDatabaseContext
|
|
|
|
|
|
|
|
oDBContext = CreateUnoService(cUnoDatabaseContext)
|
|
|
|
sDBName=oDBContext.ElementNames(0) 'Names of Databases
|
|
|
|
|
2011-02-08 05:59:01 -06:00
|
|
|
g_CurrentTestCase = cDBOpen
|
2010-06-23 06:47:42 -05:00
|
|
|
sCurrentMessage = cMessageDatabaseOpen
|
|
|
|
|
|
|
|
oDataSource = oDBContext.GetByName(sDBName)
|
|
|
|
sTable=oDataSource.Tables.ElementNames(0)
|
|
|
|
oDBConnection = oDBContext.GetByName(sDBName).GetConnection("","")
|
|
|
|
|
2011-02-08 05:59:01 -06:00
|
|
|
LogTestResult( "Database "+ cMessageDatabaseOpen, not IsNull (oDBConnection) )
|
2010-06-23 06:47:42 -05:00
|
|
|
if (IsNull(oDBConnection)) then
|
|
|
|
Close #FileChannel%
|
|
|
|
Exit Sub
|
|
|
|
End If
|
|
|
|
|
|
|
|
' Database is open now
|
|
|
|
|
2011-02-08 05:59:01 -06:00
|
|
|
g_CurrentTestCase = cDBService
|
2010-06-23 06:47:42 -05:00
|
|
|
sCurrentMessage = cMessageDatabaseService + " " + cUnoRowSet
|
|
|
|
oRowSet = createUnoService(cUnoRowSet)
|
|
|
|
|
|
|
|
if (IsNull(oRowSet)) then
|
2011-02-08 05:59:01 -06:00
|
|
|
LogTestResult( "Database "+ cMessageDatabaseService + " " + cUnoRowSet, not IsNull (oRowSet) )
|
2010-06-23 06:47:42 -05:00
|
|
|
Exit Sub
|
|
|
|
else
|
2011-02-08 05:59:01 -06:00
|
|
|
LogTestResult( "Database "+ cMessageDatabaseService, TRUE )
|
2010-06-23 06:47:42 -05:00
|
|
|
End If
|
|
|
|
|
2011-02-08 05:59:01 -06:00
|
|
|
g_CurrentTestCase = cDBInsert
|
2010-06-23 06:47:42 -05:00
|
|
|
sCurrentMessage = cMessageDatabaseInsert
|
|
|
|
|
|
|
|
oRowSet.ActiveConnection = oDBConnection
|
|
|
|
|
|
|
|
oRowSet.CommandType = com.sun.star.sdb.CommandType.COMMAND
|
|
|
|
oRowSet.Command = "SELECT * FROM " + sTable
|
|
|
|
oRowSet.execute()
|
|
|
|
|
|
|
|
oRowSet.moveToInsertRow
|
|
|
|
oRowSet.updateString(5, sTestString)
|
|
|
|
|
|
|
|
oRowSet.insertRow()
|
|
|
|
nRowCount=oRowSet.RowCount
|
|
|
|
|
|
|
|
oRowSet.moveToCurrentRow()
|
|
|
|
|
|
|
|
bResult = (oRowSet.getString(5) = sTestString)
|
2011-02-08 05:59:01 -06:00
|
|
|
LogTestResult( "Database "+ cMessageDatabaseInsert, bResult )
|
2010-06-23 06:47:42 -05:00
|
|
|
|
|
|
|
'delete only if insert passed
|
|
|
|
|
|
|
|
if (bResult) Then
|
2011-02-08 05:59:01 -06:00
|
|
|
g_CurrentTestCase = cDBDelete
|
2010-06-23 06:47:42 -05:00
|
|
|
sCurrentMessage = cMessageDatabaseDelete
|
|
|
|
oRowSet.deleteRow()
|
|
|
|
bResult = (nRowCount - oRowSet.RowCount = 0)
|
|
|
|
if ( bResult ) Then
|
|
|
|
oRowSet.next()
|
|
|
|
bResult = (nRowCount - oRowSet.RowCount = 1)
|
|
|
|
End If
|
2011-02-08 05:59:01 -06:00
|
|
|
LogTestResult( "Database "+ cMessageDatabaseDelete, bResult )
|
2010-06-23 06:47:42 -05:00
|
|
|
End If
|
|
|
|
|
|
|
|
' read other record
|
|
|
|
|
2011-02-08 05:59:01 -06:00
|
|
|
g_CurrentTestCase = cDBSeek
|
2010-06-23 06:47:42 -05:00
|
|
|
sCurrentMessage = cMessageDatabaseSeek
|
|
|
|
oRowSet.first()
|
|
|
|
bResult = not (oRowSet.getString(5) = sTestString)
|
2011-02-08 05:59:01 -06:00
|
|
|
LogTestResult( "Database "+ cMessageDatabaseSeek, bResult )
|
2010-06-23 06:47:42 -05:00
|
|
|
|
2011-02-08 05:59:01 -06:00
|
|
|
g_CurrentTestCase = cDBClose
|
2010-06-23 06:47:42 -05:00
|
|
|
sCurrentMessage = cMessageDatabaseClose
|
|
|
|
oDBConnection.Dispose()
|
2011-02-08 05:59:01 -06:00
|
|
|
LogTestResult( "Database "+ cMessageDatabaseClose, True )
|
2010-06-23 06:47:42 -05:00
|
|
|
|
|
|
|
Print #FileChannel, "---"
|
|
|
|
Close #FileChannel%
|
|
|
|
Exit Sub ' Without error
|
|
|
|
|
|
|
|
DBERROR:
|
2011-02-08 05:59:01 -06:00
|
|
|
If ( g_CurrentTestCase = cLogfileFailed ) then
|
|
|
|
LogTestResult( "", False )
|
2010-06-23 06:47:42 -05:00
|
|
|
Exit Sub
|
|
|
|
else
|
2011-02-08 05:59:01 -06:00
|
|
|
LogTestResult( "Database "+ sCurrentMessage, FALSE )
|
2010-06-23 06:47:42 -05:00
|
|
|
Close #FileChannel%
|
|
|
|
End If
|
|
|
|
Exit Sub ' With error
|
|
|
|
End Sub
|
|
|
|
</script:module>
|