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="dbaccess_ORowSet" 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' Be sure that all variables are dimensioned:
37option explicit
38
39
40
41' REQUIRED VARIABLES for interface/service tests:
42
43' Required for  com.sun.star.lang.XComponent:
44  Global oComponentInstance As Object ' it will be disposed
45
46' Required for  com.sun.star.sdbc.XColumnLocate:
47  Global cExistantColumnName As String
48
49' Required for com.sun.star.sdbc.XResultSet
50  Global cXResultSetFirstRecord as String
51  Global cXResultSetLastRecord as String
52  Global cXResultSetRecord1 as String
53  Global cXResultSetRecord2 as String
54  Global cXResultSet2BeforeLastRecord as String
55
56' Required for com.sun.star.sdbc.XParameters
57  Global paramTypes as Variant
58
59' Required for com.sun.star.sdbc.XRow and com.sun.star.sdbc.XRowUpdate
60  Global rowTypes as Variant
61  Global rowTypesCol as Variant
62
63' Required for com.sun.star.sdbc.XResultSetUpdate
64  Global textColumn As String
65
66  Global oConnection As Object
67
68
69Sub CreateObj()
70
71'*************************************************************************
72' COMPONENT:
73' dbaccess.ORowSet
74'*************************************************************************
75On Error Goto ErrHndl
76
77    Dim oRowSet As Object, facc As Object, dbSource As Object
78    Dim srcFile As String, dstFile As String, dbSrcURL As String
79
80    ' Copying DB file to temp location
81    srcFile = utils.Path2URL(cTestDocsDir) + "TestDB/testDB.dbf"
82    dstFile = utils.getTempFileURL("TestDB.dbf")
83    dbSrcURL = "sdbc:dbase:" + utils.StrReplace(dstFile, "/testDB.dbf", "")
84
85    facc = createUnoService("com.sun.star.ucb.SimpleFileAccess")
86
87    if not facc.exists(srcFile) then
88        Out.log("could not find source of testDB.dbf: " + srcFile)
89    end if
90    if (facc.exists(dstFile)) then facc.kill(dstFile)
91    facc.copy(srcFile, dstFile)
92
93    dbtools.RegisterDataSource("DBTest", dbSrcURL)
94
95    oRowSet = createUnoService("com.sun.star.sdb.RowSet")
96
97    oRowSet.DataSourceName = "DBTest"
98    oRowSet.Command = "TestDB"
99    oRowSet.CommandType = com.sun.star.sdb.CommandType.TABLE
100
101    oRowSet.execute()
102
103    wait(200)
104
105    oConnection = oRowSet.ActiveConnection
106
107    if NOT isObject(oConnection) then
108        Out.Log("oConnection wasn't retrieved properly !!!")
109    end if
110
111    oRowSet.first()
112
113    Out.Log("The first record has: '" + oRowSet.getString(1) + "'")
114
115    oObj = oRowSet
116
117    oComponentInstance = createUnoService("com.sun.star.sdb.RowSet")
118    cExistantColumnName = "_TEXT"
119    cXResultSetFirstRecord = "text1"
120    cXResultSetLastRecord = "text3"
121    cXResultSetRecord1 = "text1"
122    cXResultSetRecord2 = "text2"
123    cXResultSet2BeforeLastRecord = "text2"
124
125    paramTypes = DimArray()
126
127'    paramTypes = Array("boolean", "byte", "short", "int", "long", "float", "double", "string", _
128'        "bytes", "date", "time", "timestamp", "binarystream", "characterstream", "object", _
129'        "ref", "blob", "clob", "array")
130
131
132'    Dim dat As new com.sun.star.util.Date
133'    Dim tim As new com.sun.star.util.Time
134'    Dim datTim As new com.sun.star.util.DateTime
135
136'    dat.Year = 2001
137'    dat.Month = 1
138'    dat.Day = 1
139
140'    tim.Hours = 1
141'    tim.Minutes = 1
142'    tim.Seconds = 1
143
144'    paramVal = Array(true, 11, 11, 111, NULL, 1.1, 11.11, "text1", NULL, dat, tim, NULL, NULL, NULL, NULL,
145'        NULL, NULL, NULL, NULL)
146
147    ' for XRow and XRowUpdate
148    rowTypes = Array("string", "int", "long", "double", "float", "date", "datetm", "boolean")
149    rowTypesCol = Array(1, 2, 3, 4, 5, 6, 7, 9)
150'    rowTypes = Array("boolean", "byte", "short", "int", "long", "float", "double", "string", _
151'        "bytes", "date", "time", "timestamp", "binarystream", "characterstream", "object", _
152'        "numericobject")
153
154
155
156' Required for com.sun.star.sdbc.XResultSetUpdate
157    textColumn = "_TEXT"
158
159Exit Sub
160ErrHndl:
161    Test.Exception()
162End Sub
163
164Sub DisposeObj()
165On Error Goto ErrHndl
166    Out.Log("Closing DB connection ...")
167    oConnection.close()
168
169    Out.Log("Revoking 'DBTest' datasource ...")
170    dbtools.RevokeDB("DBTest")
171Exit Sub
172ErrHndl:
173    Test.Exception()
174    resume next
175End Sub
176</script:module>
177