1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sdbc_XResultSetUpdate" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9' 10' Copyright 2000, 2010 Oracle and/or its affiliates. 11' 12' OpenOffice.org - a multi-platform office productivity suite 13' 14' This file is part of OpenOffice.org. 15' 16' OpenOffice.org is free software: you can redistribute it and/or modify 17' it under the terms of the GNU Lesser General Public License version 3 18' only, as published by the Free Software Foundation. 19' 20' OpenOffice.org is distributed in the hope that it will be useful, 21' but WITHOUT ANY WARRANTY; without even the implied warranty of 22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23' GNU Lesser General Public License version 3 for more details 24' (a copy is included in the LICENSE file that accompanied this code). 25' 26' You should have received a copy of the GNU Lesser General Public License 27' version 3 along with OpenOffice.org. If not, see 28' <http://www.openoffice.org/license.html> 29' for a copy of the LGPLv3 License. 30' 31'************************************************************************* 32'************************************************************************* 33 34 35 36'************************************************************************* 37' This Interface/Service test depends on the following GLOBAL variables, 38' which must be specified in the object creation: 39 40' - Global textColumn As String 41 42'************************************************************************* 43 44 45 46 47 48Sub RunTest() 49 50'************************************************************************* 51' INTERFACE: 52' com.sun.star.sdbc.XResultSetUpdate 53'************************************************************************* 54On Error Goto ErrHndl 55 Dim bOK As Boolean 56 Dim iCount As Integer 57 Dim cString As String 58 Dim colIdx As Integer 59 60 colIdx = oObj.findColumn(textColumn) 61 62 Test.StartMethod("insertRow()") 63 bOK = true 64 iCount = countRows() 65 Out.Log("Initially " + countRows() + " records") 66 oObj.moveToInsertRow() 67 oObj.updateString(colIdx, "New string") 68 oObj.insertRow() 69 Out.Log("After inserting " + countRows() + " records") 70 oObj.last() 71 bOK = bOK AND oObj.getString(colIdx) = "New string" 72 bOK = bOK AND iCount = countRows() - 1 73 Test.MethodTested("insertRow()", bOK) 74 75 Test.StartMethod("cancelRowUpdates()") 76 bOK = true 77 oObj.last() 78 oObj.updateString(colIdx, "Changed string") 79 oObj.cancelRowUpdates() 80 bOK = bOK AND oObj.getString(colIdx) = "New string" 81 bOK = bOK AND iCount = countRows() - 1 82 Test.MethodTested("cancelRowUpdates()", bOK) 83 84 Test.StartMethod("updateRow()") 85 bOK = true 86 oObj.last() 87 oObj.updateString(colIdx, "Changed string") 88 oObj.updateRow() 89 bOK = bOK AND oObj.getString(colIdx) = "Changed string" 90 bOK = bOK AND iCount = countRows() - 1 91 Test.MethodTested("updateRow()", bOK) 92 93 Test.StartMethod("deleteRow()") 94 Dim rowsBefore As Integer, rowsAfter As Integer 95 bOK = true 96 rowsBefore = countRows() 97 oObj.Last() 98 oObj.deleteRow() 99 rowsAfter = countRows() 100 Out.Log("Rows before: " + rowsBefore + ", rows after: " + rowsAfter) 101 bOK = bOK AND iCount = rowsAfter 102 oObj.Last() 103 Out.Log(oObj.getString(colIdx)) 104 Test.MethodTested("deleteRow()", bOK) 105 106 Test.StartMethod("moveToInsertRow()") 107 bOK = true 108 oObj.moveToInsertRow() 109 bOK = bOK AND oObj.getString(colIdx) = "" 110 Test.MethodTested("moveToInsertRow()", bOK) 111 112 Test.StartMethod("moveToCurrentRow()") 113 bOK = true 114 oObj.first() 115 oObj.next() 116 cString = oObj.getString(colIdx) 117 oObj.moveToInsertRow() 118 oObj.moveToCurrentRow() 119 bOK = bOK AND oObj.getString(colIdx) = cString 120 Test.MethodTested("moveToCurrentRow()", bOK) 121 122Exit Sub 123ErrHndl: 124 Test.Exception() 125 bOK = false 126 resume next 127End Sub 128Function countRows() As Integer 129 Dim iCount As Integer 130 iCount = 0 131 oObj.first() 132 while NOT oObj.isAfterLast() 133 iCount = iCount + 1 134 oObj.next() 135 wend 136 countRows() = iCount 137End Function 138</script:module> 139