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