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="forms_ODatabaseForm" 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' REQUIRED VARIABLES for interface/service tests: 36 37' for XPersistObject 38 Global oPersistInstance As Object 39 40' Required for com.sun.star.lang.XComponent: 41 Global oComponentInstance As Object ' it will be disposed 42 43 ' Requiered for com.sun.star.container.XNameContainer 44 Global oInstance As Object 'instance to insert 45 46 ' Required for com.sun.star.sdbc.XResultSet 47 Global cXResultSetFirstRecord as String 48 Global cXResultSetLastRecord as String 49 Global cXResultSetRecord1 as String 50 Global cXResultSetRecord2 as String 51 Global cXResultSet2BeforeLastRecord as String 52 53' Required for com.sun.star.sdbc.XColumnLocate: 54 Global cExistantColumnName As String 55 56 ' Requiered for com.sun.star.container.XNameReplace 57 Global cNameToReplace As String 'name of instance to be replased 58 Global oReplaceInstance As Object 'instance, that will be inserted 59 'instead old one 60 61 Global oIdxReplaceInstance As Object 62 63' Required for com.sun.star.sdbc.XParameters 64 Global paramTypes as Variant 65 66' Required for com.sun.star.sdbc.XRow and com.sun.star.sdbc.XRowUpdate 67 Global rowTypes as Variant 68 Global rowTypesCol as Variant 69 70' Required for com.sun.star.sdbc.XResultSetUpdate 71 Global textColumn As String 72 73' Required for com.sun.star.awt.XTabControllerModel 74 Global XTabControlModel1 As Object 75 Global XTabControlModel2 As Object 76 77 Global oConnection As Object 78 79' Required for com.sun.star.container.XContainer 80 Global oElementToInsert As Object 81 Global oContainer As Object 82 83Sub CreateObj() 84 85'************************************************************************* 86' COMPONENT: 87' forms.ODatabaseForm 88'************************************************************************* 89On Error Goto ErrHndl 90 Dim bOK As Boolean 91 Dim oRowSet As Object, facc As Object, dbSource As Object 92 Dim srcFile As String, dstFile As String, dbSrcURL As String 93 Dim oDrawPage As Object, oForms As Object, oForm As Object 94 Dim oShape1 As Object, oShape2 As Object 95 96 bOK = true 97 98 ' Copying DB file to temp location 99 srcFile = utils.Path2URL(cTestDocsDir) + "TestDB/testDB.dbf" 100 dstFile = utils.getTempFileURL("TestDB.dbf") 101 dbSrcURL = "sdbc:dbase:" + utils.StrReplace(dstFile, "/testDB.dbf", "") 102 103 Out.Log("Copying file '" + srcFile + "' to '" + dstFile + "'") 104 facc = createUnoService("com.sun.star.ucb.SimpleFileAccess") 105 if (facc.exists(dstFile)) then facc.kill(dstFile) 106 facc.copy(srcFile, dstFile) 107 108 dbtools.RegisterDataSource("DBTest", dbSrcURL) 109 110 ' Creating a form 111 oDoc = utils.createDocument("swriter", cObjectName) 112 113 oShape1 = toolkittools.addControlToDefaultForm("ComboBox", 1000, 1000, 2000, 1000) 114 oShape2 = toolkittools.addControlToDefaultForm("TextField", 1000, 1000, 2000, 1000) 115 'get control from document 116 oDrawPage = oDoc.DrawPage 117 oForms = oDrawPage.getForms() 118 119 oForm = oForms.getByName("Standard") 120 121 oForms.insertByName("Instance1", oDoc.createInstance("com.sun.star.form.component.Form")) 122 oForms.insertByName("Instance2", oDoc.createInstance("com.sun.star.form.component.Form")) 123 124 oObj = oForm 125 126 'connect to a database 127 oForm.DataSourceName = "DBTest" 128 oForm.Command = "TestDB" 129 oForm.CommandType = com.sun.star.sdb.CommandType.TABLE 130 oForm.Load() 131 132 oConnection = oForm.ActiveConnection 133 Dim list as Object 134' list = createUnoListener("C_", "com.sun.star.lang.XEventListener") 135' oConnection.addEventListener(list) 136 137 'for XComponent 138 Out.Log("" + oForms.hasByName("Instance1") + "," + oForms.hasByName("Instance2")) 139 oComponentInstance = oForms.getByName("Instance1") 140 oPersistInstance = oForms.getByName("Instance2") 141 142 'for XNameContainer, XIndexContainer 143 oInstance = oDoc.createInstance("com.sun.star.form.component.ComboBox") 144 145 'for XContainer 146 oElementToInsert = oDoc.createInstance("com.sun.star.form.component.ComboBox") 147 148 'for XNameReplace 149 oReplaceInstance = oDoc.createInstance("com.sun.star.form.component.ComboBox") 150 oObj.insertByName(cObjectName + "Replace", oDoc.createInstance("com.sun.star.form.component.ComboBox")) 151 cNameToReplace = cObjectName + "Replace" 152 153 'for XIndexReplace 154 oIdxReplaceInstance = oDoc.createInstance("com.sun.star.form.component.ComboBox") 155 156 cExistantColumnName = "_TEXT" 157 cXResultSetFirstRecord = "text1" 158 cXResultSetLastRecord = "text3" 159 cXResultSetRecord1 = "text1" 160 cXResultSetRecord2 = "text2" 161 cXResultSet2BeforeLastRecord = "text2" 162 163 ' for XParameters 164 paramTypes = DimArray() 165' paramTypes = Array("boolean", "byte", "short", "int", "long", "float", "double", "string", _ 166' "bytes", "date", "time", "timestamp", "binarystream", "characterstream", "object", "objectwithinfo", _ 167' "ref", "blob", "clob", "array") 168 169 ' for XRow and XRowUpdate 170 rowTypes = Array("string", "int", "long", "double", "float", "date", "datetm", "boolean") 171 rowTypesCol = Array(1, 2, 3, 4, 5, 6, 7, 9) 172' rowTypes = Array("boolean", "byte", "short", "int", "long", "float", "double", "string", _ 173' "bytes", "date", "time", "timestamp", "binarystream", "characterstream", "object", "objectwithinfo", _ 174' "ref", "blob", "clob", "array") 175 176' Required for com.sun.star.sdbc.XResultSetUpdate 177 textColumn = "_TEXT" 178 179' Required for com.sun.star.awt.XTabControllerModel 180 XTabControlModel1 = oShape1.getControl() 181 XTabControlModel2 = oShape2.getControl() 182 183Exit Sub 184ErrHndl: 185 Test.Exception() 186End Sub 187 188Sub DisposeObj() 189On Error Goto ErrHndl 190'msgbox "Disposing ODatabaseForm" 191 Out.Log("Closing DB connection ...") 192 oConnection.close() 193 194 Out.Log("Revoking 'DBTest' datasource ...") 195 dbtools.RevokeDB("DBTest") 196'msgbox "ODatabaseForm disposed." 197Exit Sub 198ErrHndl: 199 Test.Exception() 200 resume next 201End Sub 202 203Sub C_disposing() 204 Out.Log("!!! Connection disposed !!!") 205' oConnection.close() 206End Sub 207</script:module> 208