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