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