tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / wizards / source / access2base / Database.xba
blob347eafeb499dfcd99b8fc506f9135e825cf230a8
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="Database" 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 =======================================================================================================================
9 Option Compatible
10 Option ClassModule
12 Option Explicit
14 REM -----------------------------------------------------------------------------------------------------------------------
15 REM --- CLASS ROOT FIELDS ---
16 REM -----------------------------------------------------------------------------------------------------------------------
18 Private _Type As String &apos; Must be DATABASE
19 Private _This As Object &apos; Workaround for absence of This builtin function
20 Private _Parent As Object
21 Private _DbConnect As Integer &apos; DBCONNECTxxx constants
22 Private Title As String
23 Private Document As Object &apos; com.sun.star.comp.dba.ODatabaseDocument or SwXTextDocument or ScModelObj
24 Private Connection As Object &apos; com.sun.star.sdbc.drivers.OConnectionWrapper or com.sun.star.sdbc.XConnection
25 Private URL As String
26 Private Location As String &apos; Different from URL for registered databases
27 Private _ReadOnly As Boolean
28 Private MetaData As Object &apos; interface XDatabaseMetaData
29 Private _RDBMS As Integer &apos; DBMS constants
30 Private _ColumnTypes() As Variant &apos; Part of Metadata.GetTypeInfo()
31 Private _ColumnTypeNames() As Variant
32 Private _ColumnPrecisions() As Variant
33 Private _ColumnTypesReference() As Variant
34 Private _ColumnTypesAlias() As Variant &apos; To what should a field whose origin is another DBMS be converted ? See DataTypes By RDBMS.ods
35 Private _BinaryStream As Boolean &apos; False = binary fields must NOT be streamed f.i. via ReadAllBytes or WriteAllBytes
36 Private Form As Object &apos; com.sun.star.form.XForm
37 Private FormName As String
38 Private RecordsetMax As Long &apos; To make unique names in Collection below (See bug # 121342)
39 Private RecordsetsColl As Object &apos; Collection of active recordsets
41 REM -----------------------------------------------------------------------------------------------------------------------
42 REM --- CONSTRUCTORS / DESTRUCTORS ---
43 REM -----------------------------------------------------------------------------------------------------------------------
44 Private Sub Class_Initialize()
45 _Type = OBJDATABASE
46 Set _This = Nothing
47 Set _Parent = Nothing
48 _DbConnect = 0
49 Title = &quot;&quot;
50 Set Document = Nothing
51 Set Connection = Nothing
52 URL = &quot;&quot;
53 _ReadOnly = False
54 Set MetaData = Nothing
55 _RDBMS = DBMS_UNKNOWN
56 _ColumnTypes = Array()
57 _ColumnTypeNames = Array()
58 _ColumnPrecisions = Array()
59 _ColumnTypesReference = Array()
60 _ColumnTypesAlias() = Array()
61 _BinaryStream = False
62 Set Form = Nothing
63 FormName = &quot;&quot;
64 RecordsetMax = 0
65 Set RecordsetsColl = New Collection
66 End Sub &apos; Constructor
68 REM -----------------------------------------------------------------------------------------------------------------------
69 Private Sub Class_Terminate()
70 On Local Error Resume Next
71 Call CloseAllRecordsets()
72 If _DbConnect &lt;&gt; DBCONNECTANY Then
73 If Not IsNull(Connection) Then
74 Connection.close()
75 Connection.dispose()
76 Set Connection = Nothing
77 End If
78 Else
79 mClose()
80 End If
81 Call Class_Initialize()
82 End Sub &apos; Destructor
84 REM -----------------------------------------------------------------------------------------------------------------------
85 Public Sub Dispose()
86 Call Class_Terminate()
87 End Sub &apos; Explicit destructor
91 REM -----------------------------------------------------------------------------------------------------------------------
92 REM --- CLASS GET/LET/SET PROPERTIES ---
93 REM -----------------------------------------------------------------------------------------------------------------------
95 Property Get Connect() As String
96 Connect = _PropertyGet(&quot;Connect&quot;)
97 End Property &apos; Connect (get)
99 REM -----------------------------------------------------------------------------------------------------------------------
100 Property Get Name() As String
101 Name = _PropertyGet(&quot;Name&quot;)
102 End Property &apos; Name (get)
104 REM -----------------------------------------------------------------------------------------------------------------------
105 Property Get ObjectType() As String
106 ObjectType = _PropertyGet(&quot;ObjectType&quot;)
107 End Property &apos; ObjectType (get)
109 REM -----------------------------------------------------------------------------------------------------------------------
110 Property Get OnCreate() As String
111 OnCreate = _PropertyGet(&quot;OnCreate&quot;)
112 End Property &apos; OnCreate (get)
114 REM -----------------------------------------------------------------------------------------------------------------------
115 Property Get OnFocus() As String
116 OnFocus = _PropertyGet(&quot;OnFocus&quot;)
117 End Property &apos; OnFocus (get)
119 REM -----------------------------------------------------------------------------------------------------------------------
120 Property Get OnLoad() As String
121 OnLoad = _PropertyGet(&quot;OnLoad&quot;)
122 End Property &apos; OnLoad (get)
124 REM -----------------------------------------------------------------------------------------------------------------------
125 Property Get OnLoadFinished() As String
126 OnLoadFinished = _PropertyGet(&quot;OnLoadFinished&quot;)
127 End Property &apos; OnLoadFinished (get)
129 REM -----------------------------------------------------------------------------------------------------------------------
130 Property Get OnModifyChanged() As String
131 OnModifyChanged = _PropertyGet(&quot;OnModifyChanged&quot;)
132 End Property &apos; OnModifyChanged (get)
134 REM -----------------------------------------------------------------------------------------------------------------------
135 Property Get OnNew() As String
136 OnNew = _PropertyGet(&quot;OnNew&quot;)
137 End Property &apos; OnNew (get)
139 REM -----------------------------------------------------------------------------------------------------------------------
140 Property Get OnPrepareUnload() As String
141 OnPrepareUnload = _PropertyGet(&quot;OnPrepareUnload&quot;)
142 End Property &apos; OnPrepareUnload (get)
144 REM -----------------------------------------------------------------------------------------------------------------------
145 Property Get OnPrepareViewClosing() As String
146 OnPrepareViewClosing = _PropertyGet(&quot;OnPrepareViewClosing&quot;)
147 End Property &apos; OnPrepareViewClosing (get)
149 REM -----------------------------------------------------------------------------------------------------------------------
150 Property Get OnSave() As String
151 OnSave = _PropertyGet(&quot;OnSave&quot;)
152 End Property &apos; OnSave (get)
154 REM -----------------------------------------------------------------------------------------------------------------------
155 Property Get OnSaveAs() As String
156 OnSaveAs = _PropertyGet(&quot;OnSaveAs&quot;)
157 End Property &apos; OnSaveAs (get)
159 REM -----------------------------------------------------------------------------------------------------------------------
160 Property Get OnSaveAsDone() As String
161 OnSaveAsDone = _PropertyGet(&quot;OnSaveAsDone&quot;)
162 End Property &apos; OnSaveAsDone (get)
164 REM -----------------------------------------------------------------------------------------------------------------------
165 Property Get OnSaveAsFailed() As String
166 OnSaveAsFailed = _PropertyGet(&quot;OnSaveAsFailed&quot;)
167 End Property &apos; OnSaveAsFailed (get)
169 REM -----------------------------------------------------------------------------------------------------------------------
170 Property Get OnSaveDone() As String
171 OnSaveDone = _PropertyGet(&quot;OnSaveDone&quot;)
172 End Property &apos; OnSaveDone (get)
174 REM -----------------------------------------------------------------------------------------------------------------------
175 Property Get OnSaveFailed() As String
176 OnSaveFailed = _PropertyGet(&quot;OnSaveFailed&quot;)
177 End Property &apos; OnSaveFailed (get)
179 REM -----------------------------------------------------------------------------------------------------------------------
180 Property Get OnSubComponentClosed() As String
181 OnSubComponentClosed = _PropertyGet(&quot;OnSubComponentClosed&quot;)
182 End Property &apos; OnSubComponentClosed (get)
184 REM -----------------------------------------------------------------------------------------------------------------------
185 Property Get OnSubComponentOpened() As String
186 OnSubComponentOpened = _PropertyGet(&quot;OnSubComponentOpened&quot;)
187 End Property &apos; OnSubComponentOpened (get)
189 REM -----------------------------------------------------------------------------------------------------------------------
190 Property Get OnTitleChanged() As String
191 OnTitleChanged = _PropertyGet(&quot;OnTitleChanged&quot;)
192 End Property &apos; OnTitleChanged (get)
194 REM -----------------------------------------------------------------------------------------------------------------------
195 Property Get OnUnfocus() As String
196 OnUnfocus = _PropertyGet(&quot;OnUnfocus&quot;)
197 End Property &apos; OnUnfocus (get)
199 REM -----------------------------------------------------------------------------------------------------------------------
200 Property Get OnUnload() As String
201 OnUnload = _PropertyGet(&quot;OnUnload&quot;)
202 End Property &apos; OnUnload (get)
204 REM -----------------------------------------------------------------------------------------------------------------------
205 Property Get OnViewClosed() As String
206 OnViewClosed = _PropertyGet(&quot;OnViewClosed&quot;)
207 End Property &apos; OnViewClosed (get)
209 REM -----------------------------------------------------------------------------------------------------------------------
210 Property Get OnViewCreated() As String
211 OnViewCreated = _PropertyGet(&quot;OnViewCreated&quot;)
212 End Property &apos; OnViewCreated (get)
214 REM -----------------------------------------------------------------------------------------------------------------------
215 Property Get Version() As String
216 Version = _PropertyGet(&quot;Version&quot;)
217 End Property &apos; Version (get)
219 REM -----------------------------------------------------------------------------------------------------------------------
220 REM --- CLASS METHODS ---
221 REM -----------------------------------------------------------------------------------------------------------------------
223 REM -----------------------------------------------------------------------------------------------------------------------
224 Public Function mClose() As Variant
225 &apos; Close the database
227 If _ErrorHandler() Then On Local Error Goto Error_Function
228 Const cstThisSub = &quot;Database.Close&quot;
229 Utils._SetCalledSub(cstThisSub)
230 mClose = False
231 If _DbConnect &lt;&gt; DBCONNECTANY Then Goto Error_NotApplicable
233 With Connection
234 If Utils._hasUNOMethod(Connection, &quot;flush&quot;) Then .flush
235 .close()
236 .dispose()
237 End With
238 Set Connection = Nothing
239 mClose = True
241 Exit_Function:
242 Utils._ResetCalledSub(cstThisSub)
243 Exit Function
244 Error_NotApplicable:
245 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(), 0, 1, cstThisSub)
246 Goto Exit_Function
247 Error_Function:
248 TraceError(TRACEABORT, Err, Utils._CalledSub(), Erl)
249 GoTo Exit_Function
250 End Function &apos; (m)Close
252 REM -----------------------------------------------------------------------------------------------------------------------
253 Public Sub CloseAllRecordsets()
254 &apos; Clean all recordsets for housekeeping
256 Dim sRecordsets() As String, i As Integer, oRecordset As Object
257 On Local Error Goto Exit_Sub
259 If IsNull(RecordsetsColl) Then Exit Sub
260 If RecordsetsColl.Count &lt; 1 Then Exit Sub
261 For i = 1 To RecordsetsColl.Count
262 Set oRecordset = RecordsetsColl.Item(i)
263 oRecordset.mClose(False) &apos; Do not remove entry in collection
264 Next i
265 Set RecordsetsColl = New Collection
266 RecordsetMax = 0
268 Exit_Sub:
269 Exit Sub
270 End Sub &apos; CloseAllRecordsets V0.9.5
272 REM -----------------------------------------------------------------------------------------------------------------------
273 Public Function CreateQueryDef(ByVal Optional pvQueryName As Variant _
274 , ByVal Optional pvSql As Variant _
275 , ByVal Optional pvOption As Variant _
276 ) As Object
277 &apos;Return a (new) QueryDef object based on SQL statement
278 Const cstThisSub = &quot;Database.CreateQueryDef&quot;
279 Utils._SetCalledSub(cstThisSub)
281 Const cstNull = -1
282 Dim oQuery As Object, oQueries As Object, i As Integer, sQueryName As String
284 If _ErrorHandler() Then On Local Error Goto Error_Function
286 Set CreateQueryDef = Nothing
287 If _DbConnect &lt;&gt; DBCONNECTBASE Then Goto Error_NotApplicable
288 If IsMissing(pvQueryName) Then Call _TraceArguments()
289 If IsMissing(pvSql) Then Call _TraceArguments()
290 If IsMissing(pvOption) Then pvOption = cstNull
292 If Not Utils._CheckArgument(pvQueryName, 1, vbString) Then Goto Exit_Function
293 If pvQueryName = &quot;&quot; Then Call _TraceArguments()
294 If Not Utils._CheckArgument(pvSql, 2, vbString) Then Goto Exit_Function
295 If pvSql = &quot;&quot; Then Call _TraceArguments()
296 If Not Utils._CheckArgument(pvOption, 3, Utils._AddNumeric(), Array(cstNull, dbSQLPassThrough)) Then Goto Exit_Function
298 If _ReadOnly Then Goto Error_NoUpdate
300 Set oQuery = CreateUnoService(&quot;com.sun.star.sdb.QueryDefinition&quot;)
301 oQuery.rename(pvQueryName)
302 oQuery.Command = _ReplaceSquareBrackets(pvSql)
303 oQuery.EscapeProcessing = Not ( pvOption = dbSQLPassThrough )
305 Set oQueries = Document.DataSource.getQueryDefinitions()
306 With oQueries
307 For i = 0 To .getCount() - 1
308 sQueryName = .getByIndex(i).Name
309 If UCase(sQueryName) = UCase(pvQueryName) Then
310 TraceError(TRACEWARNING, ERRQUERYDEFDELETED, Utils._CalledSub(), 0, False, sQueryName)
311 .removeByName(sQueryName)
312 Exit For
313 End If
314 Next i
315 .insertByName(pvQueryName, oQuery)
316 End With
317 Set CreateQueryDef = QueryDefs(pvQueryName)
319 Exit_Function:
320 Utils._ResetCalledSub(cstThisSub)
321 Exit Function
322 Error_NotApplicable:
323 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(), 0, 1, cstThisSub)
324 Goto Exit_Function
325 Error_NoUpdate:
326 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(), 0)
327 Goto Exit_Function
328 Error_Function:
329 TraceError(TRACEABORT, Err, cstThisSub, Erl)
330 GoTo Exit_Function
331 End Function &apos; CreateQueryDef V1.1.0
333 REM -----------------------------------------------------------------------------------------------------------------------
334 Public Function CreateTableDef(ByVal Optional pvTableName As Variant) As Object
335 &apos;Return a (new/empty) TableDef object
336 Const cstThisSub = &quot;Database.CreateTableDef&quot;
337 Utils._SetCalledSub(cstThisSub)
339 Dim oTable As Object, oTables As Object, sTables() As String
340 Dim i As Integer, sTableName As String, oNewTable As Object
341 Dim vNameComponents() As Variant, iNames As Integer
343 If _ErrorHandler() Then On Local Error Goto Error_Function
345 Set CreateTableDef = Nothing
346 If _DbConnect &lt;&gt; DBCONNECTBASE Then Goto Error_NotApplicable
347 If IsMissing(pvTableName) Then Call _TraceArguments()
349 If Not Utils._CheckArgument(pvTableName, 1, vbString) Then Goto Exit_Function
350 If pvTableName = &quot;&quot; Then Call _TraceArguments()
352 If _ReadOnly Then Goto Error_NoUpdate
354 Set oTables = Connection.getTables
355 With oTables
356 sTables = .ElementNames()
357 &apos; Check existence of object and find its exact (case-sensitive) name
358 For i = 0 To UBound(sTables)
359 If UCase(pvTableName) = UCase(sTables(i)) Then
360 sTableName = sTables(i)
361 TraceError(TRACEWARNING, ERRTABLEDEFDELETED, Utils._CalledSub(), 0, False, sTableName)
362 .dropByName(sTableName)
363 Exit For
364 End If
365 Next i
366 Set oNewTable = New DataDef
367 Set oNewTable._This = oNewTable
368 oNewTable._Type = OBJTABLEDEF
369 oNewTable._Name = pvTableName
370 vNameComponents = Split(pvTableName, &quot;.&quot;)
371 iNames = UBound(vNameComponents)
372 If iNames &gt;= 2 Then oNewtable.CatalogName = vNameComponents(iNames - 2) Else oNewTable.CatalogName = &quot;&quot;
373 If iNames &gt;= 1 Then oNewtable.SchemaName = vNameComponents(iNames - 1) Else oNewTable.SchemaName = &quot;&quot;
374 oNewtable.TableName = vNameComponents(iNames)
375 Set oNewTable._ParentDatabase = _This
376 Set oNewTable.TableDescriptor = .createDataDescriptor()
377 oNewTable.TableDescriptor.CatalogName = oNewTable.CatalogName
378 oNewTable.TableDescriptor.SchemaName = oNewTable.SchemaName
379 oNewTable.TableDescriptor.Name = oNewTable.TableName
380 oNewTable.TableDescriptor.Type = &quot;TABLE&quot;
381 End With
383 Set CreateTabledef = oNewTable
385 Exit_Function:
386 Utils._ResetCalledSub(cstThisSub)
387 Exit Function
388 Error_NotApplicable:
389 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(), 0, 1, cstThisSub)
390 Goto Exit_Function
391 Error_NoUpdate:
392 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(), 0)
393 Goto Exit_Function
394 Error_Function:
395 TraceError(TRACEABORT, Err, cstThisSub, Erl)
396 GoTo Exit_Function
397 End Function &apos; CreateTableDef V1.1.0
399 REM -----------------------------------------------------------------------------------------------------------------------
400 Public Function DAvg( _
401 ByVal Optional psExpr As String _
402 , ByVal Optional psDomain As String _
403 , ByVal Optional pvCriteria As Variant _
404 ) As Variant
405 &apos; Return average of scope
406 Const cstThisSub = &quot;Database.DAvg&quot;
407 Utils._SetCalledSub(cstThisSub)
408 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
409 DAvg = _DFunction(&quot;AVG&quot;, psExpr, psDomain, Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria), &quot;&quot;)
410 Utils._ResetCalledSub(cstThisSub)
411 End Function &apos; DAvg
413 REM -----------------------------------------------------------------------------------------------------------------------
414 Public Function DCount( _
415 ByVal Optional psExpr As String _
416 , ByVal Optional psDomain As String _
417 , ByVal Optional pvCriteria As Variant _
418 ) As Variant
419 &apos; Return # of occurrences of scope
420 Const cstThisSub = &quot;Database.DCount&quot;
421 Utils._SetCalledSub(cstThisSub)
422 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
423 DCount = _DFunction(&quot;COUNT&quot;, psExpr, psDomain, Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria), &quot;&quot;)
424 Utils._ResetCalledSub(cstThisSub)
425 End Function &apos; DCount
427 REM -----------------------------------------------------------------------------------------------------------------------
428 Public Function DLookup( _
429 ByVal Optional psExpr As String _
430 , ByVal Optional psDomain As String _
431 , ByVal Optional pvCriteria As Variant _
432 , ByVal Optional pvOrderClause As Variant _
433 ) As Variant
435 &apos; Return a value within a table
436 &apos;Arguments: psExpr: an SQL expression
437 &apos; psDomain: a table- or queryname
438 &apos; pvCriteria: an optional WHERE clause
439 &apos; pcOrderClause: an optional order clause incl. &quot;DESC&quot; if relevant
440 &apos;Return: Value of the psExpr if found, else Null.
441 &apos;Author: inspired from Allen Browne. http://allenbrowne.com/ser-42.html
442 &apos;Examples:
443 &apos; 1. To find the last value, include DESC in the OrderClause, e.g.:
444 &apos; DLookup(&quot;[Surname] &amp; [FirstName]&quot;, &quot;tblClient&quot;, , &quot;ClientID DESC&quot;)
445 &apos; 2. To find the lowest non-null value of a field, use the Criteria, e.g.:
446 &apos; DLookup(&quot;ClientID&quot;, &quot;tblClient&quot;, &quot;Surname Is Not Null&quot; , &quot;Surname&quot;)
448 Const cstThisSub = &quot;Database.DLookup&quot;
449 Utils._SetCalledSub(cstThisSub)
450 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
451 DLookup = _DFunction(&quot;&quot;, psExpr, psDomain _
452 , Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria) _
453 , Iif(IsMissing(pvOrderClause), &quot;&quot;, pvOrderClause) _
455 Utils._ResetCalledSub(cstThisSub)
456 End Function &apos; DLookup
458 REM -----------------------------------------------------------------------------------------------------------------------
459 Public Function DMax( _
460 ByVal Optional psExpr As String _
461 , ByVal Optional psDomain As String _
462 , ByVal Optional pvCriteria As Variant _
463 ) As Variant
464 &apos; Return maximum of scope
465 Const cstThisSub = &quot;Database.DMax&quot;
466 Utils._SetCalledSub(cstThisSub)
467 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
468 DMax = _DFunction(&quot;MAX&quot;, psExpr, psDomain, Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria), &quot;&quot;)
469 Utils._ResetCalledSub(cstThisSub)
470 End Function &apos; DMax
472 REM -----------------------------------------------------------------------------------------------------------------------
473 Public Function DMin( _
474 ByVal Optional psExpr As String _
475 , ByVal Optional psDomain As String _
476 , ByVal Optional pvCriteria As Variant _
477 ) As Variant
478 &apos; Return minimum of scope
479 Const cstThisSub = &quot;Database.DMin&quot;
480 Utils._SetCalledSub(cstThisSub)
481 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
482 DMin = _DFunction(&quot;MIN&quot;, psExpr, psDomain, Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria), &quot;&quot;)
483 Utils._ResetCalledSub(cstThisSub)
484 End Function &apos; DMin
486 REM -----------------------------------------------------------------------------------------------------------------------
487 Public Function DStDev( _
488 ByVal Optional psExpr As String _
489 , ByVal Optional psDomain As String _
490 , ByVal Optional pvCriteria As Variant _
491 ) As Variant
492 &apos; Return standard deviation of scope
493 Const cstThisSub = &quot;Database.DStDev&quot;
494 Utils._SetCalledSub(cstThisSub)
495 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
496 DStDev = _DFunction(&quot;STDDEV_SAMP&quot;, psExpr, psDomain, Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria), &quot;&quot;) &apos; STDDEV not STDEV !
497 Utils._ResetCalledSub(cstThisSub)
498 End Function &apos; DStDev
500 REM -----------------------------------------------------------------------------------------------------------------------
501 Public Function DStDevP( _
502 ByVal Optional psExpr As String _
503 , ByVal Optional psDomain As String _
504 , ByVal Optional pvCriteria As Variant _
505 ) As Variant
506 &apos; Return standard deviation of scope
507 Const cstThisSub = &quot;Database.DStDevP&quot;
508 Utils._SetCalledSub(cstThisSub)
509 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
510 DStDevP = _DFunction(&quot;STDDEV_POP&quot;, psExpr, psDomain, Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria), &quot;&quot;) &apos; STDDEV not STDEV !
511 Utils._ResetCalledSub(cstThisSub)
512 End Function &apos; DStDevP
514 REM -----------------------------------------------------------------------------------------------------------------------
515 Public Function DSum( _
516 ByVal Optional psExpr As String _
517 , ByVal Optional psDomain As String _
518 , ByVal Optional pvCriteria As Variant _
519 ) As Variant
520 &apos; Return sum of scope
521 Const cstThisSub = &quot;Database.DSum&quot;
522 Utils._SetCalledSub(cstThisSub)
523 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
524 DSum = _DFunction(&quot;SUM&quot;, psExpr, psDomain, Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria), &quot;&quot;)
525 Utils._ResetCalledSub(cstThisSub)
526 End Function &apos; DSum
528 REM -----------------------------------------------------------------------------------------------------------------------
529 Public Function DVar( _
530 ByVal Optional psExpr As String _
531 , ByVal Optional psDomain As String _
532 , ByVal Optional pvCriteria As Variant _
533 ) As Variant
534 &apos; Return variance of scope
535 Const cstThisSub = &quot;Database.DVar&quot;
536 Utils._SetCalledSub(cstThisSub)
537 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
538 DVar = _DFunction(&quot;VAR_SAMP&quot;, psExpr, psDomain, Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria), &quot;&quot;)
539 Utils._ResetCalledSub(cstThisSub)
540 End Function &apos; DVar
542 REM -----------------------------------------------------------------------------------------------------------------------
543 Public Function DVarP( _
544 ByVal Optional psExpr As String _
545 , ByVal Optional psDomain As String _
546 , ByVal Optional pvCriteria As Variant _
547 ) As Variant
548 &apos; Return variance of scope
549 Const cstThisSub = &quot;Database.DVarP&quot;
550 Utils._SetCalledSub(cstThisSub)
551 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
552 DVarP = _DFunction(&quot;VAR_POP&quot;, psExpr, psDomain, Iif(IsMissing(pvCriteria), &quot;&quot;, pvCriteria), &quot;&quot;)
553 Utils._ResetCalledSub(cstThisSub)
554 End Function &apos; DVarP
556 REM -----------------------------------------------------------------------------------------------------------------------
557 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
558 &apos; Return property value of psProperty property name
560 Utils._SetCalledSub(&quot;Database.getProperty&quot;)
561 If IsMissing(pvProperty) Then Call _TraceArguments()
562 getProperty = _PropertyGet(pvProperty)
563 Utils._ResetCalledSub(&quot;Database.getProperty&quot;)
565 End Function &apos; getProperty
567 REM -----------------------------------------------------------------------------------------------------------------------
568 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
569 &apos; Return True if object has a valid property called pvProperty (case-insensitive comparison !)
571 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
572 Exit Function
574 End Function &apos; hasProperty
576 REM -----------------------------------------------------------------------------------------------------------------------
577 Public Function OpenRecordset(ByVal Optional pvSource As Variant _
578 , ByVal Optional pvType As Variant _
579 , ByVal Optional pvOptions As Variant _
580 , ByVal Optional pvLockEdit As Variant _
581 ) As Object
582 &apos;Return a Recordset object based on Source (= SQL, table or query name)
584 Const cstThisSub = &quot;Database.OpenRecordset&quot;
585 Utils._SetCalledSub(cstThisSub)
586 Const cstNull = -1
588 Dim lCommandType As Long, sCommand As String, oObject As Object
589 Dim sSource As String, i As Integer, iCount As Integer
590 Dim sObjects() As String, bFound As Boolean, oTables As Object, oQueries As Object
591 Dim iType As Integer, iOptions As Integer, iLockEdit As Integer
593 If _ErrorHandler() Then On Local Error Goto Error_Function
594 Set oObject = Nothing
595 If IsMissing(pvSource) Then Call _TraceArguments()
596 If pvSource = &quot;&quot; Then Call _TraceArguments()
597 If VarType(pvType) = vbError Then
598 iType = cstNull
599 ElseIf IsMissing(pvType) Then
600 iType = cstNull
601 Else
602 If Not Utils._CheckArgument(pvType, 2, Utils._AddNumeric(), Array(cstNull, dbOpenForwardOnly)) Then Goto Exit_Function
603 iType = pvType
604 End If
605 If VarType(pvOptions) = vbError Then
606 iOptions = cstNull
607 ElseIf IsMissing(pvOptions) Then
608 iOptions = cstNull
609 Else
610 If Not Utils._CheckArgument(pvOptions, 3, Utils._AddNumeric(), Array(cstNull, dbSQLPassThrough)) Then Goto Exit_Function
611 iOptions = pvOptions
612 End If
613 If VarType(pvLockEdit) = vbError Then
614 iLockEdit = cstNull
615 ElseIf IsMissing(pvLockEdit) Then
616 iLockEdit = cstNull
617 Else
618 If Not Utils._CheckArgument(pvLockEdit, 4, Utils._AddNumeric(), Array(cstNull, dbReadOnly)) Then Goto Exit_Function
619 iLockEdit = pvLockEdit
620 End If
622 sSource = Split(UCase(Trim(pvSource)), &quot; &quot;)(0)
623 Select Case True
624 Case sSource = &quot;SELECT&quot;
625 lCommandType = com.sun.star.sdb.CommandType.COMMAND
626 sCommand = _ReplaceSquareBrackets(pvSource)
627 Case Else
628 sSource = UCase(Trim(pvSource))
629 REM Explore tables
630 Set oTables = Connection.getTables
631 sObjects = oTables.ElementNames()
632 bFound = False
633 For i = 0 To UBound(sObjects)
634 If sSource = UCase(sObjects(i)) Then
635 sCommand = sObjects(i)
636 bFound = True
637 Exit For
638 End If
639 Next i
640 If bFound Then
641 lCommandType = com.sun.star.sdb.CommandType.TABLE
642 Else
643 REM Explore queries
644 Set oQueries = Connection.getQueries
645 sObjects = oQueries.ElementNames()
646 For i = 0 To UBound(sObjects)
647 If sSource = UCase(sObjects(i)) Then
648 sCommand = sObjects(i)
649 bFound = True
650 Exit For
651 End If
652 Next i
653 If Not bFound Then Goto Trace_NotFound
654 lCommandType = com.sun.star.sdb.CommandType.QUERY
655 End If
656 End Select
658 Set oObject = New Recordset
659 With oObject
660 ._CommandType = lCommandType
661 ._Command = sCommand
662 ._ParentName = Title
663 ._ParentType = _Type
664 ._ForwardOnly = ( iType = dbOpenForwardOnly )
665 ._PassThrough = ( iOptions = dbSQLPassThrough )
666 ._ReadOnly = ( (iLockEdit = dbReadOnly) Or _ReadOnly )
667 Set ._This = oObject
668 Set ._ParentDatabase = _This
669 Call ._Initialize()
670 RecordsetMax = RecordsetMax + 1
671 ._Name = Format(RecordsetMax, &quot;0000000&quot;)
672 RecordsetsColl.Add(oObject, UCase(._Name))
673 End With
675 If Not ( oObject._BOF And oObject._EOF ) Then oObject.MoveFirst() &apos; Do nothing if resultset empty
677 Exit_Function:
678 Set OpenRecordset = oObject
679 Set oObject = Nothing
680 Utils._ResetCalledSub(cstThisSub)
681 Exit Function
682 Error_Function:
683 TraceError(TRACEABORT, Err, cstThisSub, Erl)
684 GoTo Exit_Function
685 Trace_NotFound:
686 TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(), 0, , Array(_GetLabel(&quot;TABLE&quot;) &amp; &quot;/&quot; &amp; _GetLabel(&quot;QUERY&quot;), pvSource))
687 Goto Exit_Function
688 End Function &apos; OpenRecordset V1.1.0
690 REM -----------------------------------------------------------------------------------------------------------------------
691 Public Function OpenSQL(Optional ByVal pvSQL As Variant _
692 , Optional ByVal pvOption As Variant _
693 ) As Boolean
694 &apos; Return True if the execution of the SQL statement was successful
695 &apos; SQL must contain a SELECT query
696 &apos; pvOption can force pass through mode
698 If _ErrorHandler() Then On Local Error Goto Error_Function
700 Const cstThisSub = &quot;Database.OpenSQL&quot;
701 Utils._SetCalledSub(cstThisSub)
703 OpenSQL = False
704 If IsMissing(pvSQL) Then Call _TraceArguments()
705 If Not Utils._CheckArgument(pvSQL, 1, vbString) Then Goto Exit_Function
706 Const cstNull = -1
707 If IsMissing(pvOption) Then
708 pvOption = cstNull
709 Else
710 If Not Utils._CheckArgument(pvOption, 2, Utils._AddNumeric(), Array(dbSQLPassThrough, cstNull)) Then Goto Exit_Function
711 End If
712 If _DbConnect &lt;&gt; DBCONNECTBASE And _DbConnect &lt;&gt; DBCONNECTFORM Then Goto Error_NotApplicable
714 Dim oURL As New com.sun.star.util.URL, oDispatch As Object
715 Dim vArgs(8) as New com.sun.star.beans.PropertyValue
717 oURL.Complete = &quot;.component:DB/DataSourceBrowser&quot;
718 oDispatch = StarDesktop.queryDispatch(oURL, &quot;_Blank&quot;, 8)
720 vArgs(0).Name = &quot;ActiveConnection&quot; : vArgs(0).Value = Connection
721 vArgs(1).Name = &quot;CommandType&quot; : vArgs(1).Value = com.sun.star.sdb.CommandType.COMMAND
722 vArgs(2).Name = &quot;Command&quot; : vArgs(2).Value = _ReplaceSquareBrackets(pvSQL)
723 vArgs(3).Name = &quot;ShowMenu&quot; : vArgs(3).Value = True
724 vArgs(4).Name = &quot;ShowTreeView&quot; : vArgs(4).Value = False
725 vArgs(5).Name = &quot;ShowTreeViewButton&quot; : vArgs(5).Value = False
726 vArgs(6).Name = &quot;Filter&quot; : vArgs(6).Value = &quot;&quot;
727 vArgs(7).Name = &quot;ApplyFilter&quot; : vArgs(7).Value = False
728 vArgs(8).Name = &quot;EscapeProcessing&quot; : vArgs(8).Value = CBool(Not ( pvOption = dbSQLPassThrough ))
730 oDispatch.dispatch(oURL, vArgs)
731 OpenSQL = True
733 Exit_Function:
734 Exit Function
735 Error_Function:
736 TraceError(TRACEABORT, Err, &quot;OpenSQL&quot;, Erl)
737 GoTo Exit_Function
738 SQL_Error:
739 TraceError(TRACEFATAL, ERRSQLSTATEMENT, Utils._CalledSub(), 0, , pvSQL)
740 Goto Exit_Function
741 Error_NotApplicable:
742 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(), 0, 1, cstThisSub)
743 Goto Exit_Function
744 End Function &apos; OpenSQL V1.1.0
746 REM -----------------------------------------------------------------------------------------------------------------------
747 Public Function OutputTo(ByVal pvObjectType As Variant _
748 , ByVal Optional pvObjectName As Variant _
749 , ByVal Optional pvOutputFormat As Variant _
750 , ByVal Optional pvOutputFile As Variant _
751 , ByVal Optional pvAutoStart As Variant _
752 , ByVal Optional pvTemplateFile As Variant _
753 , ByVal Optional pvEncoding As Variant _
754 , ByVal Optional pvQuality As Variant _
755 , ByRef Optional pvHeaders As Variant _
756 , ByRef Optional pvData As Variant _
757 ) As Boolean
758 &apos;Supported: acFormatHTML, acFormatODS, acFormatXLS, acFormatXLSX, acFormatTXT for tables and queries
759 &apos;pvHeaders and pvData (unpublished) when pvObjectType = acOutputArray
761 If _ErrorHandler() Then On Local Error Goto Error_Function
762 Const cstThisSub = &quot;Database.OutputTo&quot;
763 Utils._SetCalledSub(cstThisSub)
765 OutputTo = False
767 If Not Utils._CheckArgument(pvObjectType, 1, Utils._AddNumeric(), Array(acOutputTable, acOutputQuery, acOutputArray)) Then Goto Exit_Function
768 If IsMissing(pvObjectName) Then Call _TraceArguments()
769 If Not Utils._CheckArgument(pvObjectName, 2, vbString) Then Goto Exit_Function
770 If IsMissing(pvOutputFormat) Then pvOutputFormat = &quot;&quot;
771 If Not Utils._CheckArgument(pvOutputFormat, 3, vbString) Then Goto Exit_Function
772 If pvOutputFormat &lt;&gt; &quot;&quot; Then
773 If Not Utils._CheckArgument(UCase(pvOutputFormat), 3, vbString, Array( _
774 UCase(acFormatHTML), &quot;HTML&quot; _
775 , UCase(acFormatODS), &quot;ODS&quot; _
776 , UCase(acFormatXLS), &quot;XLS&quot; _
777 , UCase(acFormatXLSX), &quot;XLSX&quot; _
778 , UCase(acFormatTXT), &quot;TXT&quot;, &quot;CSV&quot; _
779 , &quot;&quot;)) _
780 Then Goto Exit_Function &apos; A 2nd time to allow case unsensitivity
781 End If
782 If IsMissing(pvOutputFile) Then pvOutputFile = &quot;&quot;
783 If Not Utils._CheckArgument(pvOutputFile, 4, vbString) Then Goto Exit_Function
784 If IsMissing(pvAutoStart) Then pvAutoStart = False
785 If Not Utils._CheckArgument(pvAutoStart, 5, vbBoolean) Then Goto Exit_Function
786 If IsMissing(pvTemplateFile) Then pvTemplateFile = &quot;&quot;
787 If Not Utils._CheckArgument(pvTemplateFile, 6, vbString) Then Goto Exit_Function
788 If IsMissing(pvEncoding) Then pvEncoding = 0
789 If Not Utils._CheckArgument(pvEncoding, 7, _AddNumeric()) Then Goto Exit_Function
790 If IsMissing(pvQuality) Then pvQuality = acExportQualityPrint
791 If Not Utils._CheckArgument(pvQuality, 7, _AddNumeric(), Array(acExportQualityPrint, acExportQualityScreen)) Then Goto Exit_Function
792 If pvObjectType = acOutputArray Then
793 If IsMissing(pvHeaders) Or IsMissing(pvData) Then Call _TraceArguments()
794 pvOutputFormat = &quot;HTML&quot;
795 End If
797 Dim sOutputFile As String, oTable As Object
798 Dim sOutputFormat As String, iTemplate As Integer, iOutputFile As Integer, bOutput As Boolean, sSuffix As String
800 If pvObjectType = acOutputArray Then
801 Set oTable = Nothing
802 Else
803 &apos;Find applicable table or query
804 If pvObjectType = acOutputTable Then Set oTable = TableDefs(pvObjectName, True) Else Set oTable = Querydefs(pvObjectName, True)
805 If IsNull(oTable) Then Goto Error_NotFound
806 End If
808 &apos;Determine format and parameters
809 If pvOutputFormat = &quot;&quot; Then
810 sOutputFormat = _PromptFormat(Array(&quot;HTML&quot;, &quot;ODS&quot;, &quot;XLS&quot;, &quot;XLSX&quot;, &quot;TXT&quot;)) &apos; Prompt user for format
811 If sOutputFormat = &quot;&quot; Then Goto Exit_Function
812 Else
813 sOutputFormat = UCase(pvOutputFormat)
814 End If
816 &apos;Determine output file
817 If pvOutputFile = &quot;&quot; Then &apos; Prompt file picker to user
818 Select Case sOutputFormat
819 Case UCase(acFormatHTML), &quot;HTML&quot; : sSuffix = &quot;html&quot;
820 Case UCase(acFormatODS), &quot;ODS&quot; : sSuffix = &quot;ods&quot;
821 Case UCase(acFormatXLS), &quot;XLS&quot; : sSuffix = &quot;xls&quot;
822 Case UCase(acFormatXLSX), &quot;XLSX&quot; : sSuffix = &quot;xlsx&quot;
823 Case UCase(acFormatTXT), &quot;TXT&quot;, &quot;CSV&quot; : sSuffix = &quot;txt&quot;
824 End Select
825 sOutputFile = _PromptFilePicker(sSuffix)
826 If sOutputFile = &quot;&quot; Then Goto Exit_Function
827 Else
828 sOutputFile = pvOutputFile
829 End If
830 sOutputFile = ConvertToURL(sOutputFile)
832 &apos;Create file
833 Select Case sOutputFormat
834 Case UCase(acFormatHTML), &quot;HTML&quot;
835 If pvObjectType = acOutputArray Then
836 bOutput = _OutputToHTML(Nothing, pvObjectName, sOutputFile, pvTemplateFile, pvHeaders, pvData)
837 Else
838 bOutput = _OutputToHTML(oTable, pvObjectName, sOutputFile, pvTemplateFile)
839 End If
840 Case UCase(acFormatODS), &quot;ODS&quot;
841 bOutput = _OutputToCalc(oTable, sOutputFile, acFormatODS)
842 Case UCase(acFormatXLS), &quot;XLS&quot;
843 bOutput = _OutputToCalc(oTable, sOutputFile, acFormatXLS)
844 Case UCase(acFormatXLS), &quot;XLSX&quot;
845 bOutput = _OutputToCalc(oTable, sOutputFile, acFormatXLSX)
846 Case UCase(acFormatTXT), &quot;TXT&quot;, &quot;CSV&quot;
847 bOutput = _OutputToCalc(oTable, sOutputFile, acFormatTXT, pvEncoding)
848 End Select
850 &apos;Launch application, if requested
851 If bOutput Then
852 If pvAutoStart Then Call _ShellExecute(sOutputFile)
853 Else
854 GoTo Error_File
855 End If
857 OutputTo = True
859 Exit_Function:
860 If Not IsNull(oTable) Then
861 oTable.Dispose()
862 Set oTable = Nothing
863 End If
864 Utils._ResetCalledSub(cstThisSub)
865 Exit Function
866 Error_NotFound:
867 TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(), 0, , Array(_GetLabel(&quot;OBJECT&quot;), pvObjectName))
868 Goto Exit_Function
869 Error_Function:
870 TraceError(TRACEABORT, Err, cstThisSub, Erl)
871 GoTo Exit_Function
872 Error_File:
873 TraceError(TRACEFATAL, ERRFILENOTCREATED, Utils._CalledSub(), 0, , sOutputFile)
874 GoTo Exit_Function
875 End Function &apos; OutputTo V1.4.0
877 REM -----------------------------------------------------------------------------------------------------------------------
878 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
879 &apos; Return
880 &apos; a Collection object if pvIndex absent
881 &apos; a Property object otherwise
883 Utils._SetCalledSub(&quot;Database.Properties&quot;)
884 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
885 vPropertiesList = _PropertiesList()
886 sObject = Utils._PCase(_Type)
887 If IsMissing(pvIndex) Then
888 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList)
889 Else
890 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList, pvIndex)
891 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
892 End If
893 Set vProperty._ParentDatabase = _This
895 Exit_Function:
896 Set Properties = vProperty
897 Utils._ResetCalledSub(&quot;Database.Properties&quot;)
898 Exit Function
899 End Function &apos; Properties
901 REM -----------------------------------------------------------------------------------------------------------------------
902 Public Function QueryDefs(ByVal Optional pvIndex As Variant, ByVal Optional pbCheck As Boolean) As Object
903 &apos; Collect all Queries in the database
904 &apos; pbCheck unpublished
906 If _ErrorHandler() Then On Local Error Goto Error_Function
907 Utils._SetCalledSub(&quot;Database.QueryDefs&quot;)
908 If IsMissing(pbCheck) Then pbCheck = False
910 Dim sObjects() As String, sObjectName As String, oObject As Object
911 Dim i As Integer, bFound As Boolean, oQueries As Object
912 Set oObject = Nothing
913 If Not IsMissing(pvIndex) Then
914 If Not Utils._CheckArgument(pvIndex, 1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
915 End If
917 Set oQueries = Connection.getQueries
918 sObjects = oQueries.ElementNames()
919 Select Case True
920 Case IsMissing(pvIndex)
921 Set oObject = New Collect
922 Set oObject._This = oObject
923 oObject._CollType = COLLQUERYDEFS
924 Set oObject._Parent = _This
925 oObject._Count = UBound(sObjects) + 1
926 Goto Exit_Function
927 Case VarType(pvIndex) = vbString
928 bFound = False
929 &apos; Check existence of object and find its exact (case-sensitive) name
930 For i = 0 To UBound(sObjects)
931 If UCase(pvIndex) = UCase(sObjects(i)) Then
932 sObjectName = sObjects(i)
933 bFound = True
934 Exit For
935 End If
936 Next i
937 If Not bFound Then Goto Trace_NotFound
938 Case Else &apos; pvIndex is numeric
939 If pvIndex &lt; 0 Or pvIndex &gt; UBound(sObjects) Then Goto Trace_IndexError
940 sObjectName = sObjects(pvIndex)
941 End Select
943 Set oObject = New DataDef
944 Set oObject._This = oObject
945 oObject._Type = OBJQUERYDEF
946 oObject._Name = sObjectName
947 Set oObject._ParentDatabase = _This
948 oObject._readOnly = _ReadOnly
949 Set oObject.Query = oQueries.getByName(sObjectName)
951 Exit_Function:
952 Set QueryDefs = oObject
953 Set oObject = Nothing
954 Utils._ResetCalledSub(&quot;Database.QueryDefs&quot;)
955 Exit Function
956 Error_Function:
957 TraceError(TRACEABORT, Err, &quot;Database.QueryDefs&quot;, Erl)
958 GoTo Exit_Function
959 Trace_NotFound:
960 If Not pbCheck Then TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(), 0, , Array(_GetLabel(&quot;QUERY&quot;), pvIndex))
961 Goto Exit_Function
962 Trace_IndexError:
963 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(), 0)
964 Goto Exit_Function
965 End Function &apos; QueryDefs V1.1.0
967 REM -----------------------------------------------------------------------------------------------------------------------
968 Public Function Recordsets(ByVal Optional pvIndex As Variant) As Object
969 &apos; Collect all active recordsets
971 If _ErrorHandler() Then On Local Error Goto Error_Function
972 Utils._SetCalledSub(&quot;Database.Recordsets&quot;)
974 Set Recordsets = Nothing
975 If Not IsMissing(pvIndex) Then
976 If Not Utils._CheckArgument(pvIndex, 1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
977 End If
979 Dim sObjects() As String, sObjectName As String, oObject As Object
980 Dim i As Integer, bFound As Boolean, oTables As Object
982 Select Case True
983 Case IsMissing(pvIndex)
984 Set oObject = New Collect
985 Set oObject._This = oObject
986 oObject._CollType = COLLRECORDSETS
987 Set oObject._Parent = _This
988 oObject._Count = RecordsetsColl.Count
989 Case VarType(pvIndex) = vbString
990 bFound = _hasRecordset(pvIndex)
991 If Not bFound Then Goto Trace_NotFound
992 Set oObject = RecordsetsColl.Item(pvIndex)
993 Case Else &apos; pvIndex is numeric
994 If pvIndex &lt; 0 Or pvIndex &gt;= RecordsetsColl.Count Then Goto Trace_IndexError
995 Set oObject = RecordsetsColl.Item(pvIndex + 1) &apos; Collection members are numbered 1 ... Count
996 End Select
998 Exit_Function:
999 Set Recordsets = oObject
1000 Set oObject = Nothing
1001 Utils._ResetCalledSub(&quot;Database.Recordsets&quot;)
1002 Exit Function
1003 Error_Function:
1004 TraceError(TRACEABORT, Err, &quot;Database.Recordsets&quot;, Erl)
1005 GoTo Exit_Function
1006 Trace_NotFound:
1007 TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(), 0, , Array(_GetLabel(&quot;RECORDSET&quot;), pvIndex))
1008 Goto Exit_Function
1009 Trace_IndexError:
1010 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(), 0)
1011 Goto Exit_Function
1012 End Function &apos; Recordsets V0.9.5
1014 REM -----------------------------------------------------------------------------------------------------------------------
1015 Public Function RunSQL(Optional ByVal pvSQL As Variant _
1016 , Optional ByVal pvOption As Variant _
1017 ) As Boolean
1018 &apos; Return True if the execution of the SQL statement was successful
1019 &apos; SQL must contain an ACTION query
1021 If _ErrorHandler() Then On Local Error Goto Error_Function
1023 Const cstThisSub = &quot;Database.RunSQL&quot;
1024 Utils._SetCalledSub(cstThisSub)
1026 RunSQL = False
1027 If IsMissing(pvSQL) Then Call _TraceArguments()
1028 If Not Utils._CheckArgument(pvSQL, 1, vbString) Then Goto Exit_Function
1029 Const cstNull = -1
1030 If IsMissing(pvOption) Then
1031 pvOption = cstNull
1032 Else
1033 If Not Utils._CheckArgument(pvOption, 2, Utils._AddNumeric(), Array(cstNull, dbSQLPassThrough)) Then Goto Exit_Function
1034 End If
1036 Dim oStatement As Object, vResult As Variant
1037 Set oStatement = Connection.createStatement()
1038 oStatement.EscapeProcessing = Not ( pvOption = dbSQLPassThrough )
1039 On Local Error Goto SQL_Error
1040 vResult = oStatement.execute(_ReplaceSquareBrackets(pvSQL))
1041 On Local Error Goto Error_Function
1042 RunSQL = True
1044 Exit_Function:
1045 Utils._ResetCalledSub(cstThisSub)
1046 Exit Function
1047 Error_Function:
1048 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1049 GoTo Exit_Function
1050 SQL_Error:
1051 TraceError(TRACEFATAL, ERRSQLSTATEMENT, Utils._CalledSub(), 0, , pvSQL)
1052 Goto Exit_Function
1053 End Function &apos; RunSQL V1.1.0
1055 REM -----------------------------------------------------------------------------------------------------------------------
1056 Public Function TableDefs(ByVal Optional pvIndex As Variant, ByVal Optional pbCheck As Boolean) As Object
1057 &apos; Collect all tables in the database
1058 &apos; pbCheck unpublished
1060 Const cstThisSub = &quot;Database.TableDefs&quot;
1061 If _ErrorHandler() Then On Local Error Goto Error_Function
1062 Utils._SetCalledSub(cstThisSub)
1063 If IsMissing(pbCheck) Then pbCheck = False
1065 Dim sObjects() As String, sObjectName As String, oObject As Object
1066 Dim i As Integer, bFound As Boolean, oTables As Object
1067 Set oObject = Nothing
1068 If Not IsMissing(pvIndex) Then
1069 If Not Utils._CheckArgument(pvIndex, 1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
1070 End If
1072 Set oTables = Connection.getTables
1073 sObjects = oTables.ElementNames()
1074 Select Case True
1075 Case IsMissing(pvIndex)
1076 Set oObject = New Collect
1077 Set oObject._This = oObject
1078 oObject._CollType = COLLTABLEDEFS
1079 Set oObject._Parent = _This
1080 oObject._Count = UBound(sObjects) + 1
1081 Goto Exit_Function
1082 Case VarType(pvIndex) = vbString
1083 bFound = False
1084 &apos; Check existence of object and find its exact (case-sensitive) name
1085 For i = 0 To UBound(sObjects)
1086 If UCase(pvIndex) = UCase(sObjects(i)) Then
1087 sObjectName = sObjects(i)
1088 bFound = True
1089 Exit For
1090 End If
1091 Next i
1092 If Not bFound Then Goto Trace_NotFound
1093 Case Else &apos; pvIndex is numeric
1094 If pvIndex &lt; 0 Or pvIndex &gt; UBound(sObjects) Then Goto Trace_IndexError
1095 sObjectName = sObjects(pvIndex)
1096 End Select
1098 Set oObject = New DataDef
1099 With oObject
1100 ._This = oObject
1101 ._Type = OBJTABLEDEF
1102 ._Name = sObjectName
1103 Set ._ParentDatabase = _This
1104 ._ReadOnly = _ReadOnly
1105 Set .Table = oTables.getByName(sObjectName)
1106 .CatalogName = .Table.CatalogName
1107 .SchemaName = .Table.SchemaName
1108 .TableName = .Table.Name
1109 End With
1111 Exit_Function:
1112 Set TableDefs = oObject
1113 Set oObject = Nothing
1114 Utils._ResetCalledSub(cstThisSub)
1115 Exit Function
1116 Error_Function:
1117 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1118 GoTo Exit_Function
1119 Trace_NotFound:
1120 If Not pbCheck Then TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(), 0, , Array(_GetLabel(&quot;TABLE&quot;), pvIndex))
1121 Goto Exit_Function
1122 Trace_IndexError:
1123 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(), 0)
1124 Goto Exit_Function
1125 End Function &apos; TableDefs V1.1.0
1127 REM -----------------------------------------------------------------------------------------------------------------------
1128 REM --- PRIVATE FUNCTIONS ---
1129 REM -----------------------------------------------------------------------------------------------------------------------
1131 REM -----------------------------------------------------------------------------------------------------------------------
1132 Private Function _DFunction(ByVal psFunction As String _
1133 , ByVal psExpr As String _
1134 , ByVal psDomain As String _
1135 , ByVal pvCriteria As Variant _
1136 , ByVal Optional pvOrderClause As Variant _
1137 ) As Variant
1138 &apos;Arguments: psFunction an optional aggregate function
1139 &apos; psExpr: an SQL expression [might contain an aggregate function]
1140 &apos; psDomain: a table- or queryname
1141 &apos; pvCriteria: an optional WHERE clause
1142 &apos; pcOrderClause: an optional order clause incl. &quot;DESC&quot; if relevant
1144 If _ErrorHandler() Then On Local Error GoTo Error_Function
1146 Dim oResult As Object &apos;To retrieve the value to find.
1147 Dim vResult As Variant &apos;Return value for function.
1148 Dim sSql As String &apos;SQL statement.
1149 Dim oStatement As Object &apos;For CreateStatement method
1150 Dim sExpr As String &apos;For inclusion of aggregate function
1151 Dim sTempField As String &apos;Random temporary field in SQL expression
1153 Dim sTarget as String, sWhere As String, sOrderBy As String, sLimit As String
1154 Dim sProductName As String
1156 vResult = Null
1158 Randomize 2^14-1
1159 sTempField = &quot;[TEMP&quot; &amp; Right(&quot;00000&quot; &amp; Int(100000 * Rnd), 5) &amp; &quot;]&quot;
1160 If pvCriteria &lt;&gt; &quot;&quot; Then sWhere = &quot; WHERE &quot; &amp; pvCriteria Else sWhere = &quot;&quot;
1161 If pvOrderClause &lt;&gt; &quot;&quot; Then sOrderBy = &quot; ORDER BY &quot; &amp; pvOrderClause Else sOrderBy = &quot;&quot;
1162 sLimit = &quot;&quot;
1164 sProductName = UCase(MetaData.getDatabaseProductName())
1166 Select Case sProductName
1167 Case &quot;MYSQL&quot;, &quot;SQLITE&quot;
1168 If psFunction = &quot;&quot; Then
1169 sTarget = psExpr
1170 sLimit = &quot; LIMIT 1&quot;
1171 Else
1172 sTarget = UCase(psFunction) &amp; &quot;(&quot; &amp; psExpr &amp; &quot;)&quot;
1173 End If
1174 sSql = &quot;SELECT &quot; &amp; sTarget &amp; &quot; AS &quot; &amp; sTempField &amp; &quot; FROM &quot; &amp; psDomain &amp; sWhere &amp; sOrderBy &amp; sLimit
1175 Case &quot;FIREBIRD (ENGINE12)&quot;
1176 If psFunction = &quot;&quot; Then sTarget = &quot;FIRST 1 &quot; &amp; psExpr Else sTarget = UCase(psFunction) &amp; &quot;(&quot; &amp; psExpr &amp; &quot;)&quot;
1177 sSql = &quot;SELECT &quot; &amp; sTarget &amp; &quot; AS &quot; &amp; sTempField &amp; &quot; FROM &quot; &amp; psDomain &amp; sWhere &amp; sOrderBy
1178 Case Else &apos; Standard syntax - Includes HSQLDB
1179 If psFunction = &quot;&quot; Then sTarget = &quot;TOP 1 &quot; &amp; psExpr Else sTarget = UCase(psFunction) &amp; &quot;(&quot; &amp; psExpr &amp; &quot;)&quot;
1180 sSql = &quot;SELECT &quot; &amp; sTarget &amp; &quot; AS &quot; &amp; sTempField &amp; &quot; FROM &quot; &amp; psDomain &amp; sWhere &amp; sOrderBy
1181 End Select
1183 &apos;Lookup the value.
1184 Set oStatement = Connection.createStatement()
1185 With oStatement
1186 .ResultSetType = com.sun.star.sdbc.ResultSetType.FORWARD_ONLY
1187 .ResultSetConcurrency = com.sun.star.sdbc.ResultSetConcurrency.READ_ONLY
1188 .EscapeProcessing = False
1189 sSql = _ReplaceSquareBrackets(sSql) &apos;Substitute [] by quote string
1190 Set oResult = .executeQuery(sSql)
1191 If Not IsNull(oResult) And Not IsEmpty(oResult) Then
1192 If Not oResult.next() Then Goto Exit_Function
1193 vResult = Utils._getResultSetColumnValue(oResult, 1, True) &apos; Force return of binary field
1194 End If
1195 End With
1197 Exit_Function:
1198 &apos;Assign the returned value.
1199 _DFunction = vResult
1200 Set oResult = Nothing
1201 Set oStatement = Nothing
1202 Exit Function
1203 Error_Function:
1204 TraceError(TRACEFATAL, ERRDFUNCTION, _A2B_.CalledSub, 0, , sSQL)
1205 Goto Exit_Function
1206 End Function &apos; DFunction V1.5.0
1208 REM -----------------------------------------------------------------------------------------------------------------------
1209 Private Function _FilterOptionsDefault(ByVal plEncoding As Long) As String
1210 &apos; Return the default FilterOptions string for table/query export to csv
1212 Dim sFieldSeparator as string
1213 Const cstComma = &quot;,&quot;
1214 Const cstTextDelimitor = &quot;&quot;&quot;&quot;
1216 If _DecimalPoint() = &quot;,&quot; Then sFieldSeparator = &quot;;&quot; Else sFieldSeparator = cstComma
1217 _FilteroptionsDefault = Trim(Str(Asc(sFieldSeparator))) _
1218 &amp; cstComma &amp; Trim(Str(Asc(cstTextDelimitor))) _
1219 &amp; cstComma &amp; Trim(Str(plEncoding)) _
1220 &amp; cstComma &amp; &quot;1&quot;
1222 End Function &apos; _FilterOptionsDefault V1.4.0
1224 REM -----------------------------------------------------------------------------------------------------------------------
1225 Public Function _hasRecordset(ByVal psName As String) As Boolean
1226 &apos; Return True if psName if in the collection of Recordsets
1228 Dim oRecordset As Object
1229 If _ErrorHandler() Then On Local Error Goto Error_Function
1230 Set oRecordset = RecordsetsColl.Item(psName)
1231 _hasRecordset = True
1233 Exit_Function:
1234 Exit Function
1235 Error_Function: &apos; Item by key aborted
1236 _hasRecordset = False
1237 GoTo Exit_Function
1238 End Function &apos; _hasRecordset V0.9.5
1240 REM -----------------------------------------------------------------------------------------------------------------------
1241 Private Sub _LoadMetadata()
1242 &apos; Load essentially getTypeInfo() results from Metadata
1244 Dim sProduct As String
1245 Dim iInfo As Integer, oTypeInfo As Object, sName As String, lType As Integer
1247 Const cstMaxInfo = 40
1248 ReDim _ColumnTypes(0 To cstMaxInfo)
1249 ReDim _ColumnTypeNames(0 To cstMaxInfo)
1250 ReDim _ColumnPrecisions(0 To cstMaxInfo)
1251 Const cstHSQLDB1 = &quot;HSQL Database Engine 1.&quot;
1252 Const cstHSQLDB2 = &quot;HSQL Database Engine 2.&quot;
1253 Const cstFirebird = &quot;sdbc:embedded:firebird&quot;
1254 Const cstMSAccess2003 = &quot;MS Jet 0&quot;
1255 Const cstMSAccess2007 = &quot;MS Jet 04.&quot;
1256 Const cstMYSQL = &quot;MySQL&quot;
1257 Const cstPOSTGRES = &quot;PostgreSQL&quot;
1258 Const cstSQLITE = &quot;SQLite&quot;
1260 With com.sun.star.sdbc.DataType
1261 _ColumnTypesReference = Array( _
1262 .ARRAY _
1263 , .BIGINT _
1264 , .BINARY _
1265 , .BIT _
1266 , .BLOB _
1267 , .BOOLEAN _
1268 , .CHAR _
1269 , .CLOB _
1270 , .DATE _
1271 , .DECIMAL _
1272 , .DISTINCT _
1273 , .DOUBLE _
1274 , .FLOAT _
1275 , .INTEGER _
1276 , .LONGVARBINARY _
1277 , .LONGVARCHAR _
1278 , .NUMERIC _
1279 , .OBJECT _
1280 , .OTHER _
1281 , .REAL _
1282 , .REF _
1283 , .SMALLINT _
1284 , .SQLNULL _
1285 , .STRUCT _
1286 , .TIME _
1287 , .TIMESTAMP _
1288 , .TINYINT _
1289 , .VARBINARY _
1290 , .VARCHAR _
1292 End With
1294 With Metadata
1295 sProduct = .getDatabaseProductName() &amp; &quot; &quot; &amp; .getDatabaseProductVersion
1296 Select Case True
1297 Case Len(sProduct) &gt; Len(cstHSQLDB1) And Left(sProduct, Len(cstHSQLDB1)) = cstHSQLDB1
1298 _RDBMS = DBMS_HSQLDB1
1299 _ColumnTypesAlias = Array(0, -5, -2, 16, -4, 16, 1, -1, 91, 3, 0, 8, 6, 4, -4, -1, 2, 0, 0, 7, 0, 5, 0, 0, 92, 93, -6, -3, 12)
1300 _BinaryStream = True
1301 Case Len(sProduct) &gt; Len(cstHSQLDB2) And Left(sProduct, Len(cstHSQLDB2)) = cstHSQLDB2
1302 _RDBMS = DBMS_HSQLDB2
1303 _ColumnTypesAlias = Array(0, -5, -3, -7, 2004, 16, 1, 2005, 91, 3, 0, 8, 8, 4, -3, 12, 2, 0, 0, 8, 0, 5, 0, 0, 92, 93, -6, -3, 12)
1304 _BinaryStream = True
1305 Case .URL = cstFirebird &apos; Only embedded 3.0
1306 _RDBMS = DBMS_FIREBIRD
1307 _ColumnTypesAlias = Array(0, -5, -2, 16, 2004, 16, 1, 2005, 91, 3, 0, 8, 6, 4, -4, 2005, 2, 0, 0, 8, 0, 5, 0, 0, 92, 93, 4, 2004, 12)
1308 _BinaryStream = True
1309 Case Len(sProduct) &gt; Len(cstMSAccess2007) And Left(sProduct, Len(cstMSAccess2007)) = cstMSAccess2007
1310 _RDBMS = DBMS_MSACCESS2007
1311 _ColumnTypesAlias = Array(0, 4, -2, 16, -2, 16, 12, 12, 93, 8, 0, 8, 6, 4, -3, 12, 2, 0, 0, 8, 0, 5, 0, 0, 93, 93, -6, -2, 12)
1312 _BinaryStream = True
1313 Case Len(sProduct) &gt; Len(cstMSAccess2003) And Left(sProduct, Len(cstMSAccess2003)) = cstMSAccess2003
1314 _RDBMS = DBMS_MSACCESS2003
1315 _ColumnTypesAlias = Array(0, 4, -2, 16, -2, 16, 12, 12, 93, 8, 0, 8, 6, 4, -3, 12, 2, 0, 0, 8, 0, 5, 0, 0, 93, 93, -6, -2, 12)
1316 _BinaryStream = True
1317 Case Len(sProduct) &gt; Len(cstMYSQL) And Left(sProduct, Len(cstMYSQL)) = cstMYSQL
1318 _RDBMS = DBMS_MYSQL
1319 _ColumnTypesAlias = Array(0, -5, -2, -7, -4, -7, 1, -1, 91, 3, 0, 8, 8, 4, -4, -1, 2, 0, 0, 7, 0, 5, 0, 0, 92, 93, -6, -3, -1)
1320 _BinaryStream = False
1321 Case Len(sProduct) &gt; Len(cstPOSTGRES) And Left(sProduct, Len(cstPOSTGRES)) = cstPOSTGRES
1322 _RDBMS = DBMS_POSTGRES
1323 _ColumnTypesAlias = Array(0, -5, -3, 16, -3, 16, 1, 12, 91, 8, 0, 8, 8, 4, -3, 12, 2, 0, 0, 7, 0, 5, 0, 0, 92, 93, 4, -3, 12)
1324 _BinaryStream = True
1325 Case Len(sProduct) &gt; Len(cstSQLITE) And Left(sProduct, Len(cstSQLITE)) = cstSQLITE
1326 _RDBMS = DBMS_SQLITE
1327 _ColumnTypesAlias = Array(0, -5, -4, -7, -4, -7, 1, -1, 91, 8, 0, 8, 6, 4, -4, -1, 8, 0, 0, 8, 0, 5, 0, 0, 92, 93, -6, -4, 12)
1328 _BinaryStream = True
1329 Case Else
1330 _RDBMS = DBMS_UNKNOWN
1331 _BinaryStream = True
1332 End Select
1334 iInfo = -1
1335 Set oTypeInfo = MetaData.getTypeInfo()
1336 With oTypeInfo
1337 .next()
1338 Do While Not .isAfterLast() And iInfo &lt; cstMaxInfo
1339 sName = .getString(1)
1340 lType = .getLong(2)
1341 If _RDBMS = DBMS_POSTGRES And (Left(sName, 1) &lt;&gt; &quot;_&quot; Or lType &lt;&gt; -1) Then &apos; Skip
1342 Else
1343 iInfo = iInfo + 1
1344 _ColumnTypeNames(iInfo) = sName
1345 _ColumnTypes(iInfo) = lType
1346 _ColumnPrecisions(iInfo) = CLng(.getLong(3))
1347 End If
1348 .next()
1349 Loop
1350 End With
1351 ReDim Preserve _ColumnTypes(0 To iInfo)
1352 ReDim Preserve _ColumnTypeNames(0 To iInfo)
1353 ReDim Preserve _ColumnPrecisions(0 To iInfo)
1354 End With
1356 End Sub &apos; _LoadMetadata V1.6.0
1358 REM -----------------------------------------------------------------------------------------------------------------------
1359 Private Function _OutputBinaryToHTML() As String
1360 &apos; Converts Binary value to HTML compatible string
1362 _OutputBinaryToHTML = &quot;&amp;nbsp;&quot;
1364 End Function &apos; _OutputBinaryToHTML V1.4.0
1366 REM -----------------------------------------------------------------------------------------------------------------------
1367 Private Function _OutputBooleanToHTML(ByVal pbBool As Boolean) As String
1368 &apos; Converts input boolean value to HTML compatible string
1370 _OutputBooleanToHTML = Iif(pbBool, &quot;&amp;#x2714;&quot;, &quot;&amp;#x2716;&quot;) &apos; ✔ and ✖
1372 End Function &apos; _OutputBooleanToHTML V1.4.0
1374 REM -----------------------------------------------------------------------------------------------------------------------
1375 Private Function _OutputClassToHTML(ByVal pvArray As Variant) As String
1376 &apos; Formats classes attribute of &lt;tr&gt; and &lt;td&gt; tags
1378 If Not IsArray(pvArray) Then
1379 _OutputClassToHTML = &quot;&quot;
1380 ElseIf UBound(pvArray) &lt; LBound(pvArray) Then
1381 _OutputClassToHTML = &quot;&quot;
1382 Else
1383 _OutputClassToHTML = &quot; class=&quot;&quot;&quot; &amp; Join(pvArray, &quot; &quot;) &amp; &quot;&quot;&quot;&quot;
1384 End If
1386 End Function &apos; _OutputClassToHTML V1.4.0
1388 REM -----------------------------------------------------------------------------------------------------------------------
1389 Private Function _OutputDataToHTML(ByRef pvTable As Variant, ByVal pvName As String, ByVal piFile As Integer _
1390 , ByRef Optional pvHeaders As Variant _
1391 , ByRef Optional pvData As Variant _
1392 ) As Boolean
1393 &apos; Write html tags around data found in pvTable
1394 &apos; Exit when error without execution stop (to avoid file remaining open ...)
1396 Dim oTableRS As Object, vData() As Variant, i As Integer, j As Integer
1397 Dim vFieldsBin() As Variant, iDataType As Integer, iNumRows As Integer, iNumFields As Integer, vDataCell As Variant
1398 Dim bDataArray As Boolean, sHeader As String
1399 Dim vTrClass() As Variant, vTdClass As Variant, iCountRows As Integer, iLastRow As Integer
1400 Const cstMaxRows = 200
1401 On Local Error GoTo Error_Function
1403 bDataArray = IsNull(pvTable)
1404 Print #piFile, &quot; &lt;table class=&quot;&quot;dbdatatable&quot;&quot;&gt;&quot;
1405 Print #piFile, &quot; &lt;caption&gt;&quot; &amp; pvName &amp; &quot;&lt;/caption&gt;&quot;
1407 vFieldsBin() = Array()
1408 If bDataArray Then
1409 Set oTableRS = Nothing
1410 iNumFields = UBound(pvHeaders) + 1
1411 ReDim vFieldsBin(0 To iNumFields - 1)
1412 For i = 0 To iNumFields - 1
1413 vFieldsBin(i) = False
1414 Next i
1415 Else
1416 Set oTableRS = pvTable.OpenRecordset( , , dbReadOnly)
1417 iNumFields = oTableRS.Fields.Count
1418 ReDim vFieldsBin(0 To iNumFields - 1)
1419 With com.sun.star.sdbc.DataType
1420 For i = 0 To iNumFields - 1
1421 iDataType = oTableRS.Fields(i).DataType
1422 vFieldsBin(i) = Utils._IsBinaryType(iDataType)
1423 Next i
1424 End With
1425 End If
1427 With oTableRS
1428 Print #piFile, &quot; &lt;thead&gt;&quot;
1429 Print #piFile, &quot; &lt;tr&gt;&quot;
1430 For i = 0 To iNumFields - 1
1431 If bDataArray Then sHeader = pvHeaders(i) Else sHeader = .Fields(i)._Name
1432 Print #piFile, &quot; &lt;th scope=&quot;&quot;col&quot;&quot;&gt;&quot; &amp; sHeader &amp; &quot;&lt;/th&gt;&quot;
1433 Next i
1434 Print #piFile, &quot; &lt;/tr&gt;&quot;
1435 Print #piFile, &quot; &lt;/thead&gt;&quot;
1436 Print #piFile, &quot; &lt;tfoot&gt;&quot;
1437 Print #piFile, &quot; &lt;/tfoot&gt;&quot;
1439 Print #piFile, &quot; &lt;tbody&gt;&quot;
1440 If bDataArray Then
1441 iLastRow = UBound(pvData, 2) + 1
1442 Else
1443 .MoveLast
1444 iLastRow = .RecordCount
1445 .MoveFirst
1446 End If
1447 iCountRows = 0
1448 Do While iCountRows &lt; iLastRow
1449 If bDataArray Then
1450 iNumRows = iLastRow
1451 Else
1452 vData() = .GetRows(cstMaxRows)
1453 iNumRows = UBound(vData, 2) + 1
1454 End If
1455 For j = 0 To iNumRows - 1
1456 iCountRows = iCountRows + 1
1457 vTrClass() = Array()
1458 If iCountRows = 1 Then vTrClass() = _AddArray(vTrClass, &quot;firstrow&quot;)
1459 If iCountRows = iLastRow Then vTrClass() = _AddArray(vTrClass, &quot;lastrow&quot;)
1460 If (iCountRows Mod 2) = 0 Then vTrClass() = _AddArray(vTrClass, &quot;even&quot;) Else vTrClass() = _AddArray(vTrClass, &quot;odd&quot;)
1461 Print #piFile, &quot; &lt;tr&quot; &amp; _OutputClassToHTML(vTrClass) &amp; &quot;&gt;&quot;
1462 For i = 0 To iNumFields - 1
1463 vTdClass() = Array()
1464 If i = 0 Then vTdClass() = _AddArray(vTdClass, &quot;firstcol&quot;)
1465 If i = iNumFields - 1 Then vTdClass() = _AddArray(vTdClass, &quot;lastcol&quot;)
1466 If Not vFieldsBin(i) Then
1467 If bDataArray Then vDataCell = pvData(i, j) Else vDataCell = vData(i, j)
1468 If vDataCell Is Nothing Then vDataCell = Null &apos; Necessary because Null object has not a VarType = vbNull
1469 If VarType(vDataCell) = vbString Then &apos; Null string gives IsDate = True !
1470 If Len(vDataCell) &gt; 0 And IsDate(vDataCell) Then vDataCell = CDate(vDataCell)
1471 End If
1472 Select Case VarType(vDataCell)
1473 Case vbEmpty, vbNull
1474 vTdClass() = _AddArray(vTdClass, &quot;null&quot;)
1475 Print #piFile, &quot; &lt;td&quot; &amp; _OutputClassToHTML(vTdClass) &amp; &quot;&gt;&quot; &amp; _OutputNullToHTML() &amp; &quot;&lt;/td&gt;&quot;
1476 Case vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbDecimal, vbUShort, vbULong, vbBigInt
1477 vTdClass() = _AddArray(vTdClass, &quot;numeric&quot;)
1478 If vDataCell &lt; 0 Then vTdClass() = _AddArray(vTdClass, &quot;negative&quot;)
1479 Print #piFile, &quot; &lt;td&quot; &amp; _OutputClassToHTML(vTdClass) &amp; &quot;&gt;&quot; &amp; _OutputNumberToHTML(vDataCell) &amp; &quot;&lt;/td&gt;&quot;
1480 Case vbBoolean
1481 vTdClass() = _AddArray(vTdClass, &quot;bool&quot;)
1482 If vDataCell = False Then vTdClass() = _AddArray(vTdClass, &quot;false&quot;)
1483 Print #piFile, &quot; &lt;td&quot; &amp; _OutputClassToHTML(vTdClass) &amp; &quot;&gt;&quot; &amp; _OutputBooleanToHTML(vDataCell) &amp; &quot;&lt;/td&gt;&quot;
1484 Case vbDate
1485 vTdClass() = _AddArray(vTdClass, &quot;date&quot;)
1486 Print #piFile, &quot; &lt;td&quot; &amp; _OutputClassToHTML(vTdClass) &amp; &quot;&gt;&quot; &amp; _OutputDateToHTML(vDataCell) &amp; &quot;&lt;/td&gt;&quot;
1487 Case vbString
1488 vTdClass() = _AddArray(vTdClass, &quot;char&quot;)
1489 Print #piFile, &quot; &lt;td&quot; &amp; _OutputClassToHTML(vTdClass) &amp; &quot;&gt;&quot; &amp; _OutputStringToHTML(vDataCell) &amp; &quot;&lt;/td&gt;&quot;
1490 Case Else
1491 Print #piFile, &quot; &lt;td&quot; &amp; _OutputClassToHTML(vTdClass) &amp; &quot;&gt;&quot; &amp; _CStr(vDataCell) &amp; &quot;&lt;/td&gt;&quot;
1492 End Select
1493 Else &apos; Binary fields
1494 Print #piFile, &quot; &lt;td&quot; &amp; _OutputClassToHTML(vTdClass) &amp; &quot;&gt;&quot; &amp; _OutputBinaryToHTML() &amp; &quot;&lt;/td&gt;&quot;
1495 End If
1496 Next i
1497 Print #piFile, &quot; &lt;/tr&gt;&quot;
1498 Next j
1499 Loop
1501 If Not bDataArray Then .mClose()
1502 End With
1503 Set oTableRS = Nothing
1505 Print #piFile, &quot; &lt;/tbody&gt;&quot;
1506 Print #piFile, &quot; &lt;/table&gt;&quot;
1507 _OutputDataToHTML = True
1509 Exit_Function:
1510 Exit Function
1511 Error_Function:
1512 TraceError(TRACEWARNING, Err, &quot;_OutputDataToHTML&quot;, Erl)
1513 _OutputDataToHTML = False
1514 Resume Exit_Function
1515 End Function &apos; _OutputDataToHTML V1.4.0
1517 REM -----------------------------------------------------------------------------------------------------------------------
1518 Private Function _OutputDateToHTML(ByVal psDate As Date) As String
1519 &apos; Converts input date to HTML compatible string
1521 _OutputDateToHTML = Format(psDate) &apos; With regional settings - Ignores time if = to 0
1523 End Function &apos; _OutputDateToHTML V1.4.0
1525 REM -----------------------------------------------------------------------------------------------------------------------
1526 Private Function _OutputNullToHTML() As String
1527 &apos; Converts Null value to HTML compatible string
1529 _OutputNullToHTML = &quot;&amp;nbsp;&quot;
1531 End Function &apos; _OutputNullToHTML V1.4.0
1533 REM -----------------------------------------------------------------------------------------------------------------------
1534 Private Function _OutputNumberToHTML(ByVal pvNumber As Variant, ByVal Optional piPrecision As Integer) As String
1535 &apos; Converts input number to HTML compatible string
1537 Dim vNumber As Variant
1538 If IsMissing(piPrecision) Then piPrecision = -1
1539 If pvNumber = Int(pvNumber) Then
1540 vNumber = Int(pvNumber)
1541 Else
1542 If piPrecision &gt;= 0 Then vNumber = (Int(pvNumber * 10 ^ piPrecision + 0.5)) / 10 ^ piPrecision Else vNumber = pvNumber
1543 End If
1544 _OutputNumberToHTML = Format(vNumber)
1546 End Function &apos; _OutputNumberToHTML V1.4.0
1548 REM -----------------------------------------------------------------------------------------------------------------------
1549 Private Function _OutputStringToHTML(ByVal psString As String) As String
1550 &apos; Converts input string to HTML compatible string
1551 &apos; - UTF-8 encoding
1552 &apos; - recognition of next patterns
1553 &apos; - &amp;quot; - &amp;amp; - &amp;apos; - &amp;lt; - &amp;gt;
1554 &apos; - &lt;pre&gt;
1555 &apos; - &lt;a href=&quot;...
1556 &apos; - &lt;br&gt;
1557 &apos; - &lt;img src=&quot;...
1558 &apos; - &lt;b&gt;, &lt;u&gt;, &lt;i&gt;
1560 Dim vPatterns As Variant
1561 Dim lCurrentChar as Long, lPattern As Long, lNextPattern As Long, sPattern As String
1562 Dim sOutput As String, sChar As String
1563 Dim sUrl As String, lNextQuote As Long, lUrl As Long, bQuote As Boolean, bTagEnd As Boolean
1564 Dim i As Integer, l As Long
1566 vPatterns = Array( _
1567 &quot;&amp;quot;&quot;, &quot;&amp;amp;&quot;, &quot;&amp;apos;&quot;, &quot;&amp;lt;&quot;, &quot;&amp;gt;&quot;, &quot;&amp;nbsp;&quot; _
1568 , &quot;&lt;pre&gt;&quot;, &quot;&lt;/pre&gt;&quot;, &quot;&lt;br&gt;&quot; _
1569 , &quot;&lt;a href=&quot;&quot;&quot;, &quot;&lt;a id=&quot;&quot;&quot;, &quot;&lt;/a&gt;&quot;, &quot;&lt;img src=&quot;&quot;&quot; _
1570 , &quot;&lt;span class=&quot;&quot;&quot;, &quot;&lt;/span&gt;&quot; _
1571 , &quot;&lt;b&gt;&quot;, &quot;&lt;/b&gt;&quot;, &quot;&lt;u&gt;&quot;, &quot;&lt;/u&gt;&quot;, &quot;&lt;i&gt;&quot;, &quot;&lt;/i&gt;&quot; _
1574 lCurrentChar = 1
1575 sOutput = &quot;&quot;
1577 Do While lCurrentChar &lt;= Len(psString)
1578 &apos; Where is next closest pattern ?
1579 lPattern = Len(psString) + 1
1580 sPattern = &quot;&quot;
1581 For i = 0 To UBound(vPatterns)
1582 lNextPattern = InStr(lCurrentChar, psString, vPatterns(i), 1) &apos; Text (not case-sensitive) string comparison
1583 If lNextPattern &gt; 0 And lNextPattern &lt; lPattern Then
1584 lPattern = lNextPattern
1585 sPattern = Mid(psString, lPattern, Len(vPatterns(i)))
1586 End If
1587 Next i
1588 &apos; Up to the next pattern or to the end of the string, UTF8-encode each character
1589 For l = lCurrentChar To lPattern - 1
1590 sChar = Mid(psString, l, 1)
1591 sOutput = sOutput &amp; Utils._UTF8Encode(sChar)
1592 Next l
1593 &apos; Process hyperlink patterns and keep others
1594 If Len(sPattern) &gt; 0 Then
1595 Select Case LCase(sPattern)
1596 Case &quot;&lt;a href=&quot;&quot;&quot;, &quot;&lt;a id=&quot;&quot;&quot;, &quot;&lt;img src=&quot;&quot;&quot;, &quot;&lt;span class=&quot;&quot;&quot;
1597 &apos; Up to next quote, url-encode
1598 lNextQuote = 0
1599 lUrl = lPattern + Len(sPattern)
1600 lNextQuote = InStr(lUrl, psString, &quot;&quot;&quot;&quot;, 1)
1601 If lNextQuote = 0 Then lNextQuote = Len(psString) &apos; Should not happen but, if quoted string not closed ...
1602 sUrl = Mid(psString, lUrl, lNextQuote - lUrl)
1603 sOutput = sOutput &amp; sPattern &amp; sUrl &amp; &quot;&quot;&quot;&quot;
1604 lCurrentChar = lNextQuote + 1
1605 bQuote = False
1606 bTagEnd = False
1608 sChar = Mid(psString, lCurrentChar, 1)
1609 Select Case sChar
1610 Case &quot;&quot;&quot;&quot;
1611 bQuote = Not bQuote
1612 sOutput = sOutput &amp; sChar
1613 Case &quot;&gt;&quot; &apos; Tag end if not somewhere between quotes
1614 If Not bQuote Then
1615 bTagEnd = True
1616 sOutput = sOutput &amp; sChar
1617 Else
1618 sOutput = sOutput &amp; _UTF8Encode(sChar)
1619 End If
1620 Case Else
1621 sOutput = sOutput &amp; _UTF8Encode(sChar)
1622 End Select
1623 lCurrentChar = lCurrentChar + 1
1624 If lCurrentChar &gt; Len(psString) Then bTagEnd = True &apos; Should not happen but, if tag not closed ...
1625 Loop Until bTagEnd
1626 Case Else
1627 sOutput = sOutput &amp; sPattern
1628 lCurrentChar = lPattern + Len(sPattern)
1629 End Select
1630 Else
1631 lCurrentChar = Len(psString) + 1
1632 End If
1633 Loop
1635 _OutputStringToHTML = sOutput
1637 End Function &apos; _OutputStringToHTML V1.4.0
1639 REM -----------------------------------------------------------------------------------------------------------------------
1640 Private Function _OutputToCalc(poData As Object _
1641 , ByVal psOutputFile As String _
1642 , ByVal psFilter As String _
1643 , Optional ByVal plEncoding As Long _
1644 ) As Boolean
1645 &apos; https://wiki.documentfoundation.org/Documentation/DevGuide/Spreadsheet_Documents#Database_Import
1646 &apos; https://wiki.documentfoundation.org/Documentation/DevGuide/Spreadsheet_Documents#Filter_Options
1648 Dim oCalcDoc As Object, oSheet As Object, vWin As Variant
1649 Dim vImportDesc() As Variant, iSource As Integer
1650 Dim oRange As Object, i As Integer, iCol As Integer, oColumns As Object
1652 If _ErrorHandler() Then On Local Error Goto Error_Function
1653 _OutputToCalc = False
1654 If IsMissing(plEncoding) Then plEncoding = acUTF8Encoding
1655 &apos; Create a new OO-Calc-Document
1656 Set oCalcDoc = StarDesktop.LoadComponentFromURL( _
1657 &quot;private:factory/scalc&quot; _
1658 , &quot;_default&quot; ,0, Array() _
1661 &apos; Get the unique spreadsheet
1662 Set oSheet = oCalcDoc.Sheets(0)
1664 &apos; Describe import
1665 With poData
1666 If ._Type = &quot;TABLEDEF&quot; Then
1667 iSource = com.sun.star.sheet.DataImportMode.TABLE
1668 Else
1669 iSource = com.sun.star.sheet.DataImportMode.QUERY
1670 End If
1671 vImportDesc = Array( _
1672 _MakePropertyValue(&quot;DatabaseName&quot;, URL) _
1673 , _MakePropertyValue(&quot;SourceType&quot;, iSource) _
1674 , _MakePropertyValue(&quot;SourceObject&quot;, ._Name) _
1676 oSheet.Name = ._Name
1677 End With
1679 &apos; Import
1680 oSheet.getCellByPosition(0, 0).doImport(vImportDesc())
1682 Select Case psFilter
1683 Case acFormatODS, acFormatXLS, acFormatXLSX &apos; Formatting
1684 iCol = poData.Fields().Count
1685 Set oRange = oSheet.getCellRangeByPosition(0, 0, iCol - 1, 0)
1686 oRange.CharWeight = com.sun.star.awt.FontWeight.BOLD
1687 oRange.CellBackColor = RGB(200, 200, 200)
1688 oRange.HoriJustify = com.sun.star.table.CellHoriJustify.CENTER
1689 Set oColumns = oRange.getColumns()
1690 For i = 0 To iCol - 1
1691 oColumns.getByIndex(i).OptimalWidth = True
1692 Next i
1693 oCalcDoc.storeAsUrl(psOutputFile, Array( _
1694 _MakePropertyValue(&quot;FilterName&quot;, psFilter) _
1695 , _MakePropertyValue(&quot;Overwrite&quot;, True) _
1697 Case Else
1698 oCalcDoc.storeAsUrl(psOutputFile, Array( _
1699 _MakePropertyValue(&quot;FilterName&quot;, psFilter) _
1700 , _MakePropertyValue(&quot;FilterOptions&quot;, _FilterOptionsDefault(plEncoding)) _
1701 , _MakePropertyValue(&quot;Overwrite&quot;, True) _
1703 End Select
1705 oCalcDoc.close(False)
1706 _OutputToCalc = True
1708 Exit_Function:
1709 Set oColumns = Nothing
1710 Set oRange = Nothing
1711 Set oSheet = Nothing
1712 Set oCalcDoc = Nothing
1713 Exit Function
1714 Error_Function:
1715 TraceError(TRACEABORT, ERRDFUNCTION, _A2B_.CalledSub, 0, , sSQL)
1716 Goto Exit_Function
1717 End Function &apos; OutputToCalc V1.4.0
1719 REM -----------------------------------------------------------------------------------------------------------------------
1720 Public Function _OutputToHTML(ByRef pvTable As Variant, ByVal pvName As String, ByVal psOutputFile As String, ByVal psTemplateFile As String _
1721 , ByRef Optional pvHeaders As Variant _
1722 , ByRef Optional pvData As Variant _
1723 ) As Boolean
1724 &apos; http://www.ehow.com/how_5652706_create-html-template-ms-access.html
1726 Dim bDataArray As Boolean
1727 Dim vMinimalTemplate As Variant, vTemplate As Variant
1728 Dim iFile As Integer, i As Integer, sLine As String, lBody As Long
1729 Const cstTitle = &quot;&lt;!--Template_Title--&gt;&quot;, cstBody = &quot;&lt;!--Template_Body--&gt;&quot;
1730 Const cstTitleAlt = &quot;&lt;!--AccessTemplate_Title--&gt;&quot;, cstBodyAlt = &quot;&lt;!--AccessTemplate_Body--&gt;&quot;
1732 On Local Error GoTo Error_Function
1733 vMinimalTemplate = Array( _
1734 &quot;&lt;!DOCTYPE html&gt;&quot; _
1735 , &quot;&lt;html&gt;&quot; _
1736 , &quot; &lt;head&gt;&quot; _
1737 , &quot; &lt;title&gt;&quot; &amp; cstTitle &amp; &quot;&lt;/title&gt;&quot; _
1738 , &quot; &lt;/head&gt;&quot; _
1739 , &quot; &lt;body&gt;&quot; _
1740 , &quot; &quot; &amp; cstBody _
1741 , &quot; &lt;/body&gt;&quot; _
1742 , &quot;&lt;/html&gt;&quot; _
1745 vTemplate = _ReadFileIntoArray(psTemplateFile)
1746 If LBound(vTemplate) &gt; UBound(vTemplate) Then vTemplate() = vMinimalTemplate()
1748 bDataArray = IsNull(pvTable)
1750 &apos; Write output file
1751 iFile = FreeFile()
1752 Open psOutputFile For Output Access Write Lock Read Write As #iFile
1753 For i = 0 To UBound(vTemplate)
1754 sLine = vTemplate(i)
1755 sLine = Join(Split(sLine, cstTitleAlt), cstTitle)
1756 sLine = Join(Split(sLine, cstBodyAlt), cstBody)
1757 Select Case True
1758 Case InStr(sLine, cstTitle) &gt; 0
1759 sLine = Join(Split(sLine, cstTitle), pvName)
1760 Print #iFile, sLine
1761 Case InStr(sLine, cstBody) &gt; 0
1762 lBody = InStr(sLine, cstBody)
1763 If lBody &gt; 1 Then Print #iFile, Left(sLine, lBody - 1)
1764 If bDataArray Then
1765 _OutputDataToHTML(pvTable, pvName, iFile, pvHeaders, pvData)
1766 Else
1767 _OutputDataToHTML(pvTable, pvName, iFile)
1768 End If
1769 If Len(sLine) &gt; lBody + Len(cstBody) - 1 Then Print #iFile, Right(sLine, Len(sLine) - lBody + Len(cstBody) + 1)
1770 Case Else
1771 Print #iFile, sLine
1772 End Select
1773 Next i
1774 Close #iFile
1776 _OutputToHTML = True
1778 Exit_Function:
1779 Exit Function
1780 Error_Function:
1781 _OutputToHTML = False
1782 GoTo Exit_Function
1783 End Function &apos; _OutputToHTML V1.4.0
1785 REM -----------------------------------------------------------------------------------------------------------------------
1786 Private Function _PropertiesList() As Variant
1788 _PropertiesList = Array(&quot;Connect&quot;, &quot;Name&quot;, &quot;ObjectType&quot; _
1789 , &quot;OnCreate&quot;, &quot;OnFocus&quot;, &quot;OnLoad&quot;, &quot;OnLoadFinished&quot;, &quot;OnModifyChanged&quot; _
1790 , &quot;OnNew&quot;, &quot;OnPrepareUnload&quot;, &quot;OnPrepareViewClosing&quot;, &quot;OnSave&quot;, &quot;OnSaveAs&quot; _
1791 , &quot;OnSaveAsDone&quot;, &quot;OnSaveAsFailed&quot;, &quot;OnSaveDone&quot;, &quot;OnSaveFailed&quot;, &quot;OnSaveTo&quot; _
1792 , &quot;OnSaveToDone&quot;, &quot;OnSaveToFailed&quot;, &quot;OnSubComponentClosed&quot;, &quot;OnSubComponentOpened&quot; _
1793 , &quot;OnTitleChanged&quot;, &quot;OnUnfocus&quot;, &quot;OnUnload&quot;, &quot;OnViewClosed&quot;, &quot;OnViewCreated&quot; _
1794 , &quot;Version&quot; _
1797 End Function &apos; _PropertiesList
1799 REM -----------------------------------------------------------------------------------------------------------------------
1800 Private Function _PropertyGet(ByVal psProperty As String) As Variant
1801 &apos; Return property value of the psProperty property name
1803 Dim i As Integer, vEvents As Variant, sEvent As String, vEvent As Variant
1805 If _ErrorHandler() Then On Local Error Goto Error_Function
1806 Utils._SetCalledSub(&quot;Database.get&quot; &amp; psProperty)
1808 _PropertyGet = EMPTY
1810 Select Case UCase(psProperty)
1811 Case UCase(&quot;Connect&quot;)
1812 If IsNull(Document) Then _PropertyGet = &quot;&quot; Else _PropertyGet = Document.Datasource.URL
1813 &apos; Location = ConvertFromUrl(URL)
1814 Case UCase(&quot;Name&quot;)
1815 _PropertyGet = Title
1816 Case UCase(&quot;ObjectType&quot;)
1817 _PropertyGet = _Type
1818 Case UCase(&quot;OnCreate&quot;), UCase(&quot;OnFocus&quot;), UCase(&quot;OnLoad&quot;), UCase(&quot;OnLoadFinished&quot;), UCase(&quot;OnModifyChanged&quot;) _
1819 , UCase(&quot;OnNew&quot;), UCase(&quot;OnPrepareUnload&quot;), UCase(&quot;OnPrepareViewClosing&quot;), UCase(&quot;OnSave&quot;), UCase(&quot;OnSaveAs&quot;) _
1820 , UCase(&quot;OnSaveAsDone&quot;), UCase(&quot;OnSaveAsFailed&quot;), UCase(&quot;OnSaveDone&quot;), UCase(&quot;OnSaveFailed&quot;), UCase(&quot;OnSaveTo&quot;) _
1821 , UCase(&quot;OnSaveToDone&quot;), UCase(&quot;OnSaveToFailed&quot;), UCase(&quot;OnSubComponentClosed&quot;), UCase(&quot;OnSubComponentOpened&quot;) _
1822 , UCase(&quot;OnTitleChanged&quot;), UCase(&quot;OnUnfocus&quot;), UCase(&quot;OnUnload&quot;), UCase(&quot;OnViewClosed&quot;), UCase(&quot;OnViewCreated&quot;)
1823 &apos; Find script event
1824 sEvent = &quot;&quot;
1825 If IsNull(Document) Then vEvents = Array() Else vEvents = Document.getEvents().ElementNames &apos; Returns an array
1826 For i = 0 To UBound(vEvents)
1827 If UCase(vEvents(i)) = UCase(psProperty) Then
1828 sEvent = vEvents(i)
1829 Exit For
1830 End If
1831 Next i
1832 If sEvent = &quot;&quot; Then
1833 _PropertyGet = &quot;&quot;
1834 Else
1835 vEvent = Document.getEvents().getByName(sEvent)
1836 If IsEmpty(vEvent) Then
1837 _PropertyGet = &quot;&quot;
1838 ElseIf vEvent(0).Value &lt;&gt; &quot;Script&quot; Then
1839 _PropertyGet = &quot;&quot;
1840 Else
1841 _PropertyGet = vEvent(1).Value
1842 End If
1843 End If
1844 Case UCase(&quot;Version&quot;)
1845 _PropertyGet = MetaData.getDatabaseProductName() &amp; &quot; &quot; &amp; MetaData.getDatabaseProductVersion
1846 Case Else
1847 Goto Trace_Error
1848 End Select
1850 Exit_Function:
1851 Utils._ResetCalledSub(&quot;Database.get&quot; &amp; psProperty)
1852 Exit Function
1853 Trace_Error:
1854 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(), 0, , psProperty)
1855 _PropertyGet = EMPTY
1856 Goto Exit_Function
1857 Error_Function:
1858 TraceError(TRACEABORT, Err, &quot;Database._PropertyGet&quot;, Erl)
1859 _PropertyGet = EMPTY
1860 GoTo Exit_Function
1861 End Function &apos; _PropertyGet
1863 REM -----------------------------------------------------------------------------------------------------------------------
1864 Public Function _ReplaceSquareBrackets(ByVal psSql As String) As String
1865 &apos; Returns psSql after substitution of [] by quote character
1866 &apos; [] square brackets in (single) quoted strings not affected
1868 Dim sQuote As String &apos;RDBMS specific quote character
1869 Dim vSubStrings() As Variant, i As Integer
1870 Const cstSingleQuote = &quot;&apos;&quot;
1872 sQuote = MetaData.IdentifierQuoteString
1873 If sQuote = &quot; &quot; Then &apos; IdentifierQuoteString returns a space &quot; &quot; if identifier quoting is not supported.
1874 _ReplaceSquareBrackets = Trim(psSql)
1875 Exit Function
1876 End If
1877 vSubStrings() = Split(psSql, cstSingleQuote)
1878 For i = 0 To UBound(vSubStrings)
1879 If (i Mod 2) = 0 Or (i = UBound(vSubStrings)) Then &apos; Only even substrings are parsed for square brackets. Last substring is parsed anyway
1880 vSubStrings(i) = Join(Split(vSubStrings(i), &quot;[&quot;), sQuote)
1881 vSubStrings(i) = Join(Split(vSubStrings(i), &quot;]&quot;), sQuote)
1882 End If
1883 Next i
1885 _ReplaceSquareBrackets = Trim(Join(vSubStrings, cstSingleQuote))
1887 End Function &apos; ReplaceSquareBrackets V1.1.0
1889 </script:module>