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'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34
35
36' REQUIRED VARIABLES for interface/service tests:
37
38' Required for  com.sun.star.lang.XComponent:
39  Global oComponentInstance As Object ' it will be disposed
40
41' Required for  com.sun.star.sdbc.XColumnLocate:
42  Global cExistantColumnName As String
43
44' Required for com.sun.star.sdbc.XResultSet
45  Global cXResultSetFirstRecord as String
46  Global cXResultSetLastRecord as String
47  Global cXResultSetRecord1 as String
48  Global cXResultSetRecord2 as String
49  Global cXResultSet2BeforeLastRecord as String
50
51' Required for com.sun.star.sdbc.XParameters
52  Global paramTypes as Variant
53
54' Required for com.sun.star.sdbc.XRow and com.sun.star.sdbc.XRowUpdate
55  Global rowTypes as Variant
56  Global rowTypesCol as Variant
57
58' Required for com.sun.star.sdbc.XResultSetUpdate
59  Global textColumn As String
60
61  Global oConnection As Object
62
63
64Sub CreateObj()
65
66'*************************************************************************
67' COMPONENT:
68' dbaccess.ORowSet
69'*************************************************************************
70On Error Goto ErrHndl
71
72    Dim oRowSet As Object, facc As Object, dbSource As Object
73    Dim srcFile As String, dstFile As String, dbSrcURL As String
74
75    ' Copying DB file to temp location
76    srcFile = utils.Path2URL(cTestDocsDir) + "TestDB/testDB.dbf"
77    dstFile = utils.getTempFileURL("TestDB.dbf")
78    dbSrcURL = "sdbc:dbase:" + utils.StrReplace(dstFile, "/testDB.dbf", "")
79
80    facc = createUnoService("com.sun.star.ucb.SimpleFileAccess")
81
82    if not facc.exists(srcFile) then
83        Out.log("could not find source of testDB.dbf: " + srcFile)
84    end if
85    if (facc.exists(dstFile)) then facc.kill(dstFile)
86    facc.copy(srcFile, dstFile)
87
88    dbtools.RegisterDataSource("DBTest", dbSrcURL)
89
90    oRowSet = createUnoService("com.sun.star.sdb.RowSet")
91
92    oRowSet.DataSourceName = "DBTest"
93    oRowSet.Command = "TestDB"
94    oRowSet.CommandType = com.sun.star.sdb.CommandType.TABLE
95
96    oRowSet.execute()
97
98    wait(200)
99
100    oConnection = oRowSet.ActiveConnection
101
102    if NOT isObject(oConnection) then
103        Out.Log("oConnection wasn't retrieved properly !!!")
104    end if
105
106    oRowSet.first()
107
108    Out.Log("The first record has: '" + oRowSet.getString(1) + "'")
109
110    oObj = oRowSet
111
112    oComponentInstance = createUnoService("com.sun.star.sdb.RowSet")
113    cExistantColumnName = "_TEXT"
114    cXResultSetFirstRecord = "text1"
115    cXResultSetLastRecord = "text3"
116    cXResultSetRecord1 = "text1"
117    cXResultSetRecord2 = "text2"
118    cXResultSet2BeforeLastRecord = "text2"
119
120    paramTypes = DimArray()
121
122'    paramTypes = Array("boolean", "byte", "short", "int", "long", "float", "double", "string", _
123'        "bytes", "date", "time", "timestamp", "binarystream", "characterstream", "object", _
124'        "ref", "blob", "clob", "array")
125
126
127'    Dim dat As new com.sun.star.util.Date
128'    Dim tim As new com.sun.star.util.Time
129'    Dim datTim As new com.sun.star.util.DateTime
130
131'    dat.Year = 2001
132'    dat.Month = 1
133'    dat.Day = 1
134
135'    tim.Hours = 1
136'    tim.Minutes = 1
137'    tim.Seconds = 1
138
139'    paramVal = Array(true, 11, 11, 111, NULL, 1.1, 11.11, "text1", NULL, dat, tim, NULL, NULL, NULL, NULL,
140'        NULL, NULL, NULL, NULL)
141
142    ' for XRow and XRowUpdate
143    rowTypes = Array("string", "int", "long", "double", "float", "date", "datetm", "boolean")
144    rowTypesCol = Array(1, 2, 3, 4, 5, 6, 7, 9)
145'    rowTypes = Array("boolean", "byte", "short", "int", "long", "float", "double", "string", _
146'        "bytes", "date", "time", "timestamp", "binarystream", "characterstream", "object", _
147'        "numericobject")
148
149
150
151' Required for com.sun.star.sdbc.XResultSetUpdate
152    textColumn = "_TEXT"
153
154Exit Sub
155ErrHndl:
156    Test.Exception()
157End Sub
158
159Sub DisposeObj()
160On Error Goto ErrHndl
161    Out.Log("Closing DB connection ...")
162    oConnection.close()
163
164    Out.Log("Revoking 'DBTest' datasource ...")
165    dbtools.RevokeDB("DBTest")
166Exit Sub
167ErrHndl:
168    Test.Exception()
169    resume next
170End Sub
171</script:module>
172