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">
4 REM =======================================================================================================================
5 REM === The Access2Base library is a part of the LibreOffice project. ===
6 REM === Full documentation is available on http://www.access2base.com ===
7 REM =======================================================================================================================
14 REM -----------------------------------------------------------------------------------------------------------------------
15 REM --- FOR INTERNAL USE ONLY ---
16 REM -----------------------------------------------------------------------------------------------------------------------
18 REM -----------------------------------------------------------------------------------------------------------------------
19 REM --- CLASS ROOT FIELDS ---
20 REM -----------------------------------------------------------------------------------------------------------------------
22 Private ErrorHandler As Boolean
23 Private MinimalTraceLevel As Integer
24 Private TraceLogs() As Variant
25 Private TraceLogCount As Integer
26 Private TraceLogLast As Integer
27 Private TraceLogMaxEntries As Integer
28 Private LastErrorCode As Integer
29 Private LastErrorLevel As String
30 Private ErrorText As String
31 Private ErrorLongText As String
32 Private CalledSub As String
33 Private DebugPrintShort As Boolean
34 Private Introspection As Object
' com.sun.star.beans.Introspection
35 Private VersionNumber As String
' Actual Access2Base version number
36 Private Locale As String
37 Private ExcludeA2B As Boolean
38 Private TextSearch As Object
39 Private SearchOptions As Variant
40 Private FindRecord As Object
41 Private StatusBar As Object
42 Private Dialogs As Object
' Collection
43 Private TempVars As Object
' Collection
44 Private CurrentDoc() As Variant
' Array of document containers - [
0] = Base document, [
1 ... N] = other documents
45 Private PythonCache() As Variant
' Array of objects created in Python scripts
47 REM -----------------------------------------------------------------------------------------------------------------------
48 REM --- CONSTRUCTORS / DESTRUCTORS ---
49 REM -----------------------------------------------------------------------------------------------------------------------
50 Private Sub Class_Initialize()
51 VersionNumber = Access2Base_Version
57 TraceLogMaxEntries =
0
59 LastErrorLevel =
""
60 ErrorText =
""
61 ErrorLongText =
""
62 CalledSub =
""
63 DebugPrintShort = True
64 Locale = L10N._GetLocale()
66 Set Introspection = CreateUnoService(
"com.sun.star.beans.Introspection
")
67 Set TextSearch = CreateUnoService(
"com.sun.star.util.TextSearch
")
68 SearchOptions = New com.sun.star.util.SearchOptions
70 .algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
72 .transliterateFlags = com.sun.star.i18n.TransliterationModules.IGNORE_CASE
74 Set FindRecord = Nothing
75 Set StatusBar = Nothing
76 Set Dialogs = New Collection
77 Set TempVars = New Collection
79 ReDim CurrentDoc(
0 To
0)
80 Set CurrentDoc(
0) = Nothing
82 End Sub
' Constructor
84 REM -----------------------------------------------------------------------------------------------------------------------
85 Private Sub Class_Terminate()
86 Call Class_Initialize()
87 End Sub
' Destructor
89 REM -----------------------------------------------------------------------------------------------------------------------
91 Call Class_Terminate()
92 End Sub
' Explicit destructor
94 REM -----------------------------------------------------------------------------------------------------------------------
95 REM --- CLASS GET/LET/SET PROPERTIES ---
96 REM -----------------------------------------------------------------------------------------------------------------------
98 REM -----------------------------------------------------------------------------------------------------------------------
99 REM --- CLASS METHODS ---
100 REM -----------------------------------------------------------------------------------------------------------------------
102 REM -----------------------------------------------------------------------------------------------------------------------
103 Public Function AddPython(ByRef pvObject As Variant) As Long
104 ' Store the object as a new entry in PythonCache and return its entry number
106 Dim lVars As Long, vObject As Variant
108 lVars = UBound(PythonCache) +
1
109 ReDim Preserve PythonCache(
0 To lVars)
110 PythonCache(lVars) = pvObject
114 End Function
' AddPython V6.4
116 REM -----------------------------------------------------------------------------------------------------------------------
117 Public Sub CloseConnection()
118 ' Close all connections established by current document to free memory.
119 ' - if Base document =
> close the one concerned database connection
120 ' - if non-Base documents =
> close the connections of each individual standalone form
122 Dim i As Integer, iCurrentDoc As Integer
123 Dim vDbContainer As Variant, vDbContainers() As Variant, vDocContainer As Variant
125 If ErrorHandler Then On Local Error Goto Error_Sub
127 If Not IsArray(CurrentDoc) Then Goto Exit_Sub
128 If UBound(CurrentDoc)
< 0 Then Goto Exit_Sub
129 iCurrentDoc = CurrentDocIndex( , False)
' False prevents error raising if not found
130 If iCurrentDoc
< 0 Then GoTo Exit_Sub
' If not found ignore
132 vDocContainer = CurrentDocument(iCurrentDoc)
134 If Not .Active Then GoTo Exit_Sub
' e.g. if multiple calls to CloseConnection()
135 For i =
0 To UBound(.DbContainers)
136 If Not IsNull(.DbContainers(i).Database) Then
137 .DbContainers(i).Database.Dispose()
138 Set .DbContainers(i).Database = Nothing
140 TraceLog(TRACEANY, UCase(CalledSub)
& " " & .URL
& Iif(i =
0,
"",
" Form=
" & .DbContainers(i).FormName), False)
141 Set .DbContainers(i) = Nothing
143 .DbContainers = Array()
147 Set .Document = Nothing
149 CurrentDoc(iCurrentDoc) = vDocContainer
154 TraceError(TRACEABORT, Err, CalledSub, Erl, False)
' No error message addressed to the user, only stored in console
156 End Sub
' CloseConnection
158 REM -----------------------------------------------------------------------------------------------------------------------
159 Public Function CurrentDb() As Object
160 ' Returns _A2B_.CurrentDocument().Database as an object to allow access to its properties
162 Dim iCurrentDoc As Integer
164 Set CurrentDb = Nothing
166 If Not IsArray(CurrentDoc) Then Goto Exit_Function
167 If UBound(CurrentDoc)
< 0 Then Goto Exit_Function
168 iCurrentDoc = CurrentDocIndex(, False)
' False = no abort
169 If iCurrentDoc
>=
0 Then
170 If UBound(CurrentDoc(iCurrentDoc).DbContainers)
>=
0 Then Set CurrentDb = CurrentDoc(iCurrentDoc).DbContainers(
0).Database
175 End Function
' CurrentDb
177 REM -----------------------------------------------------------------------------------------------------------------------
178 Public Function CurrentDocIndex(Optional pvURL As Variant, Optional pbAbort As Variant) As Integer
179 ' Returns the entry in CurrentDoc(...) referring to the current document
181 Dim i As Integer, bFound As Boolean, sURL As String
182 Const cstBase =
"com.sun.star.comp.dba.ODatabaseDocument
"
187 If Not IsArray(CurrentDoc) Then Goto Trace_Error
188 If UBound(CurrentDoc)
< 0 Then Goto Trace_Error
189 For i =
1 To UBound(CurrentDoc)
' [
0] reserved to database .odb document
190 If IsMissing(pvURL) Then
' Not on
1 single line ?!?
191 If Utils._hasUNOProperty(ThisComponent,
"URL
") Then
192 sURL = ThisComponent.URL
194 Exit For
' f.i. ThisComponent = Basic IDE ...
197 sURL = pvURL
' To support the SelectObject action
199 If CurrentDoc(i).Active And CurrentDoc(i).URL = sURL Then
207 If IsNull(CurrentDoc(
0)) Then GoTo Trace_Error
209 If Not .Active Then GoTo Trace_Error
210 If IsNull(.Document) Then GoTo Trace_Error
218 If IsMissing(pbAbort) Then pbAbort = True
219 If pbAbort Then TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1) Else CurrentDocIndex = -
1
221 End Function
' CurrentDocIndex
223 REM -----------------------------------------------------------------------------------------------------------------------
224 Public Function CurrentDocument(ByVal Optional piDocIndex As Integer) As Variant
225 ' Returns the CurrentDoc(...) referring to the current document or to the argument
227 Dim iDocIndex As Integer
228 If IsMissing(piDocIndex) Then iDocIndex = CurrentDocIndex(, False) Else iDocIndex = piDocIndex
229 If iDocIndex
>=
0 And iDocIndex
<= UBound(CurrentDoc) Then Set CurrentDocument = CurrentDoc(iDocIndex) Else Set CurrentDocument = Nothing
233 REM -----------------------------------------------------------------------------------------------------------------------
235 ' For debugging purposes
236 Dim i As Integer, j As Integer, vCurrentDoc As Variant
237 On Local Error Resume Next
239 DebugPrint
"Version
", VersionNumber
240 DebugPrint
"TraceLevel
", MinimalTraceLevel
241 DebugPrint
"TraceCount
", TraceLogCount
242 DebugPrint
"CalledSub
", CalledSub
243 If IsArray(CurrentDoc) Then
244 For i =
0 To UBound(CurrentDoc)
245 vCurrentDoc = CurrentDoc(i)
246 If Not IsNull(vCurrentDoc) Then
247 DebugPrint i,
"URL
", vCurrentDoc.URL
248 For j =
0 To UBound(vCurrentDoc.DbContainers)
249 DebugPrint i, j,
"Form
", vCurrentDoc.DbContainers(j).FormName
250 DebugPrint i, j,
"Database
", vCurrentDoc.DbContainers(j).Database.Title
258 REM -----------------------------------------------------------------------------------------------------------------------
259 Public Function hasItem(psCollType As String, ByVal psName As String) As Boolean
260 ' Return True if psName if in the collection
263 On Local Error Goto Error_Function
' Whatever ErrorHandler !
266 Select Case psCollType
268 Set oItem = Dialogs.Item(UCase(psName))
270 Set oItem = TempVars.Item(UCase(psName))
277 Error_Function:
' Item by key aborted
280 End Function
' hasItem
282 REM -----------------------------------------------------------------------------------------------------------------------
283 REM --- PRIVATE FUNCTIONS ---
284 REM -----------------------------------------------------------------------------------------------------------------------
286 REM -----------------------------------------------------------------------------------------------------------------------
287 Public Function _CurrentDb(ByVal Optional piDocEntry As Integer, ByVal Optional piDbEntry As Integer) As Variant
288 REM Without arguments same as CurrentDb() except that it generates an error if database not connected (internal use)
289 REM With
2 arguments return the corresponding entry in Root
291 Dim odbDatabase As Variant
292 If IsMissing(piDocEntry) Then
293 Set odbDatabase = CurrentDb()
295 If Not IsArray(CurrentDoc) Then Goto Trace_Error
296 If piDocEntry
< 0 Or piDbEntry
< 0 Then Goto Trace_Error
297 If piDocEntry
> UBound(CurrentDoc) Then Goto Trace_Error
298 If piDbEntry
> UBound(CurrentDoc(piDocEntry).DbContainers) Then Goto Trace_Error
299 Set odbDatabase = CurrentDoc(piDocEntry).DbContainers(piDbEntry).Database
301 If IsNull(odbDatabase) Then GoTo Trace_Error
304 Set _CurrentDb = odbDatabase
307 TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1)
309 End Function
' _CurrentDb