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=
"Utils" 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 =======================================================================================================================
11 Global _A2B_ As Variant
13 REM -----------------------------------------------------------------------------------------------------------------------
14 REM --- PRIVATE FUNCTIONS ---
15 REM -----------------------------------------------------------------------------------------------------------------------
17 Public Function _AddArray(ByVal pvArray As Variant, pvItem As Variant) As Variant
18 'Add the item at the end of the array
20 Dim vArray() As Variant
21 If IsArray(pvArray) Then vArray = pvArray Else vArray = Array()
22 ReDim Preserve vArray(LBound(vArray) To UBound(vArray) +
1)
23 vArray(UBound(vArray)) = pvItem
24 _AddArray() = vArray()
28 REM -----------------------------------------------------------------------------------------------------------------------
29 Public Function _AddNumeric(ByVal Optional pvTypes As Variant) As Variant
30 'Return on top of argument the list of all numeric types
31 'Facilitates the entry of the list of allowed types in _CheckArgument calls
33 Dim i As Integer, vNewList() As Variant, vNumeric() As Variant, iSize As Integer
34 If IsMissing(pvTypes) Then
36 ElseIf IsArray(pvTypes) Then
39 vNewList = Array(pvTypes)
42 vNumeric = Array(vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbBigint, vbDecimal, vbBoolean)
44 iSize = UBound(vNewlist)
45 ReDim Preserve vNewList(iSize + UBound(vNumeric) +
1)
46 For i =
0 To UBound(vNumeric)
47 vNewList(iSize + i +
1) = vNumeric(i)
50 _AddNumeric = vNewList
52 End Function
' _AddNumeric V0.8
.0
54 REM -----------------------------------------------------------------------------------------------------------------------
56 Public Function _BitShift(piValue As Integer, piConstant As Integer) As Boolean
59 If piValue =
0 Then Exit Function
60 Select Case piConstant
63 Case
1,
3,
5,
7,
9,
11,
13,
15: _BitShift = True
68 Case
2,
3,
6,
7,
10,
11,
14,
15: _BitShift = True
73 Case
4,
5,
6,
7,
12,
13,
14,
15: _BitShift = True
78 Case
8,
9,
10,
11,
12,
13,
14,
15: _BitShift = True
83 End Function
' BitShift
85 REM -----------------------------------------------------------------------------------------------------------------------
86 Public Function _CalledSub() As String
87 _CalledSub = Iif(_A2B_.CalledSub =
"",
"", _GetLabel(
"CALLTO
")
& " '" & _A2B_.CalledSub
& "'")
88 End Function
' CalledSub V0.8
.9
91 REM -----------------------------------------------------------------------------------------------------------------------
92 Public Function _CheckArgument(pvItem As Variant _
93 , ByVal piArgNr As Integer _
94 , ByVal pvType As Variant _
95 , ByVal Optional pvValid As Variant _
96 , ByVal Optional pvError As Boolean _
98 ' Called by public functions to check the validity of their arguments
99 ' pvItem Argument to be checked
100 ' piArgNr Argument sequence number
101 ' pvType Single value or array of allowed variable types
102 ' If of string type must contain one or more valid pseudo-object types
103 ' pvValid Single value or array of allowed values - comparison for strings is case-insensitive
104 ' pvError If True (default), error handling in this routine. False in _setProperty methods in class modules.
106 _CheckArgument = False
108 Dim iVarType As Integer, bValidIsMissing As Boolean
109 If IsArray(pvType) Then iVarType = VarType(pvType(LBound(pvType))) Else iVarType = VarType(pvType)
110 If iVarType = vbString Then
' pvType is a pseudo-type string
111 _CheckArgument = Utils._IsPseudo(pvItem, pvType)
113 bValidIsMissing = ( VarType(pvValid) = vbError )
114 If Not bValidIsMissing Then bValidIsMissing = IsMissing(pvValid)
115 If bValidIsMissing Then _CheckArgument = Utils._IsScalar(pvItem, pvType) Else _CheckArgument = Utils._IsScalar(pvItem, pvType, pvValid)
118 If VarType(pvItem) = vbCurrency Or VarType(pvItem) = vbDecimal Or VarType(pvItem) = vbBigint Then pvItem = CDbl(pvItem)
121 If Not _CheckArgument Then
122 If IsMissing(pvError) Then pvError = True
124 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0,
1, Array(piArgNr, pvItem))
128 End Function
' CheckArgument V0.9
.0
130 REM -----------------------------------------------------------------------------------------------------------------------
131 Public Function _CStr(ByVal pvArg As Variant, ByVal Optional pbShort As Boolean) As String
132 ' Convert pvArg into a readable string (truncated if too long and pbShort = True or missing)
133 ' pvArg may be a byte-array. Other arrays are processed recursively into a semicolon separated string
135 Dim sArg As String, sObject As String, oArg As Object, sLength As String, i As Long, iMax As Long
137 Const cstByteLength =
25
139 If IsMissing(pbShort) Then pbShort = True
140 If IsArray(pvArg) Then
142 If VarType(pvArg) = vbByte Or VarType(pvArg) = vbArray + vbByte Then
143 If pbShort And UBound(pvArg)
> cstByteLength Then iMax = cstByteLength Else iMax = UBound(pvArg)
145 sArg = sArg
& Right(
"00" & Hex(pvArg(i)),
2)
149 sArg =
"[ARRAY]
"
150 Else
' One-dimension arrays only
151 For i = LBound(pvArg) To UBound(pvArg)
152 sArg = sArg
& Utils._CStr(pvArg(i), pbShort)
& ";
" ' Recursive call
154 If Len(sArg)
> 1 Then sArg = Left(sArg, Len(sArg) -
1)
158 Select Case VarType(pvArg)
159 Case vbEmpty : sArg =
"[EMPTY]
"
160 Case vbNull : sArg =
"[NULL]
"
162 If IsNull(pvArg) Then
163 sArg =
"[NULL]
"
165 sObject = Utils._ImplementationName(pvArg)
166 If Utils._IsPseudo(pvArg, Array(OBJDATABASE, OBJCOLLECTION, OBJPROPERTY, OBJFORM, OBJSUBFORM, OBJCONTROL, OBJOPTIONGROUP _
167 , OBJEVENT, OBJFIELD, OBJTABLEDEF, OBJQUERYDEF, OBJRECORDSET, OBJTEMPVAR, OBJCOMMANDBAR, OBJCOMMANDBARCONTROL _
170 Set oArg = pvArg
' To avoid
"Object variable not set
" error message
171 sArg =
"[
" & oArg._Type
& "]
" & oArg._Name
172 ElseIf sObject
<> "" Then
173 sArg =
"[
" & sObject
& "]
"
175 sArg =
"[OBJECT]
"
178 Case vbVariant : sArg =
"[VARIANT]
"
180 ' Replace CR + LF by \n and HT by \t
181 ' Replace semicolon by \; to allow semicolon separated rows
186 Replace(pvArg,
"\
",
"\\
") _
187 , Chr(
13),
"") _
188 , Chr(
10),
"\n
") _
189 , Chr(
9),
"\t
") _
190 ,
";
",
"\;
")
191 Case vbBoolean : sArg = Iif(pvArg,
"[TRUE]
",
"[FALSE]
")
192 Case vbByte : sArg = Right(
"00" & Hex(pvArg),
2)
193 Case vbSingle, vbDouble, vbCurrency
195 If InStr(UCase(sArg),
"E
") =
0 Then sArg = Format(pvArg,
"##
0.0##
")
196 sArg = Replace(sArg,
",
",
".
")
197 Case vbBigint : sArg = CStr(CLng(pvArg))
198 Case vbDate : sArg = Year(pvArg)
& "-
" & Right(
"0" & Month(pvArg),
2)
& "-
" & Right(
"0" & Day(pvArg),
2) _
199 & " " & Right(
"0" & Hour(pvArg),
2)
& ":
" & Right(
"0" & Minute(pvArg),
2) _
200 & ":
" & Right(
"0" & Second(pvArg),
2)
201 Case Else : sArg = CStr(pvArg)
204 If pbShort And Len(sArg)
> cstLength Then
205 sLength =
"(
" & Len(sArg)
& ")
"
206 sArg = Left(sArg, cstLength -
5 - Len(slength))
& " ...
" & sLength
210 End Function
' CStr V0.9
.5
212 REM -----------------------------------------------------------------------------------------------------------------------
213 Public Function _CVar(ByRef psArg As String, ByVal Optional pbStrDate As Boolean) As Variant
214 ' psArg is presumed an output of _CStr (stored in the meantime in a text file f.i.)
215 ' _CVar returns the corresponding original Variant variable or Null/Nothing if not possible
216 ' Return values may of types Array, Long, Double, Date, Boolean, String, Null or Empty
217 ' pbStrDate = True keeps dates as strings
219 Dim cstEscape1 As String, cstEscape2 As String
220 cstEscape1 = Chr(
14)
' Form feed used as temporary escape character for \\
221 cstEscape2 = Chr(
27)
' ESC used as temporary escape character for \;
224 If Len(psArg) =
0 Then Exit Function
226 Dim sArg As String, vArgs() As Variant, vVars() As Variant, i As Integer
227 If IsMissing(pbStrDate) Then pbStrDate = False
231 Replace(psArg,
"\\
", cstEscape1) _
232 ,
"\;
", cstEscape2) _
233 ,
"\n
", Chr(
10)) _
234 ,
"\t
", Chr(
9))
236 ' Semicolon separated string
237 vArgs = Split(sArg,
";
")
238 If UBound(vArgs)
> LBound(vArgs) Then
' Process each item recursively
240 Redim vVars(LBound(vArgs) To UBound(vArgs))
241 For i = LBound(vVars) To UBound(vVars)
242 vVars(i) = _CVar(vArgs(i), pbStrDate)
250 Case sArg =
"[EMPTY]
" : _CVar = EMPTY
251 Case sArg =
"[NULL]
" Or sArg =
"[VARIANT]
" : _CVar = Null
252 Case sArg =
"[OBJECT]
" : _CVar = Nothing
253 Case sArg =
"[TRUE]
" : _CVar = True
254 Case sArg =
"[FALSE]
" : _CVar = False
256 If pbStrDate Then _CVar = sArg Else _CVar = CDate(sArg)
258 If InStr(sArg,
".
")
> 0 Then
261 _CVar = CLng(Val(sArg))
' Val always returns a double
263 Case _RegexSearch(sArg,
"^[-+]?[
0-
9]*\.?[
0-
9]+(e[-+]?[
0-
9]+)?$
")
<> ""
264 _CVar = Val(sArg)
' Scientific notation
265 Case Else : _CVar = Replace(Replace(sArg, cstEscape1,
"\
"), cstEscape2,
";
")
268 End Function
' CVar V1.7
.0
270 REM -----------------------------------------------------------------------------------------------------------------------
271 Public Function _DecimalPoint() As String
272 'Return locale decimal point
273 _DecimalPoint = Mid(Format(
0,
"0.0"),
2,
1)
276 REM -----------------------------------------------------------------------------------------------------------------------
277 Private Function _ExtensionLocation() As String
278 ' Return the URL pointing to the location where OO installed the Access2Base extension
279 ' Adapted from https://wiki.documentfoundation.org/Documentation/DevGuide/Extensions#Location_of_Installed_Extensions
281 Dim oPip As Object, sLocation As String
282 Set oPip = GetDefaultContext.getByName(
"/singletons/com.sun.star.deployment.PackageInformationProvider
")
283 _ExtensionLocation = oPip.getPackageLocation(
"Access2Base
")
285 End Function
' ExtensionLocation
287 REM -----------------------------------------------------------------------------------------------------------------------
288 Private Function _GetDialogLib() As Object
289 ' Return actual Access2Base dialogs library
291 Dim oDialogLib As Object
293 Set oDialogLib = DialogLibraries
294 If oDialogLib.hasByName(
"Access2BaseDev
") Then
295 If Not oDialogLib.IsLibraryLoaded(
"Access2BaseDev
") Then oDialogLib.loadLibrary(
"Access2BaseDev
")
296 Set _GetDialogLib = DialogLibraries.Access2BaseDev
297 ElseIf oDialogLib.hasByName(
"Access2Base
") Then
298 If Not oDialogLib.IsLibraryLoaded(
"Access2Base
") Then oDialogLib.loadLibrary(
"Access2Base
")
299 Set _GetDialogLib = DialogLibraries.Access2Base
301 Set _GetDialogLib = Nothing
306 REM -----------------------------------------------------------------------------------------------------------------------
307 Public Function _GetEventName(ByVal psProperty As String) As String
308 ' Return the LO internal event name
309 ' Corrects the typo on ErrorOccur(r?)ed
311 _GetEventName = Replace(LCase(Mid(psProperty,
3,
1))
& Right(psProperty, Len(psProperty) -
3),
"errorOccurred
",
"errorOccured
")
313 End Function
' _GetEventName V1.7
.0
315 REM -----------------------------------------------------------------------------------------------------------------------
316 Public Function _GetEventScriptCode(poObject As Object _
317 , ByVal psEvent As String _
318 , ByVal psName As String _
319 , Optional ByVal pbExtendName As Boolean _
321 ' Extract from the parent of poObject the macro linked to psEvent.
322 ' psName is the name of the object
324 Dim i As Integer, vEvents As Variant, sEvent As String, oParent As Object, iIndex As Integer, sName As String
326 _GetEventScriptCode =
""
327 If Not Utils._hasUNOMethod(poObject,
"getParent
") Then Exit Function
329 ' Find form index i.e. find control via getByIndex()
330 If IsMissing(pbExtendName) Then pbExtendName = False
331 Set oParent = poObject.getParent()
333 For i =
0 To oParent.getCount() -
1
334 sName = oParent.getByIndex(i).Name
335 If (sName = psName) Or (pbExtendName And (sName =
"MainForm
" Or sName =
"Form
")) Then
340 If iIndex
< 0 Then Exit Function
342 ' Find script event
343 vEvents = oParent.getScriptEvents(iIndex)
' Returns an array
344 sEvent = Utils._GetEventName(psEvent)
' Targeted event method
345 For i =
0 To UBound(vEvents)
346 If vEvents(i).EventMethod = sEvent Then
347 _GetEventScriptCode = vEvents(i).ScriptCode
352 End Function
' _GetEventScriptCode V1.7
.0
354 REM -----------------------------------------------------------------------------------------------------------------------
355 Private Function _GetResultSetColumnValue(poResultSet As Object _
356 , ByVal piColIndex As Integer _
357 , Optional ByVal pbReturnBinary As Boolean _
359 REM Modified from Roberto Benitez
's BaseTools
360 REM get the data for the column specified by ColIndex
361 REM If pbReturnBinary = False (default) then return length of binary field
362 REM get type name from metadata
364 Dim vValue As Variant, iType As Integer, vDateTime As Variant, oValue As Object
365 Dim bNullable As Boolean, lSize As Long
366 Const cstMaxTextLength =
65535
367 Const cstMaxBinlength =
2 *
65535
369 On Local Error Goto
0 ' Disable error handler
370 vValue = Null
' Default value if error
371 If IsMissing(pbReturnBinary) Then pbReturnBinary = False
372 With com.sun.star.sdbc.DataType
373 iType = poResultSet.MetaData.getColumnType(piColIndex)
374 bNullable = ( poResultSet.MetaData.IsNullable(piColIndex) = com.sun.star.sdbc.ColumnValue.NULLABLE )
376 Case .ARRAY : vValue = poResultSet.getArray(piColIndex)
377 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
378 Set oValue = poResultSet.getBinaryStream(piColIndex)
380 If Not poResultSet.wasNull() Then
381 If Not _hasUNOMethod(oValue,
"getLength
") Then
' When no recordset
382 lSize = cstMaxBinLength
384 lSize = CLng(oValue.getLength())
386 If lSize
<= cstMaxBinLength And pbReturnBinary Then
388 oValue.readBytes(vValue, lSize)
389 Else
' Return length of field, not content
395 Case .BIT, .BOOLEAN : vValue = poResultSet.getBoolean(piColIndex)
396 Case .DATE : vDateTime = poResultSet.getDate(piColIndex)
397 If Not poResultSet.wasNull() Then vValue = DateSerial(CInt(vDateTime.Year), CInt(vDateTime.Month), CInt(vDateTime.Day))
398 Case .DISTINCT, .OBJECT, .OTHER, .STRUCT
400 Case .DOUBLE, .REAL : vValue = poResultSet.getDouble(piColIndex)
401 Case .FLOAT : vValue = poResultSet.getFloat(piColIndex)
402 Case .INTEGER, .SMALLINT : vValue = poResultSet.getInt(piColIndex)
403 Case .BIGINT : vValue = poResultSet.getLong(piColIndex)
404 Case .DECIMAL, .NUMERIC : vValue = poResultSet.getDouble(piColIndex)
405 Case .SQLNULL : vValue = poResultSet.getNull(piColIndex)
406 Case .OBJECT, .OTHER, .STRUCT : vValue = Null
407 Case .REF : vValue = poResultSet.getRef(piColIndex)
408 Case .TINYINT : vValue = poResultSet.getShort(piColIndex)
409 Case .CHAR, .VARCHAR : vValue = poResultSet.getString(piColIndex)
410 Case .LONGVARCHAR, .CLOB
411 Set oValue = poResultSet.getCharacterStream(piColIndex)
413 If Not poResultSet.wasNull() Then
414 If Not _hasUNOMethod(oValue,
"getLength
") Then
' When no recordset
415 lSize = cstMaxTextLength
417 lSize = CLng(oValue.getLength())
420 vValue = poResultSet.getString(piColIndex)
425 Case .TIME : vDateTime = poResultSet.getTime(piColIndex)
426 If Not poResultSet.wasNull() Then vValue = TimeSerial(vDateTime.Hours, vDateTime.Minutes, vDateTime.Seconds)
', vDateTime.HundredthSeconds)
427 Case .TIMESTAMP : vDateTime = poResultSet.getTimeStamp(piColIndex)
428 If Not poResultSet.wasNull() Then vValue = DateSerial(CInt(vDateTime.Year), CInt(vDateTime.Month), CInt(vDateTime.Day)) _
429 + TimeSerial(vDateTime.Hours, vDateTime.Minutes, vDateTime.Seconds)
', vDateTime.HundredthSeconds)
431 vValue = poResultSet.getString(piColIndex)
'GIVE STRING A TRY
432 If IsNumeric(vValue) Then vValue = Val(vValue)
'Required when type =
"", sometimes numeric fields are returned as strings (query/MSAccess)
435 If poResultSet.wasNull() Then vValue = Null
439 _GetResultSetColumnValue = vValue
441 End Function
' GetResultSetColumnValue V
1.5.0
443 REM -----------------------------------------------------------------------------------------------------------------------
444 Public Function _FinalProperty(psShortcut As String) As String
445 ' Return the final property of a shortcut
447 Const cstEXCLAMATION =
"!
"
448 Const cstDOT =
".
"
450 Dim iCurrentIndex As Integer, vCurrentObject As Variant, sCurrentProperty As String
451 Dim sComponents() As String, sSubComponents() As String
452 _FinalProperty =
""
453 sComponents = Split(Trim(psShortcut), cstEXCLAMATION)
454 If UBound(sComponents) =
0 Then Exit Function
455 sSubComponents = Split(sComponents(UBound(sComponents)), cstDOT)
456 Select Case UBound(sSubComponents)
458 _FinalProperty = sSubComponents(
1)
463 End Function
' FinalProperty
465 REM -----------------------------------------------------------------------------------------------------------------------
466 Public Function _GetProductName(ByVal Optional psFlag As String) as String
467 'Return OO product (
"PRODUCT
") and version numbers (
"VERSION
")
468 'Derived from Tools library
470 Dim oProdNameAccess as Object
471 Dim sVersion as String
472 Dim sProdName as String
473 If IsMissing(psFlag) Then psFlag =
"ALL
"
474 oProdNameAccess = _GetRegistryKeyContent(
"org.openoffice.Setup/Product
")
475 sProdName = oProdNameAccess.getByName(
"ooName
")
476 sVersion = oProdNameAccess.getByName(
"ooSetupVersionAboutBox
")
478 Case
"ALL
" : _GetProductName = sProdName
& " " & sVersion
479 Case
"PRODUCT
" : _GetProductName = sProdName
480 Case
"VERSION
" : _GetProductName = sVersion
482 End Function
' GetProductName V1.0
.0
484 REM -----------------------------------------------------------------------------------------------------------------------
485 Public Function _GetRandomFileName(ByVal psName As String) As String
486 ' Return the full name of a random temporary file suffixed by psName
488 Dim sRandom As String
489 sRandom = Right(
"000000" & Int(
999999 * Rnd),
6)
490 _GetRandomFileName = Utils._getTempDirectoryURL()
& "/
" & "A2B_TEMP_
" & psName
& "_
" & sRandom
492 End Function
' GetRandomFileName
494 REM -----------------------------------------------------------------------------------------------------------------------
495 Public Function _GetRegistryKeyContent(sKeyName as string, Optional bforUpdate as Boolean) As Variant
496 'Implement ConfigurationProvider service
497 'Derived from Tools library
499 Dim oConfigProvider as Object
500 Dim aNodePath(
0) as new com.sun.star.beans.PropertyValue
501 oConfigProvider = createUnoService(
"com.sun.star.configuration.ConfigurationProvider
")
502 aNodePath(
0).Name =
"nodepath
"
503 aNodePath(
0).Value = sKeyName
504 If IsMissing(bForUpdate) Then bForUpdate = False
506 _GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationUpdateAccess
", aNodePath())
508 _GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess
", aNodePath())
510 End Function
' GetRegistryKeyContent V0.8
.5
512 REM -----------------------------------------------------------------------------------------------------------------------
513 Public Function _getTempDirectoryURL() As String
514 ' Return the temporary directory defined in the OO Options (Paths)
515 Dim sDirectory As String, oSettings As Object, oPathSettings As Object
517 If _ErrorHandler() Then On Local Error Goto Error_Function
519 _getTempDirectoryURL =
""
520 oPathSettings = createUnoService(
"com.sun.star.util.PathSettings
" )
521 sDirectory = oPathSettings.GetPropertyValue(
"Temp
" )
523 _getTempDirectoryURL = sDirectory
528 TraceError(
"ERROR
", Err,
"_getTempDirectoryURL
", Erl)
529 _getTempDirectoryURL =
""
531 End Function
' _getTempDirectoryURL V0.8
.5
533 REM -----------------------------------------------------------------------------------------------------------------------
534 Public Function _getUNOTypeName(pvObject As Variant) As String
535 ' Return the symbolic name of the pvObject (UNO-object) type
536 ' Code-snippet from XRAY
538 Dim oService As Object, vClass as Variant
539 _getUNOTypeName =
""
540 On Local Error Resume Next
541 oService = CreateUnoService(
"com.sun.star.reflection.CoreReflection
")
542 vClass = oService.getType(pvObject)
543 If vClass.TypeClass = com.sun.star.uno.TypeClass.STRUCT Then
544 _getUNOTypeName = vClass.Name
548 End Function
' getUNOTypeName
550 REM -----------------------------------------------------------------------------------------------------------------------
551 Public Function _hasUNOMethod(pvObject As Variant, psMethod As String) As Boolean
552 ' Return true if pvObject has the (UNO) method psMethod
553 ' Code-snippet found in Bernard Marcelly
's XRAY
555 Dim vInspect as Variant
556 _hasUNOMethod = False
557 If IsNull(pvObject) Then Exit Function
558 On Local Error Resume Next
559 vInspect = _A2B_.Introspection.Inspect(pvObject)
560 _hasUNOMethod = vInspect.hasMethod(psMethod, com.sun.star.beans.MethodConcept.ALL)
562 End Function
' hasUNOMethod V0.8
.0
564 REM -----------------------------------------------------------------------------------------------------------------------
565 Public Function _hasUNOProperty(pvObject As Variant, psProperty As String) As Boolean
566 ' Return true if pvObject has the (UNO) property psProperty
567 ' Code-snippet found in Bernard Marcelly
's XRAY
569 Dim vInspect as Variant
570 _hasUNOProperty = False
571 If IsNull(pvObject) Then Exit Function
572 On Local Error Resume Next
573 vInspect = _A2B_.Introspection.Inspect(pvObject)
574 _hasUNOProperty = vInspect.hasProperty(psProperty, com.sun.star.beans.PropertyConcept.ALL)
576 End Function
' hasUNOProperty V0.8
.0
578 REM -----------------------------------------------------------------------------------------------------------------------
579 Public Function _ImplementationName(pvObject As Variant) As String
580 ' Use getImplementationName method or _getUNOTypeName function
582 Dim sObjectType As String
583 On Local Error Resume Next
584 sObjectType = pvObject.getImplementationName()
585 If sObjectType =
"" Then sObjectType = _getUNOTypeName(pvObject)
587 _ImplementationName = sObjectType
589 End Function
' ImplementationName
591 REM -----------------------------------------------------------------------------------------------------------------------
592 Public Function _InList(ByVal pvItem As Variant, pvList As Variant, ByVal Optional pvReturnValue As Variant, Optional ByVal pbBinarySearch As Boolean) As Variant
593 ' Return True if pvItem is present in the pvList array (case insensitive comparison)
594 ' Return the value in pvList if pvReturnValue = True
596 Dim i As Integer, bFound As Boolean, iListVarType As Integer, iItemVarType As Integer
597 Dim iTop As Integer, iBottom As Integer, iFound As Integer
598 iItemVarType = VarType(pvItem)
599 If IsMissing(pvReturnValue) Then pvReturnValue = False
600 If iItemVarType = vbNull Or IsNull(pvList) Then
602 ElseIf Not IsArray(pvList) Then
603 If iItemVarType = vbString Then bFound = ( UCase(pvItem) = UCase(pvList) ) Else bFound = ( pvItem = pvList )
604 If Not pvReturnValue Then
607 If bFound Then _InList = pvList Else _InList = False
609 ElseIf UBound(pvList)
< LBound(pvList) Then
' Array not initialized
614 iListVarType = VarType(pvList(LBound(pvList)))
615 If iListVarType = iItemVarType _
616 Or ( (iListVarType = vbInteger Or iListVarType = vbLong Or iListVarType = vbSingle Or iListVarType = vbDouble _
617 Or iListVarType = vbCurrency Or iListVarType = vbBigint Or iListVarType = vbDecimal) _
618 And (iItemVarType = vbInteger Or iItemVarType = vbLong Or iItemVarType = vbSingle Or iItemVarType = vbDouble _
619 Or iItemVarType = vbCurrency Or iItemVarType = vbBigint Or iItemVarType = vbDecimal) _
621 If IsMissing(pbBinarySearch) Then pbBinarySearch = False
622 If Not pbBinarySearch Then
' Linear search
623 For i = LBound(pvList) To UBound(pvList)
624 If iItemVarType = vbString Then bFound = ( UCase(pvItem) = UCase(pvList(i)) ) Else bFound = ( pvItem = pvList(i) )
630 Else
' Binary search =
> array must be sorted
631 iTop = UBound(pvList)
632 iBottom = lBound(pvList)
634 iFound = (iTop + iBottom) /
2
635 If ( iItemVarType = vbString And UCase(pvItem)
> UCase(pvList(iFound)) ) Or ( iItemVarType
<> vbString And pvItem
> pvList(iFound) ) Then
640 If iItemVarType = vbString Then bFound = ( UCase(pvItem) = UCase(pvList(iFound)) ) Else bFound = ( pvItem = pvList(iFound) )
641 Loop Until ( bFound ) Or ( iBottom
> iTop )
644 If Not pvReturnValue Then _InList = True Else _InList = pvList(iFound)
651 End Function
' InList V1.1
.0
653 REM -----------------------------------------------------------------------------------------------------------------------
654 Public Function _InspectPropertyType(poObject As Object, psProperty As String) As String
655 'Return type of property EVEN WHEN EMPTY ! (Used in date and time controls)
657 Dim oInspect1 As Object, oInspect2 As Object, oInspect3 As Object
658 ' On Local Error Resume Next
659 _InspectPropertyType =
""
660 Set oInspect1 = CreateUnoService(
"com.sun.star.script.Invocation
")
661 Set oInspect2 = oInspect1.createInstanceWithArguments(Array(poObject)).IntroSpection
662 If Not IsNull(oInspect2) Then
663 Set oInspect3 = oInspect2.getProperty(psProperty, com.sun.star.beans.PropertyConcept.ALL)
664 If Not IsNull(oInspect3) Then _InspectPropertyType = oInspect3.Type.Name
666 Set oInspect1 = Nothing : Set oInspect2 = Nothing : Set oInspect3 = Nothing
668 End Function
' InspectPropertyType V1.0
.0
670 REM -----------------------------------------------------------------------------------------------------------------------
671 Public Function _IsLeft(psString As String, psLeft As String) As Boolean
672 ' Return True if left part of psString = psLeft
674 Dim iLength As Integer
675 iLength = Len(psLeft)
677 If Len(psString)
>= iLength Then
678 If Left(psString, iLength) = psLeft Then _IsLeft = True
683 REM -----------------------------------------------------------------------------------------------------------------------
684 Public Function _IsBinaryType(ByVal lType As Long) As Boolean
686 With com.sun.star.sdbc.DataType
688 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
691 _IsBinaryType = False
695 End Function
' IsBinaryType V1.6
.0
697 REM -----------------------------------------------------------------------------------------------------------------------
698 Public Function _IsPseudo(pvObject As Variant, ByVal pvType As Variant) As Boolean
699 ' Test pvObject: does it exist ?
700 ' is the _Type item = one of the proposed pvTypes ?
701 ' does the pseudo-object refer to an existing object (e.g. does the form really exist in the db) ?
703 Dim bIsPseudo As Boolean, bPseudoExists As Boolean, vObject As Variant
705 If _ErrorHandler() Then On Local Error Goto Exit_False
709 vObject = pvObject
' To avoid
"Object variable not set
" error message
711 Case IsEmpty(vObject)
713 Case VarType(vObject)
<> vbObject
719 Case ._Type =
""
721 bIsPseudo = _InList(._Type, pvType)
722 If Not bIsPseudo Then
' If primary type did not succeed, give the subtype a chance
723 If ._Type = OBJCONTROL Then bIsPseudo = _InList(._SubType, pvType)
729 If Not bIsPseudo Then Goto Exit_Function
731 Dim oDoc As Object, oForms As Variant
732 Const cstSeparator =
"\;
"
734 bPseudoExists = False
738 If ._Name
<> "" Then
' Check validity of form name
739 Set oDoc = _A2B_.CurrentDocument()
740 If oDoc.DbConnect = DBCONNECTFORM Then bPseudoExists = True Else bPseudoExists = _InList(._Name, Application._GetAllHierarchicalNames())
743 If ._DbConnect = DBCONNECTFORM Then bPseudoExists = True Else bPseudoExists = Not IsNull(.Connection)
745 If ._Name
<> "" Then
' Check validity of dialog name
746 bPseudoExists = ( _A2B_.hasItem(COLLALLDIALOGS, ._Name) )
751 If Not IsNull(.ControlModel) And ._Name
<> "" Then
' Check validity of control
752 Set oForms = .ControlModel.Parent
753 bPseudoExists = ( oForms.hasByName(._Name) )
756 If Not IsNull(.DatabaseForm) And ._Name
<> "" Then
' Check validity of subform
757 If .DatabaseForm.ImplementationName =
"com.sun.star.comp.forms.ODatabaseForm
" Then
758 Set oForms = .DatabaseForm.Parent
759 bPseudoExists = ( oForms.hasByName(._Name) )
763 bPseudoExists = ( .Count
> 0 )
765 bPseudoExists = ( Not IsNull(._Window) )
766 Case OBJCOMMANDBARCONTROL
767 bPseudoExists = ( Not IsNull(._ParentCommandBar) )
769 bPseudoExists = ( Not IsNull(._EventSource) )
771 bPseudoExists = ( ._Name
<> "" )
773 bPseudoExists = ( ._Name
<> "" And Not IsNull(.Table) )
775 bPseudoExists = ( ._Name
<> "" And Not IsNull(.Query) )
777 bPseudoExists = ( Not IsNull(.RowSet) )
779 bPseudoExists = ( ._Name
<> "" And Not IsNull(.Column) )
781 If ._Name
<> "" Then
' Check validity of tempvar name
782 bPseudoExists = ( _A2B_.hasItem(COLLTEMPVARS, ._Name) )
788 _IsPseudo = ( bIsPseudo And bPseudoExists )
795 End Function
' IsPseudo V1.1
.0
797 REM -----------------------------------------------------------------------------------------------------------------------
798 Private Function _IsScalar(ByVal pvArg As Variant, ByVal pvType As Variant, ByVal Optional pvValid As Variant) As Boolean
799 ' Check type of pvArg and value in allowed pvValid list
803 If IsArray(pvType) Then
804 If Not _InList(VarType(pvArg), pvType) Then Exit Function
805 ElseIf VarType(pvArg)
<> pvType Then
806 If pvType = vbBoolean And VarType(pvArg) = vbLong Then
807 If pvArg
< -
1 And pvArg
> 0 Then Exit Function
' Special boolean processing because the Not function returns a Long
812 If Not IsMissing(pvValid) Then
813 If Not _InList(pvArg, pvValid) Then Exit Function
820 End Function
' IsScalar V0.7
.5
822 REM -----------------------------------------------------------------------------------------------------------------------
823 Public Function _PCase(ByVal psString As String) As String
824 ' Return the proper case representation of argument
826 Dim vSubStrings() As Variant, i As Integer, iLen As Integer
827 vSubStrings = Split(psString,
" ")
828 For i =
0 To UBound(vSubStrings)
829 iLen = Len(vSubStrings(i))
831 vSubStrings(i) = UCase(Left(vSubStrings(i),
1))
& LCase(Right(vSubStrings(i), iLen -
1))
833 vSubStrings(i) = UCase(vSubStrings(i))
836 _PCase = Join(vSubStrings,
" ")
838 End Function
' PCase V0.9
.0
840 REM -----------------------------------------------------------------------------------------------------------------------
841 Private Function _PercentEncode(ByVal psChar As String) As String
842 ' Percent encoding of single psChar character
843 ' https://en.wikipedia.org/wiki/UTF-
8
845 Dim lChar As Long, sByte1 As String, sByte2 As String, sByte3 As String
849 Case
48 To
57,
65 To
90,
97 To
122 ' 0-
9, A-Z, a-z
850 _PercentEncode = psChar
851 Case Asc(
"-
"), Asc(
".
"), Asc(
"_
"), Asc(
"~
")
852 _PercentEncode = psChar
853 Case Asc(
"!
"), Asc(
"$
"), Asc(
"&"), Asc(
"'"), Asc(
"(
"), Asc(
")
"), Asc(
"*
"), Asc(
"+
"), Asc(
",
"), Asc(
";
"), Asc(
"=
")
' Reserved characters used as delimiters in query strings
854 _PercentEncode = psChar
855 Case Asc(
" "), Asc(
"%
")
856 _PercentEncode =
"%
" & Right(
"00" & Hex(lChar),
2)
858 _PercentEncode = psChar
860 sByte1 =
"%
" & Right(
"00" & Hex(Int(lChar /
64) +
192),
2)
861 sByte2 =
"%
" & Right(
"00" & Hex((lChar Mod
64) +
128),
2)
862 _PercentEncode = sByte1
& sByte2
864 sByte1 =
"%
" & Right(
"00" & Hex(Int(lChar /
4096) +
224),
2)
865 sByte2 =
"%
" & Right(
"00" & Hex(Int(lChar - (
4096 * Int(lChar /
4096))) /
64 +
128),
2)
866 sByte3 =
"%
" & Right(
"00" & Hex((lChar Mod
64) +
128),
2)
867 _PercentEncode = sByte1
& sByte2
& sByte3
868 Case Else
' Not supported
869 _PercentEncode = psChar
874 End Function
' _PercentEncode V1.4
.0
876 REM -----------------------------------------------------------------------------------------------------------------------
877 Public Function _ReadFileIntoArray(ByVal psFileName) As Variant
878 ' Loads all lines of a text file into a Variant array
879 ' Any error reduces output to an empty array
880 ' Input file name presumed in URL form
882 Dim vLines() As Variant, iFile As Integer, sLine As String, iCount1 As Integer, iCount2 As Integer
883 Const cstMaxLines =
16000 ' +/- the limit of array sizes in Basic
884 On Local Error GoTo Error_Function
886 _ReadFileIntoArray = Array()
887 If psFileName =
"" Then Exit Function
890 Open psFileName For Input Access Read Shared As #iFile
892 Do While Not Eof(iFile) And iCount1
< cstMaxLines
893 Line Input #iFile, sLine
894 iCount1 = iCount1 +
1
898 ReDim vLines(
0 To iCount1 -
1)
' Reading file twice preferred to ReDim Preserve for performance reasons
900 Open psFileName For Input Access Read Shared As #iFile
902 Do While Not Eof(iFile) And iCount2
< iCount1
903 Line Input #iFile, vLines(iCount2)
904 iCount2 = iCount2 +
1
909 _ReadFileIntoArray() = vLines()
914 End Function
' _ReadFileIntoArray V1.4
.0
916 REM -----------------------------------------------------------------------------------------------------------------------
917 Public Function _RegexSearch(ByRef psString As String _
918 , ByVal psRegex As String _
919 , Optional ByRef plStart As Long _
920 , Optional ByVal bForward As Boolean _
922 ' Search is not case-sensitive
923 ' Return
"" if regex not found, otherwise returns the matching string
924 ' plStart = start position of psString to search (starts at
1)
925 ' In output plStart contains the first position of the matching string
926 ' To search again the same or another pattern =
> plStart = plStart + Len(matching string)
928 Dim oTextSearch As Object
929 Dim vOptions As Variant
'com.sun.star.util.SearchOptions
930 Dim lEnd As Long, vResult As Object
932 _RegexSearch =
""
933 Set oTextSearch = _A2B_.TextSearch
' UNO XTextSearch service
934 vOptions = _A2B_.SearchOptions
935 vOptions.searchString = psRegex
' Pattern to be searched
936 oTextSearch.setOptions(vOptions)
937 If IsMissing(plStart) Then plStart =
1
938 If plStart
<=
0 Or plStart
> Len(psString) Then Exit Function
939 If IsMissing(bForWard) Then bForward = True
942 vResult = oTextSearch.searchForward(psString, plStart -
1, lEnd)
945 vResult = oTextSearch.searchForward(psString, plStart, lEnd -
1)
948 If .subRegExpressions
>=
1 Then
949 ' http://www.openoffice.org/api/docs/common/ref/com/sun/star/util/SearchResult.html
952 plStart = .startOffset(
0) +
1
953 lEnd = .endOffset(
0) +
1
955 plStart = .endOffset(
0) +
1
956 lEnd = .startOffset(
0)
958 _RegexSearch = Mid(psString, plStart, lEnd - plStart)
966 REM -----------------------------------------------------------------------------------------------------------------------
967 Public Function _RegisterDialogEventScript(poObject As Object _
968 , ByVal psEvent As String _
969 , ByVal psListener As String _
970 , ByVal psScriptCode As String _
972 ' Register a script event (psEvent) to poObject (Dialog or dialog Control)
974 Dim oEvents As Object, sEvent As String, sEventName As String, oEvent As Object
976 _RegisterDialogEventScript = False
977 If Not _hasUNOMethod(poObject,
"getEvents
") Then Exit Function
979 ' Remove existing event, if any, then store new script code
980 Set oEvents = poObject.getEvents()
981 sEvent = Utils._GetEventName(psEvent)
982 sEventName =
"com.sun.star.awt.
" & psListener
& "::
" & sEvent
983 If oEvents.hasByName(sEventName) Then oEvents.removeByName(sEventName)
984 Set oEvent = CreateUnoStruct(
"com.sun.star.script.ScriptEventDescriptor
")
986 .ListenerType = psListener
987 .EventMethod = sEvent
988 .ScriptType =
"Script
" ' Better than
"Basic
"
989 .ScriptCode = psScriptCode
991 oEvents.insertByName(sEventName, oEvent)
993 _RegisterDialogEventScript = True
995 End Function
' _RegisterDialogEventScript V1.8
.0
997 REM -----------------------------------------------------------------------------------------------------------------------
998 Public Function _RegisterEventScript(poObject As Object _
999 , ByVal psEvent As String _
1000 , ByVal psListener As String _
1001 , ByVal psScriptCode As String _
1002 , ByVal psName As String _
1003 , Optional ByVal pbExtendName As Boolean _
1005 ' Register a script event (psEvent) to poObject (Form, SubForm or Control)
1007 Dim i As Integer, oEvent As Object, sEvent As String, oParent As Object, iIndex As Integer, sName As String
1009 _RegisterEventScript = False
1010 If Not _hasUNOMethod(poObject,
"getParent
") Then Exit Function
1012 ' Find object internal index i.e. how to reach it via getByIndex()
1013 If IsMissing(pbExtendName) Then pbExtendName = False
1014 Set oParent = poObject.getParent()
1016 For i =
0 To oParent.getCount() -
1
1017 sName = oParent.getByIndex(i).Name
1018 If (sName = psName) Or (pbExtendName And (sName =
"MainForm
" Or sName =
"Form
")) Then
1023 If iIndex
< 0 Then Exit Function
1025 sEvent = Utils._GetEventName(psEvent)
' Targeted event method
1026 If psScriptCode =
"" Then
1027 oParent.revokeScriptEvent(iIndex, psListener, sEvent,
"")
1029 Set oEvent = CreateUnoStruct(
"com.sun.star.script.ScriptEventDescriptor
")
1031 .ListenerType = psListener
1032 .EventMethod = sEvent
1033 .ScriptType =
"Script
" ' Better than
"Basic
"
1034 .ScriptCode = psScriptCode
1036 oParent.registerScriptEvent(iIndex, oEvent)
1038 _RegisterEventScript = True
1040 End Function
' _RegisterEventScript V1.7
.0
1042 REM -----------------------------------------------------------------------------------------------------------------------
1043 Public Sub _ResetCalledSub(ByVal psSub As String)
1044 ' Called in bottom of each public function. _A2B_.CalledSub variable is used for error handling
1045 ' Used to trace routine in/outs and to clarify error messages
1046 If IsEmpty(_A2B_) Then Call Application._RootInit()
' Only when Utils module recompiled
1048 If .CalledSub = psSub Then .CalledSub =
""
1049 If .MinimalTraceLevel =
1 Then TraceLog(TRACEDEBUG, _GetLabel(
"Exiting
")
& " " & psSub
& " ...
", False)
1051 End Sub
' ResetCalledSub
1053 REM -----------------------------------------------------------------------------------------------------------------------
1054 Public Function _RunScript(ByVal psScript As String, Optional pvArgs() As Variant) As Boolean
1055 ' Execute a given script with pvArgs() array of arguments
1057 On Local Error Goto Error_Function
1059 If IsNull(ThisComponent) Then Goto Exit_Function
1061 Dim oSCriptProvider As Object, oScript As Object, vResult As Variant
1063 Set oScriptProvider = ThisComponent.ScriptProvider()
1064 Set oScript = oScriptProvider.getScript(psScript)
1065 If IsMissing(pvArgs()) Then pvArgs() = Array()
1066 vResult = oScript.Invoke(pvArgs(), Array(), Array())
1076 REM -----------------------------------------------------------------------------------------------------------------------
1077 Public Sub _SetCalledSub(ByVal psSub As String)
1078 ' Called in top of each public function.
1079 ' Used to trace routine in/outs and to clarify error messages
1080 If IsEmpty(_A2B_) Then Call Application._RootInit()
' First use of Access2Base in current LibO/AOO session
1082 If .CalledSub =
"" Then
1085 .LastErrorLevel =
""
1086 .ErrorText =
""
1087 .ErrorLongText =
""
1089 If .MinimalTraceLevel =
1 Then TraceLog(TRACEDEBUG, _GetLabel(
"Entering
")
& " " & psSub
& " ...
", False)
1091 End Sub
' SetCalledSub
1093 REM -----------------------------------------------------------------------------------------------------------------------
1094 Public Function _Surround(ByVal psName As String) As String
1095 ' Return [Name] if Name contains spaces
1096 ' Return [Name1].[Name2].[Name3] if Name1.Name2.Name3 contains dots
1098 Const cstSquareOpen =
"[
"
1099 Const cstSquareClose =
"]
"
1100 Const cstDot =
".
"
1103 If InStr(psName,
".
")
> 0 Then
1104 sName = Join(Split(psName, cstDot), cstSquareClose
& cstDot
& cstSquareOpen)
1105 _Surround = cstSquareOpen
& sName
& cstSquareClose
1106 ElseIf InStr(psName,
" ")
> 0 Then
1107 _Surround = cstSquareOpen
& psName
& cstSquareClose
1112 End Function
' Surround
1114 REM -----------------------------------------------------------------------------------------------------------------------
1115 Public Function _Trim(ByVal psString As String) As String
1116 ' Remove leading and trailing spaces, remove surrounding square brackets, replace tabs by spaces
1117 Const cstSquareOpen =
"[
"
1118 Const cstSquareClose =
"]
"
1121 sTrim = Trim(Replace(psString, vbTab,
" "))
1123 If Len(sTrim)
<=
2 Then Exit Function
1125 If Left(sTrim,
1) = cstSquareOpen Then
1126 If Right(sTrim,
1) = cstSquareClose Then
1127 _Trim = Mid(sTrim,
2, Len(sTrim) -
2)
1130 End Function
' Trim V0.9
.0
1132 REM -----------------------------------------------------------------------------------------------------------------------
1133 Public Function _TrimArray(pvArray As Variant) As Variant
1134 ' Remove empty strings from strings array
1136 Dim sTrim As String, vTrim() As Variant, i As Integer, j As Integer, iCount As Integer
1138 If Not IsArray(pvArray) Then
1139 If Len(Trim(pvArray))
> 0 Then vTrim = Array(pvArray) Else vTrim = Array()
1140 ElseIf UBound(pvArray)
< LBound(pvArray) Then
' Array empty
1144 For i = LBound(pvArray) To UBound(pvArray)
1145 If Len(Trim(pvArray(i))) =
0 Then iCount = iCount +
1
1149 ElseIf iCount = UBound(pvArray) - LBound(pvArray) +
1 Then
' Array empty or all blanks
1152 ReDim vTrim(LBound(pvArray) To UBound(pvArray) - iCount)
1154 For i = LBound(pvArray) To UBound(pvArray)
1155 If Len(Trim(pvArray(i)))
> 0 Then
1156 vTrim(j) = pvArray(i)
1163 _TrimArray() = vTrim()
1165 End Function
' TrimArray V0.9
.0
1167 REM -----------------------------------------------------------------------------------------------------------------------
1168 Private Function _UpdateResultSetColumnValue(piRDBMS As Integer _
1169 , poResultSet As Object _
1170 , ByVal piColIndex As Integer _
1171 , ByVal pvValue As Variant _
1173 REM store the pvValue for the column specified by ColIndex
1174 REM get type name from metadata
1176 Dim iType As Integer, vDateTime As Variant, oValue As Object
1177 Dim bNullable As Boolean, lSize As Long, iValueType As Integer, sValueTypeName As String
1178 Const cstMaxTextLength =
65535
1179 Const cstMaxBinlength =
2 *
65535
1181 On Local Error Goto
0 ' Disable error handler
1182 _UpdateResultSetColumnValue = False
1183 With com.sun.star.sdbc.DataType
1184 iType = poResultSet.MetaData.getColumnType(piColIndex)
1185 iValueType = VarType(pvValue)
1186 sValueTypeName = UCase(poResultSet.MetaData.getColumnTypeName(piColIndex))
1187 bNullable = ( poResultSet.MetaData.IsNullable(piColIndex) = com.sun.star.sdbc.ColumnValue.NULLABLE )
1189 If bNullable And IsNull(pvValue) Then
1190 poResultSet.updateNull(piColIndex)
1193 Case .ARRAY, .DISTINCT, .OBJECT, .OTHER, .REF, .SQLNULL, .STRUCT
1194 poResultSet.updateNull(piColIndex)
1195 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
1196 poResultSet.updateBytes(piColIndex, pvValue)
1197 Case .BIT, .BOOLEAN : poResultSet.updateBoolean(piColIndex, pvValue)
1198 Case .DATE : vDateTime = CreateUnoStruct(
"com.sun.star.util.Date
")
1199 vDateTime.Year = Year(pvValue)
1200 vDateTime.Month = Month(pvValue)
1201 vDateTime.Day = Day(pvValue)
1202 poResultSet.updateDate(piColIndex, vDateTime)
1203 Case .DECIMAL, .NUMERIC : poResultSet.updateDouble(piColIndex, pvValue)
1204 Case .DOUBLE, .REAL : poResultSet.updateDouble(piColIndex, pvValue)
1205 Case .FLOAT : poResultSet.updateFloat(piColIndex, pvValue)
1206 Case .INTEGER, .SMALLINT : poResultSet.updateInt(piColIndex, pvValue)
1207 Case .BIGINT : poResultSet.updateLong(piColIndex, pvValue)
1208 Case .DECIMAL, .NUMERIC : poResultSet.updateDouble(piColIndex, pvValue)
1209 Case .TINYINT : poResultSet.updateShort(piColIndex, pvValue)
1210 Case .CHAR, .VARCHAR, .LONGVARCHAR, .CLOB
1211 If piRDBMS = DBMS_SQLITE And InStr(sValueTypeName,
"BINARY
")
> 0 Then
' Sqlite exception ... !
1212 poResultSet.updateBytes(piColIndex, pvValue)
1214 poResultSet.updateString(piColIndex, pvValue)
1216 Case .TIME : vDateTime = CreateUnoStruct(
"com.sun.star.util.Time
")
1217 vDateTime.Hours = Hour(pvValue)
1218 vDateTime.Minutes = Minute(pvValue)
1219 vDateTime.Seconds = Second(pvValue)
1220 'vDateTime.HundredthSeconds =
0
1221 poResultSet.updateTime(piColIndex, vDateTime)
1222 Case .TIMESTAMP : vDateTime = CreateUnoStruct(
"com.sun.star.util.DateTime
")
1223 vDateTime.Year = Year(pvValue)
1224 vDateTime.Month = Month(pvValue)
1225 vDateTime.Day = Day(pvValue)
1226 vDateTime.Hours = Hour(pvValue)
1227 vDateTime.Minutes = Minute(pvValue)
1228 vDateTime.Seconds = Second(pvValue)
1229 'vDateTime.HundredthSeconds =
0
1230 poResultSet.updateTimestamp(piColIndex, vDateTime)
1232 If bNullable Then poResultSet.updateNull(piColIndex)
1238 _UpdateResultSetColumnValue = True
1240 End Function
' UpdateResultSetColumnValue V
1.6.0
1242 REM -----------------------------------------------------------------------------------------------------------------------
1243 Private Function _URLEncode(ByVal psToEncode As String) As String
1244 ' http://www.w3schools.com/tags/ref_urlencode.asp
1245 ' http://xkr.us/articles/javascript/encode-compare/
1246 ' http://tools.ietf.org/html/rfc3986
1248 Dim sEncoded As String, sChar As String
1249 Dim lCurrentChar As Long, bQuestionMark As Boolean
1251 sEncoded =
""
1252 bQuestionMark = False
1253 For lCurrentChar =
1 To Len(psToEncode)
1254 sChar = Mid(psToEncode, lCurrentChar,
1)
1256 Case
" ",
"%
"
1257 sEncoded = sEncoded
& _PercentEncode(sChar)
1258 Case
"?
" ' Is it the first
"?
" ?
1259 If bQuestionMark Then
' "?
" introduces in a URL the arguments part
1260 sEncoded = sEncoded
& _PercentEncode(sChar)
1262 sEncoded = sEncoded
& sChar
1263 bQuestionMark = True
1266 If bQuestionMark Then
1267 sEncoded = sEncoded
& _PercentEncode(sChar)
1269 sEncoded = sEncoded
& "/
" ' If Windows file naming ...
1272 If bQuestionMark Then
1273 sEncoded = sEncoded
& _PercentEncode(sChar)
1275 sEncoded = sEncoded
& _UTF8Encode(sChar)
' Because IE does not support %encoding in first part of URL
1280 _URLEncode = sEncoded
1282 End Function
' _URLEncode V1.4
.0
1284 REM -----------------------------------------------------------------------------------------------------------------------
1285 Private Function _UTF8Encode(ByVal psChar As String) As String
1286 ' &-encoding of single psChar character (e.g.
"é
" becomes
"&eacute;
" or numeric equivalent
1287 ' http://www.w3schools.com/charsets/ref_html_utf8.asp
1290 Case
"""" : _UTF8Encode =
"&quot;
"
1291 Case
"&" : _UTF8Encode =
"&amp;
"
1292 Case
"<" : _UTF8Encode =
"&lt;
"
1293 Case
">" : _UTF8Encode =
"&gt;
"
1294 Case
"'" : _UTF8Encode =
"&apos;
"
1295 Case
":
",
"/
",
"?
",
"#
",
"[
",
"]
",
"@
" ' Reserved characters
1296 _UTF8Encode = psChar
1297 Case Chr(
13) : _UTF8Encode =
"" ' Carriage return
1298 Case Chr(
10) : _UTF8Encode =
"<br
>" ' Line Feed
1299 Case
< Chr(
126) : _UTF8Encode = psChar
1300 Case
"€
" : _UTF8Encode =
"&euro;
"
1301 Case Else : _UTF8Encode =
"&#
" & Asc(psChar)
& ";
"
1306 End Function
' _UTF8Encode V1.4
.0