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'*************************************************************************
38' This Interface/Service test depends on the following GLOBAL variables,
39' which must be specified in the object creation:
40
41'     - Global textColumn As String
42
43'*************************************************************************
44
45
46
47
48
49Sub RunTest()
50
51'*************************************************************************
52' INTERFACE:
53' com.sun.star.sdbc.XResultSetUpdate
54'*************************************************************************
55On Error Goto ErrHndl
56    Dim bOK As Boolean
57    Dim iCount As Integer
58    Dim cString As String
59    Dim colIdx As Integer
60
61    colIdx = oObj.findColumn(textColumn)
62
63    Test.StartMethod("insertRow()")
64    bOK = true
65    iCount = countRows()
66    Out.Log("Initially " + countRows() + " records")
67    oObj.moveToInsertRow()
68    oObj.updateString(colIdx, "New string")
69    oObj.insertRow()
70    Out.Log("After inserting " + countRows() + " records")
71    oObj.last()
72    bOK = bOK AND oObj.getString(colIdx) = "New string"
73    bOK = bOK AND iCount = countRows() - 1
74    Test.MethodTested("insertRow()", bOK)
75
76    Test.StartMethod("cancelRowUpdates()")
77    bOK = true
78    oObj.last()
79    oObj.updateString(colIdx, "Changed string")
80    oObj.cancelRowUpdates()
81    bOK = bOK AND oObj.getString(colIdx) = "New string"
82    bOK = bOK AND iCount = countRows() - 1
83    Test.MethodTested("cancelRowUpdates()", bOK)
84
85    Test.StartMethod("updateRow()")
86    bOK = true
87    oObj.last()
88    oObj.updateString(colIdx, "Changed string")
89    oObj.updateRow()
90    bOK = bOK AND oObj.getString(colIdx) = "Changed string"
91    bOK = bOK AND iCount = countRows() - 1
92    Test.MethodTested("updateRow()", bOK)
93
94    Test.StartMethod("deleteRow()")
95    Dim rowsBefore As Integer, rowsAfter As Integer
96    bOK = true
97    rowsBefore = countRows()
98    oObj.Last()
99    oObj.deleteRow()
100    rowsAfter = countRows()
101    Out.Log("Rows before: " + rowsBefore + ", rows after: " + rowsAfter)
102    bOK = bOK AND iCount = rowsAfter
103    oObj.Last()
104    Out.Log(oObj.getString(colIdx))
105    Test.MethodTested("deleteRow()", bOK)
106
107    Test.StartMethod("moveToInsertRow()")
108    bOK = true
109    oObj.moveToInsertRow()
110    bOK = bOK AND oObj.getString(colIdx) = ""
111    Test.MethodTested("moveToInsertRow()", bOK)
112
113    Test.StartMethod("moveToCurrentRow()")
114    bOK = true
115    oObj.first()
116    oObj.next()
117    cString = oObj.getString(colIdx)
118    oObj.moveToInsertRow()
119    oObj.moveToCurrentRow()
120    bOK = bOK AND oObj.getString(colIdx) = cString
121    Test.MethodTested("moveToCurrentRow()", bOK)
122
123Exit Sub
124ErrHndl:
125    Test.Exception()
126    bOK = false
127    resume next
128End Sub
129Function countRows() As Integer
130    Dim iCount As Integer
131    iCount = 0
132    oObj.first()
133    while NOT oObj.isAfterLast()
134        iCount = iCount + 1
135        oObj.next()
136    wend
137    countRows() = iCount
138End Function
139</script:module>
140