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=
"Root_" script:
language=
"StarBasic">REM =======================================================================================================================
4 REM === The Access2Base library is a part of the LibreOffice project. ===
5 REM === Full documentation is available on http://www.access2base.com ===
6 REM =======================================================================================================================
13 REM -----------------------------------------------------------------------------------------------------------------------
14 REM --- FOR INTERNAL USE ONLY ---
15 REM -----------------------------------------------------------------------------------------------------------------------
17 REM -----------------------------------------------------------------------------------------------------------------------
18 REM --- CLASS ROOT FIELDS ---
19 REM -----------------------------------------------------------------------------------------------------------------------
21 Private ErrorHandler As Boolean
22 Private MinimalTraceLevel As Integer
23 Private TraceLogs() As Variant
24 Private TraceLogCount As Integer
25 Private TraceLogLast As Integer
26 Private TraceLogMaxEntries As Integer
27 Private CalledSub As String
28 Private Introspection As Object
' com.sun.star.beans.Introspection
29 Private VersionNumber As String
' Actual Access2Base version number
30 Private Locale As String
31 Private FindRecord As Object
32 Private StatusBar As Object
33 Private Dialogs As Object
' Collection
34 Private TempVars As Object
' Collection
35 Private CurrentDoc() As Variant
' Array of document containers - [
0] = Base document, [
1 ... N] = other documents
37 REM -----------------------------------------------------------------------------------------------------------------------
38 REM --- CONSTRUCTORS / DESTRUCTORS ---
39 REM -----------------------------------------------------------------------------------------------------------------------
40 Private Sub Class_Initialize()
41 Dim vCurrentDoc() As Variant
42 VersionNumber = Access2Base_Version
48 TraceLogMaxEntries =
0
49 CalledSub =
""
50 Locale = L10N._GetLocale()
51 Set Introspection = CreateUnoService(
"com.sun.star.beans.Introspection
")
52 Set FindRecord = Nothing
53 Set StatusBar = Nothing
54 Set Dialogs = New Collection
55 Set TempVars = New Collection
56 vCurrentDoc() = Array()
57 ReDim vCurrentDoc(
0 To
0)
58 Set vCurrentDoc(
0) = Nothing
59 Set CurrentDoc() = vCurrentDoc()
60 End Sub
' Constructor
62 REM -----------------------------------------------------------------------------------------------------------------------
63 Private Sub Class_Terminate()
64 Call Class_Initialize()
65 End Sub
' Destructor
67 REM -----------------------------------------------------------------------------------------------------------------------
69 Call Class_Terminate()
70 End Sub
' Explicit destructor
72 REM -----------------------------------------------------------------------------------------------------------------------
73 REM --- CLASS GET/LET/SET PROPERTIES ---
74 REM -----------------------------------------------------------------------------------------------------------------------
76 REM -----------------------------------------------------------------------------------------------------------------------
77 REM --- CLASS METHODS ---
78 REM -----------------------------------------------------------------------------------------------------------------------
80 REM -----------------------------------------------------------------------------------------------------------------------
81 Public Sub CloseConnection()
82 ' Close all connections established by current document to free memory.
83 ' - if Base document =
> close the one concerned database connection
84 ' - if non-Base documents =
> close the connections of each individual standalone form
86 Dim i As Integer, iCurrentDoc As Integer
87 Dim vDbContainer As Variant, vDbContainers() As Variant, vDocContainer As Variant
89 If ErrorHandler Then On Local Error Goto Error_Sub
91 If Not IsArray(CurrentDoc) Then Goto Exit_Sub
92 If UBound(CurrentDoc)
< 0 Then Goto Exit_Sub
93 iCurrentDoc = CurrentDocIndex( , False)
' False prevents error raising if not found
94 If iCurrentDoc
< 0 Then GoTo Exit_Sub
' If not found ignore
96 vDocContainer = CurrentDocument(iCurrentDoc)
98 If Not .Active Then GoTo Exit_Sub
' e.g. if successive calls to CloseConnection()
99 For i =
0 To UBound(.DbContainers)
100 If Not IsNull(.DbContainers(i).Database) Then
101 .DbContainers(i).Database.Dispose()
102 Set .DbContainers(i).Database = Nothing
104 TraceLog(TRACEANY, UCase(CalledSub)
& " " & .URL
& Iif(i =
0,
"",
" Form=
" & .DbContainers(i).FormName), False)
105 Set .DbContainers(i) = Nothing
107 .DbContainers = Array()
111 Set .Document = Nothing
113 CurrentDoc(iCurrentDoc) = vDocContainer
118 TraceError(TRACEABORT, Err, CalledSub, Erl, False)
' No error message addressed to the user, only stored in console
120 End Sub
' CloseConnection
122 REM -----------------------------------------------------------------------------------------------------------------------
123 Public Function CurrentDb() As Object
124 ' Returns _A2B_.CurrentDocument().Database as an object to allow access to its properties
126 Dim iCurrentDoc As Integer
128 Set CurrentDb = Nothing
130 If Not IsArray(CurrentDoc) Then Goto Exit_Function
131 If UBound(CurrentDoc)
< 0 Then Goto Exit_Function
132 iCurrentDoc = CurrentDocIndex(, False)
' False = no abort
133 If iCurrentDoc
>=
0 Then
134 If UBound(CurrentDoc(iCurrentDoc).DbContainers)
>=
0 Then Set CurrentDb = CurrentDoc(iCurrentDoc).DbContainers(
0).Database
139 End Function
' CurrentDb
141 REM -----------------------------------------------------------------------------------------------------------------------
142 Public Function CurrentDocIndex(Optional pvURL As Variant, Optional pbAbort As Variant) As Integer
143 ' Returns the entry in CurrentDoc(...) referring to the current document
145 Dim i As Integer, bFound As Boolean, sURL As String
146 Const cstBase =
"com.sun.star.comp.dba.ODatabaseDocument
"
151 If Not IsArray(CurrentDoc) Then Goto Trace_Error
152 If UBound(CurrentDoc)
< 0 Then Goto Trace_Error
153 For i =
1 To UBound(CurrentDoc)
' [
0] reserved to database .odb document
154 If IsMissing(pvURL) Then
' Not on
1 single line ?!?
155 If Utils._hasUNOProperty(ThisComponent,
"URL
") Then
156 sURL = ThisComponent.URL
158 Exit For
' f.i. ThisComponent = Basic IDE ...
161 sURL = pvURL
' To support the SelectObject action
163 If CurrentDoc(i).Active And CurrentDoc(i).URL = sURL Then
171 If IsNull(CurrentDoc(
0)) Then GoTo Trace_Error
173 If Not .Active Then GoTo Trace_Error
174 If IsNull(.Document) Then GoTo Trace_Error
182 If IsMissing(pbAbort) Then pbAbort = True
183 If pbAbort Then TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1) Else CurrentDocIndex = -
1
185 End Function
' CurrentDocIndex
187 REM -----------------------------------------------------------------------------------------------------------------------
188 Public Function CurrentDocument(ByVal Optional piDocIndex As Integer) As Variant
189 ' Returns the CurrentDoc(...) referring to the current document or to the argument
191 Dim iDocIndex As Integer
192 If IsMissing(piDocIndex) Then iDocIndex = CurrentDocIndex() Else iDocIndex = piDocIndex
193 If iDocIndex
>=
0 And iDocIndex
<= UBound(CurrentDoc) Then Set CurrentDocument = CurrentDoc(iDocIndex) Else Set CurrentDocument = Nothing
197 REM -----------------------------------------------------------------------------------------------------------------------
199 ' For debugging purposes
200 Dim i As Integer, j As Integer, vCurrentDoc As Variant
201 On Local Error Resume Next
203 DebugPrint
"Version
", VersionNumber
204 DebugPrint
"TraceLevel
", MinimalTraceLevel
205 DebugPrint
"TraceCount
", TraceLogCount
206 DebugPrint
"CalledSub
", CalledSub
207 If IsArray(CurrentDoc) Then
208 For i =
0 To UBound(CurrentDoc)
209 vCurrentDoc = CurrentDoc(i)
210 If Not IsNull(vCurrentDoc) Then
211 DebugPrint i,
"URL
", vCurrentDoc.URL
212 For j =
0 To UBound(vCurrentDoc.DbContainers)
213 DebugPrint i, j,
"Form
", vCurrentDoc.DbContainers(j).FormName
214 DebugPrint i, j,
"Database
", vCurrentDoc.DbContainers(j).Database.Title
222 REM -----------------------------------------------------------------------------------------------------------------------
223 Public Function hasItem(psCollType As String, ByVal psName As String) As Boolean
224 ' Return True if psName if in the collection
227 On Local Error Goto Error_Function
' Whatever ErrorHandler !
230 Select Case psCollType
232 Set oItem = Dialogs.Item(UCase(psName))
234 Set oItem = TempVars.Item(UCase(psName))
241 Error_Function:
' Item by key aborted
244 End Function
' hasItem
246 REM -----------------------------------------------------------------------------------------------------------------------
247 REM --- PRIVATE FUNCTIONS ---
248 REM -----------------------------------------------------------------------------------------------------------------------
250 REM -----------------------------------------------------------------------------------------------------------------------
251 Public Function _CurrentDb(ByVal Optional piDocEntry As Integer, ByVal Optional piDbEntry As Integer) As Variant
252 REM Without arguments same as CurrentDb() except that it generates an error if database not connected (internal use)
253 REM With
2 arguments return the corresponding entry in Root
255 Dim odbDatabase As Variant
256 If IsMissing(piDocEntry) Then
257 Set odbDatabase = CurrentDb()
259 If Not IsArray(CurrentDoc) Then Goto Trace_Error
260 If piDocEntry
< 0 Or piDbEntry
< 0 Then Goto Trace_Error
261 If piDocEntry
> UBound(CurrentDoc) Then Goto Trace_Error
262 If piDbEntry
> UBound(CurrentDoc(piDocEntry).DbContainers) Then Goto Trace_Error
263 Set odbDatabase = CurrentDoc(piDocEntry).DbContainers(piDbEntry).Database
265 If IsNull(odbDatabase) Then GoTo Trace_Error
268 Set _CurrentDb = odbDatabase
271 TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1)
273 End Function
' _CurrentDb