/usr/lib/libreoffice/share/basic/Access2Base/Recordset.xba is in libreoffice-base 1:4.3.3-2+deb8u11.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Recordset" script:language="StarBasic">REM =======================================================================================================================
REM === The Access2Base library is a part of the LibreOffice project. ===
REM === Full documentation is available on http://www.access2base.com ===
REM =======================================================================================================================
Option Compatible
Option ClassModule
Option Explicit
REM -----------------------------------------------------------------------------------------------------------------------
REM --- CLASS ROOT FIELDS ---
REM -----------------------------------------------------------------------------------------------------------------------
Private _Type As String ' Must be RECORDSET
Private _Name As String ' Unique, generated
Private _ParentName As String
Private _ParentType As String
Private _ParentDatabase As Object
Private _ForwardOnly As Boolean
Private _PassThrough As Boolean
Private _ReadOnly As Boolean
Private _CommandType As Long
Private _Command As String
Private _DataSet As Boolean ' True if execute() successful
Private _BOF As Boolean
Private _EOF As Boolean
Private _Filter As String
Private _EditMode As Integer ' dbEditxxx constants
Private _BookmarkBeforeNew As Variant
Private _BookmarkLastModified As Variant
Private _IsClone As Boolean
Private RowSet As Object ' com.sun.star.comp.dba.ORowSet
REM -----------------------------------------------------------------------------------------------------------------------
REM --- CONSTRUCTORS / DESTRUCTORS ---
REM -----------------------------------------------------------------------------------------------------------------------
Private Sub Class_Initialize()
_Type = OBJRECORDSET
_Name = ""
_ParentName = ""
Set _ParentDatabase = Nothing
_ParentType = ""
_ForwardOnly = False
_PassThrough = False
_ReadOnly = False
_CommandType = 0
_Command = ""
_DataSet = False
_BOF = True
_EOF = True
_Filter = ""
_EditMode = dbEditNone
_BookmarkBeforeNew = Null
_BookmarkLastModified = Null
_IsClone = False
Set RowSet = Nothing
End Sub ' Constructor
REM -----------------------------------------------------------------------------------------------------------------------
Private Sub Class_Terminate()
mClose()
Set Statement = Nothing
Set RowSet = Nothing
End Sub
REM -----------------------------------------------------------------------------------------------------------------------
REM --- CLASS GET/LET/SET PROPERTIES ---
REM -----------------------------------------------------------------------------------------------------------------------
REM -----------------------------------------------------------------------------------------------------------------------
Property Get AbsolutePosition() As Variant
AbsolutePosition = _PropertyGet("AbsolutePosition")
End Property ' AbsolutePosition (get)
Property Let AbsolutePosition(ByVal pvValue As Variant)
Call _PropertySet("AbsolutePosition", pvValue)
End Property ' AbsolutePosition (set)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get BOF() As Boolean
BOF = _PropertyGet("BOF")
End Property ' BOF (get)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get Bookmark() As Variant
Bookmark = _PropertyGet("Bookmark")
End Property ' Bookmark (get)
Property Let Bookmark(ByVal pvValue As Variant)
Call _PropertySet("Bookmark", pvValue)
End Property ' Bookmark (set)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get Bookmarkable() As Boolean
Bookmarkable = _PropertyGet("Bookmarkable")
End Property ' Bookmarkable (get)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get EOF() As Boolean
EOF = _PropertyGet("EOF")
End Property ' EOF (get)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get EditMode() As Boolean
EditMode = _PropertyGet("EditMode")
End Property ' EditMode (get)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get Filter() As Variant
Filter = _PropertyGet("Filter")
End Property ' Filter (get)
Property Let Filter(ByVal pvValue As Variant)
Call _PropertySet("Filter", pvValue)
End Property ' Filter (set)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get LastModified() As Variant
' DO NOT PUBLISH
LastModified = _PropertyGet("LastModified")
End Property ' LastModified (get)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get Name() As String
Name = _PropertyGet("Name")
End Property ' Name (get)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get ObjectType() As String
ObjectType = _PropertyGet("ObjectType")
End Property ' ObjectType (get)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get RecordCount() As Long
RecordCount = _PropertyGet("RecordCount")
End Property ' RecordCount (get)
REM -----------------------------------------------------------------------------------------------------------------------
REM --- CLASS METHODS ---
REM -----------------------------------------------------------------------------------------------------------------------
REM -----------------------------------------------------------------------------------------------------------------------
Public Function AddNew() As Boolean
' Initiates the creation of a new record
Const cstThisSub = "Recordset.AddNew"
Dim i As Integer, iFieldsCount As Integer, oField As Object
Dim sdefault As String, oColumn As Object
Dim iValue As Integer, lValue As Long, sgValue As Single, dbValue As Double, dValue As Date
Dim vTemp As Variant
If _ErrorHandler() Then On Local Error Goto Error_Function
Utils._SetCalledSub(cstThisSub)
AddNew = False
With RowSet
'Is inserting a new row allowed ?
If _ForwardOnly Or _ReadOnly Then Goto Error_NoUpdate
If Not .CanUpdateInsertedRows Then Goto Error_NoUpdate
If Not .IsBookmarkable Then Goto Error_NoUpdate
If _EditMode <> dbEditNone Then CancelUpdate()
If _BOF And _EOF Then ' Records before first or after last do not have a bookmark
_BookmarkBeforeNew = "_BOF_"
ElseIf .isBeforeFirst() Then
_BookmarkBeforeNew = "_BOF_"
ElseIf .isAfterLast() Then
_BookmarkBeforeNew = "_EOF_"
Else
_BookmarkBeforeNew = .getBookmark()
End If
.moveToInsertRow()
'Set all fields to their default value
iFieldsCount = Fields().Count
On Local Error Resume Next ' Do not stop if default setting fails
For i = 0 To iFieldsCount - 1
Set oField = Fields(i)
Set oColumn = oField.Column
If Utils._hasUNOProperty(oColumn, "DefaultValue") Then ' Default value in database set via SQL statement
sDefault = oColumn.DefaultValue
ElseIf Utils._hasUNOProperty(oColumn, "ControlDefault") Then ' Default value set in Base via table edition
If IsEmpty(oColumn.ControlDefault) Then sdefault = "" Else sDefault = oColumn.ControlDefault
Else
sdefault = ""
End If
If sDefault = "" Then
If oColumn.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE Then oColumn.updateNull()
Else ' No default value
With com.sun.star.sdbc.DataType
Select Case oColumn.Type
Case .BIT, .BOOLEAN
If sDefault = "1" Then oColumn.updateBoolean(True) Else oColumn.updateBoolean(False)
Case .TINYINT
iValue = CInt(sDefault)
If iValue >= -128 And iValue <= +127 Then oColumn.updateShort(iValue)
Case .SMALLINT
lValue = CLng(sDefault)
If lValue >= -32768 And lValue <= 32767 Then oColumn.updateInt(lValue)
Case .INTEGER
lValue = CLng(sDefault)
If lValue >= -2147483648 And lValue <= 2147483647 Then oColumn.updateInt(lValue)
Case .BIGINT
lValue = CLng(sDefault)
Column.updateLong(lValue) ' No proper type conversion for HYPER data type
Case .FLOAT
sgValue = CSng(sDefault)
If Abs(sgValue) < 3.402823E38 And Abs(sgValue) > 1.401298E-45 Then oColumn.updateFloat(sgValue)
Case .REAL, .DOUBLE
dbValue = CDbl(sDefault)
'If Abs(dbValue) < 1.79769313486232E308 And Abs(dbValue) > 4.94065645841247E-307 Then oColumn.updateDouble(dbValue)
oColumn.updateDouble(dbValue)
Case .NUMERIC, .DECIMAL
dbValue = CDbl(sDefault)
If Utils._hasUNOProperty(Column, "Scale") Then
If Column.Scale > 0 Then
'If Abs(dbValue) < 1.79769313486232E308 And Abs(dbValue) > 4.94065645841247E-307 Then oColumn.updateDouble(dbValue)
oColumn.updateDouble(dbValue)
Else
oColumn.updateString(sdefault)
End If
Else
oColumn.updateString(sdefault)
End If
Case .CHAR, .VARCHAR, .LONGVARCHAR
oColumn.updateString(sdefault) ' vbString
Case .DATE
dValue = DateValue(sDefault)
vTemp = New com.sun.star.util.Date
With vTemp
.Day = Day(dValue)
.Month = Month(dValue)
.Year = Year(dValue)
End With
oColumn.updateDate(vTemp)
Case .TIME
dValue = TimeValue(sDefault)
vTemp = New com.sun.star.util.Time
With vTemp
.Hours = Hour(dValue)
.Minutes = Minute(dValue)
.Seconds = Second(dValue)
'.HundredthSeconds = 0
End With
oColumn.updateTime(vTemp)
Case .TIMESTAMP
dValue = DateValue(sDefault)
vTemp = New com.sun.star.util.DateTime
With vTemp
.Day = Day(dValue)
.Month = Month(dValue)
.Year = Year(dValue)
.Hours = Hour(dValue)
.Minutes = Minute(dValue)
.Seconds = Second(dValue)
'.HundredthSeconds = 0
End With
oColumn.updateTimestamp(vTemp)
' Case .BINARY, .VARBINARY, .LONGVARBINARY
' Case .BLOB
' Case .CLOB
Case Else
End Select
End With
End If
Next i
End With
If _ErrorHandler() Then On Local Error Goto Error_Function Else On Local Error Goto 0
_EditMode = dbEditAdd
AddNew = True
Exit_Function:
Utils._ResetCalledSub(cstThisSub)
Exit Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub, Erl)
GoTo Exit_Function
Error_NoUpdate:
TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(), 0)
Goto Exit_Function
End Function ' AddNew
REM -----------------------------------------------------------------------------------------------------------------------
Public Function CancelUpdate() As Boolean
' Cancel any edit action
Const cstThisSub = "Recordset.CancelUpdate"
If _ErrorHandler() Then On Local Error Goto Error_Function
Utils._SetCalledSub(cstThisSub)
CancelUpdate = False
With RowSet
Select Case _EditMode
Case dbEditNone
Case dbEditAdd
If Not IsNull(_BookmarkBeforeNew) Then
Select Case _BookmarkBeforeNew
Case "_BOF_" : .beforeFirst()
Case "_EOF_" : .afterLast()
Case Else : .moveToBookmark(_BookmarkBeforeNew)
End Select
End If
Case dbEditInProgress
.cancelRowUpdates()
End Select
End With
_EditMode = dbEditNone
_BookmarkBeforeNew = Null
_BookmarkLastModified = Null
CancelUpdate = True
Exit_Function:
Utils._ResetCalledSub(cstThisSub)
Exit Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub, Erl)
GoTo Exit_Function
End Function ' CancelUpdate
REM -----------------------------------------------------------------------------------------------------------------------
Public Function Clone() As Object
' Duplicate an existing recordset
Const cstThisSub = "Recordset.Clone"
Const cstNull = -1
Dim iType As Integer, iOptions As Integer, iLockEdit As Integer
If _ErrorHandler() Then On Local Error Goto Error_Function
Utils._SetCalledSub(cstThisSub)
Set Clone = Nothing
If _IsClone Then Goto Error_Clone
If _ForwardOnly Then iType = dbOpenForwardOnly Else iType = cstNull
If _PassThrough Then iOptions = dbSQLPassThrough Else iOptions = cstNull
iLockEdit = dbReadOnly ' Always read-only
Set Clone = OpenRecordset(iType, iOptions, iLockEdit, True)
Exit_Function:
Utils._ResetCalledSub(cstThisSub)
Exit Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub, Erl)
GoTo Exit_Function
Error_Clone:
TraceError(TRACEFATAL, ERRRECORDSETCLONE, Utils._CalledSub(), 0)
Goto Exit_Function
End Function ' Clone
REM -----------------------------------------------------------------------------------------------------------------------
Public Function mClose(ByVal Optional pbRemove As Boolean) As Variant
' Dispose UNO objects
' If pbRemove = True, remove recordset from Recordsets collection
Const cstThisSub = "Recordset.Close"
If _ErrorHandler() Then On Local Error Goto Exit_Function ' Do not stop execution
Utils._SetCalledSub(cstThisSub)
If Not IsNull(RowSet) Then
RowSet.close()
RowSet.dispose()
End If
_ForwardOnly = False
_PassThrough = False
_ReadOnly = False
_CommandType = 0
_Command = ""
_ParentName = ""
_ParentType = ""
_DataSet = False
_BOF = True
_EOF = True
_Filter = ""
_EditMode = dbEditNone
_BookmarkBeforeNew = Null
_BookmarkLastModified = Null
_IsClone = False
Set RowSet = Nothing
If IsMissing(pbRemove) Then pbRemove = True
If pbRemove Then _ParentDatabase.RecordsetsColl.Remove(_Name)
Set _ParentDatabase = Nothing
Exit_Function:
Utils._ResetCalledSub(cstThisSub)
Exit Function
End Function ' Close
REM -----------------------------------------------------------------------------------------------------------------------
Public Function Delete() As Boolean
' Deletes the current record
Const cstThisSub = "Recordset.Delete"
If _ErrorHandler() Then On Local Error Goto Error_Function
Utils._SetCalledSub(cstThisSub)
Delete = False
'Is deleting a row allowed ?
If _ForwardOnly Or _ReadOnly Then Goto Error_NoUpdate
If _EditMode <> dbEditNone Then
CancelUpdate()
Goto Error_Sequence
End If
If RowSet.rowDeleted() Then Goto Error_RowDeleted
RowSet.deleteRow()
Delete = True
Exit_Function:
Utils._ResetCalledSub(cstThisSub)
Exit Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub, Erl)
GoTo Exit_Function
Error_NoUpdate:
TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(), 0)
Goto Exit_Function
Error_RowDeleted:
TraceError(TRACEFATAL, ERRROWDELETED, Utils._CalledSub(), 0)
Goto Exit_Function
Error_Sequence:
TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(), 0, 1)
Goto Exit_Function
End Function ' Delete
REM -----------------------------------------------------------------------------------------------------------------------
Public Function Edit() As Boolean
' Updates the current record
Const cstThisSub = "Recordset.Edit"
If _ErrorHandler() Then On Local Error Goto Error_Function
Utils._SetCalledSub(cstThisSub)
Edit = False
'Is updating a row allowed ?
If _ForwardOnly Or _ReadOnly Then Goto Error_NoUpdate
If _EditMode <> dbEditNone Then CancelUpdate()
If RowSet.rowDeleted() Then Goto Error_RowDeleted
_EditMode = dbEditInProgress
Edit = True
Exit_Function:
Utils._ResetCalledSub(cstThisSub)
Exit Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub, Erl)
GoTo Exit_Function
Error_NoUpdate:
TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(), 0)
Goto Exit_Function
Error_RowDeleted:
TraceError(TRACEFATAL, ERRROWDELETED, Utils._CalledSub(), 0)
Goto Exit_Function
End Function ' Edit
REM -----------------------------------------------------------------------------------------------------------------------
Public Function Fields(ByVal Optional pvIndex As variant) As Object
If _ErrorHandler() Then On Local Error Goto Error_Function
Const cstThisSub = "Recordset.Fields"
Utils._SetCalledSub(cstThisSub)
Set Fields = Nothing
If Not IsMissing(pvIndex) Then
If Not Utils._CheckArgument(pvIndex, 1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
End If
Dim sObjects() As String, sObjectName As String, oObject As Object
Dim i As Integer, bFound As Boolean, oFields As Object
Set oFields = RowSet.getColumns()
sObjects = oFields.ElementNames()
Select Case True
Case IsMissing(pvIndex)
Set oObject = New Collect
oObject._CollType = COLLFIELDS
oObject._ParentType = OBJRECORDSET
oObject._ParentName = _Name
Set oObject._ParentDatabase = _ParentDatabase
oObject._Count = UBound(sObjects) + 1
Goto Exit_Function
Case VarType(pvIndex) = vbString
bFound = False
' Check existence of object and find its exact (case-sensitive) name
For i = 0 To UBound(sObjects)
If UCase(pvIndex) = UCase(sObjects(i)) Then
sObjectName = sObjects(i)
bFound = True
Exit For
End If
Next i
If Not bFound Then Goto Trace_NotFound
Case Else ' pvIndex is numeric
If pvIndex < 0 Or pvIndex > UBound(sObjects) Then Goto Trace_IndexError
sObjectName = sObjects(pvIndex)
End Select
Set oObject = New Field
oObject._Name = sObjectName
Set oObject.Column = oFields.getByName(sObjectName)
oObject._ParentName = _Name
oObject._ParentType = _Type
Set oObject._ParentDatabase = _ParentDatabase
Exit_Function:
Set Fields = oObject
Set oObject = Nothing
Utils._ResetCalledSub(cstThisSub)
Exit Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub, Erl)
GoTo Exit_Function
Trace_NotFound:
TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(), 0, , Array(_GetLabel("FIELD"), pvIndex))
Goto Exit_Function
Trace_IndexError:
TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(), 0)
Goto Exit_Function
End Function ' Fields
REM -----------------------------------------------------------------------------------------------------------------------
Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
' Return property value of psProperty property name
Const cstThisSub = "Recordset.getProperty"
Utils._SetCalledSub(cstThisSub)
If IsMissing(pvProperty) Then Call _TraceArguments()
getProperty = _PropertyGet(pvProperty)
Utils._ResetCalledSub(cstThisSub)
End Function ' getProperty
REM -----------------------------------------------------------------------------------------------------------------------
Public Function GetRows(ByVal Optional pvNumRows As variant) As Variant
If _ErrorHandler() Then On Local Error Goto Error_Function
Const cstThisSub = "Recordset.GetRows"
Utils._SetCalledSub(cstThisSub)
Dim vMatrix() As Variant, lSize As Long, iNumFields As Integer, i As Integer
vMatrix() = Array()
If IsMissing(pvNumRows) Then Call _TraceArguments()
If Not Utils._CheckArgument(pvNumRows, 1, Utils._AddNumeric()) Then Goto Exit_Function
If pvNumRows < 1 Then Goto Trace_Error
If IsNull(RowSet) Then Goto Trace_Closed
If Not _DataSet Then Goto Exit_Function
If _EditMode <> dbEditNone Then CancelUpdate()
If _EOF Then Goto Exit_Function
lSize = -1
iNumFields = RowSet.getColumns().Count - 1
If iNumFields < 0 Then Goto Exit_Function
ReDim vMatrix(0 To pvNumRows - 1, 0 To iNumFields) ' Conscious opposite of MSAccess !!
Do While Not _EOF And lSize < pvNumRows - 1
lSize = lSize + 1
For i = 0 To iNumFields
vMatrix(lSize, i) = _getResultSetColumnValue(RowSet, i + 1)
Next i
_Move("NEXT")
Loop
If lSize < pvNumRows - 1 Then ' Resize to number of fetched records
ReDim Preserve vMatrix(0 To lSize, 0 To iNumFields)
End If
Exit_Function:
GetRows() = vMatrix()
Utils._ResetCalledSub(cstThisSub)
Exit Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub, Erl)
GoTo Exit_Function
Trace_Error:
TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(), 0, , Array(1, pvNumRows))
Set Controls = Nothing
Goto Exit_Function
Trace_Closed:
TraceError(TRACEFATAL, ERRRECORDSETCLOSED, Utils._CalledSub(), 0)
Goto Exit_Function
End Function ' GetRows V1.1.0
REM -----------------------------------------------------------------------------------------------------------------------
Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
Const cstThisSub = "Recordset.hasProperty"
Utils._SetCalledSub(cstThisSub)
If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
Utils._ResetCalledSub(cstThisSub)
Exit Function
End Function ' hasProperty
REM -----------------------------------------------------------------------------------------------------------------------
Public Function Move(ByVal Optional pvRelative As Variant, ByVal Optional pvBookmark As variant) As Boolean
' Move record pointer Relative rows vs. bookmark or current record
If IsMissing(pvRelative) Then Call _TraceArguments()
If Not Utils._CheckArgument(pvRelative, 1, Utils._AddNumeric()) Then Goto Exit_Function
If IsMissing(pvBookmark) Then Move = _Move(pvRelative) Else Move = _Move(pvRelative, pvBookmark)
Exit_Function:
Exit Function
End Function ' Move
REM -----------------------------------------------------------------------------------------------------------------------
Public Function MoveFirst() As Boolean
MoveFirst = _Move("First")
End Function ' MoveFirst
REM -----------------------------------------------------------------------------------------------------------------------
Public Function MoveLast() As Boolean
MoveLast = _Move("Last")
End Function ' MoveLast
REM -----------------------------------------------------------------------------------------------------------------------
Public Function MoveNext() As Boolean
MoveNext = _Move("Next")
End Function ' MoveNext
REM -----------------------------------------------------------------------------------------------------------------------
Public Function MovePrevious() As Boolean
MovePrevious = _Move("Previous")
End Function ' MovePrevious
REM -----------------------------------------------------------------------------------------------------------------------
Public Function OpenRecordset(ByVal Optional pvType As Variant _
, ByVal Optional pvOptions As Variant _
, ByVal Optional pvLockEdit As Variant _
, ByVal Optional pbClone As Boolean) As Object
'Return a Recordset object based on currentrecordset object with filter addition
If _ErrorHandler() Then On Local Error Goto Error_Function
Dim cstThisSub As String
cstThisSub = Utils._PCase(_Type) & ".OpenRecordset"
Utils._SetCalledSub(cstThisSub)
Set OpenRecordset = Nothing
Const cstNull = -1
Dim oObject As Object
Set oObject = Nothing
If IsMissing(pvType) Then
pvType = cstNull
Else
If Not Utils._CheckArgument(pvType, 1, Utils._AddNumeric(), Array(cstNull, dbOpenForwardOnly)) Then Goto Exit_Function
End If
If IsMissing(pvOptions) Then
pvOptions = cstNull
Else
If Not Utils._CheckArgument(pvOptions, 2, Utils._AddNumeric(), Array(cstNull, dbSQLPassThrough)) Then Goto Exit_Function
End If
If IsMissing(pvLockEdit) Then
pvLockEdit = cstNull
Else
If Not Utils._CheckArgument(pvLockEdit, 3, Utils._AddNumeric(), Array(cstNull, dbReadOnly)) Then Goto Exit_Function
End If
If IsMissing(pbClone) Then pbClone = False ' pbClone is a not published argument
Set oObject = New Recordset
With oObject
._CommandType = _CommandType
._Command = _Command
._ParentName = _Name
._ParentType = _Type
Set ._ParentDatabase = _ParentDatabase
._ForwardOnly = ( pvType = dbOpenForwardOnly )
._PassThrough = ( pvOptions = dbSQLPassThrough )
._ReadOnly = ( (pvLockEdit = dbReadOnly) Or _ReadOnly )
Select Case True
Case pbClone : Call ._Initialize(, RowSet)
Case _Filter <> "" : Call ._Initialize(_Filter)
Case Else : Call ._Initialize()
End Select
End With
With _ParentDatabase
.RecordsetMax = .RecordsetMax + 1
oObject._Name = Format(.RecordsetMax, "0000000")
.RecordsetsColl.Add(oObject, UCase(oObject._Name))
End With
If Not ( oObject._BOF And oObject._EOF ) Then oObject.MoveFirst() ' Do nothing if resultset empty
Exit_Function:
Set OpenRecordset = oObject
Set oObject = Nothing
Utils._ResetCalledSub(cstThisSub)
Exit Function
Error_Function:
TraceError(TRACEABORT, Err, Utils._CalledSub(), Erl)
GoTo Exit_Function
End Function ' OpenRecordset
REM -----------------------------------------------------------------------------------------------------------------------
Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
' Return
' a Collection object if pvIndex absent
' a Property object otherwise
Const cstThisSub = "Recordset.Properties"
Utils._SetCalledSub(cstThisSub)
Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
vPropertiesList = _PropertiesList()
sObject = Utils._PCase(_Type)
If IsMissing(pvIndex) Then
vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList)
Else
vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList, pvIndex)
vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
End If
Set vProperty._ParentDatabase = _ParentDatabase
Exit_Function:
Set Properties = vProperty
Utils._ResetCalledSub(cstThisSub)
Exit Function
End Function ' Properties
REM -----------------------------------------------------------------------------------------------------------------------
Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
' Return True if property setting OK
Const cstThisSub = "Recordset.setProperty"
Utils._SetCalledSub(cstThisSub)
setProperty = _PropertySet(psProperty, pvValue)
Utils._ResetCalledSub(cstThisSub)
End Function
REM -----------------------------------------------------------------------------------------------------------------------
Public Function Update() As Boolean
' Finalize the updates of the current record
Const cstThisSub = "Recordset.Update"
If _ErrorHandler() Then On Local Error Goto Error_Function
Utils._SetCalledSub(cstThisSub)
Update = False
'Is updating a row allowed ?
If _ForwardOnly Or _ReadOnly Then Goto Error_NoUpdate
With RowSet
If .rowDeleted() Then Goto Error_RowDeleted
Select Case _EditMode
Case dbEditNone
Goto Trace_Error_Update
Case dbEditAdd
If .IsNew And .IsModified Then .insertRow()
_BookmarkLastModified = .getBookmark()
If Not IsNull(_BookmarkBeforeNew) Then
Select Case _BookmarkBeforeNew
Case "_BOF_" : .beforeFirst()
Case "_EOF_" : .afterLast()
Case Else : .moveToBookmark(_BookmarkBeforeNew)
End Select
End If
Case dbEditInProgress
If .IsModified Then
.updateRow()
_BookmarkLastModified = .getBookmark()
End If
End Select
End With
_EditMode = dbEditNone
Update = True
Exit_Function:
Utils._ResetCalledSub(cstThisSub)
Exit Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub, Erl)
GoTo Exit_Function
Error_NoUpdate:
TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(), 0)
Goto Exit_Function
Trace_Error_Update:
TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(), 0, 1)
Goto Exit_Function
Error_RowDeleted:
TraceError(TRACEFATAL, ERRROWDELETED, Utils._CalledSub(), 0)
Goto Exit_Function
End Function ' Update
REM -----------------------------------------------------------------------------------------------------------------------
REM --- PRIVATE FUNCTIONS ---
REM -----------------------------------------------------------------------------------------------------------------------
REM -----------------------------------------------------------------------------------------------------------------------
Public Sub _Initialize(ByVal Optional pvFilter As Variant, Optional poRowSet As Object)
' Initialize new recordset
If _Command = "" Then Exit Sub
If _ErrorHandler() Then On Local Error Goto Error_Sub
If IsMissing(pvFilter) Then pvFilter = ""
If Not IsMissing(poRowSet) Then ' Clone
Set RowSet = poRowSet.createResultSet()
_IsClone = True
RowSet.last() ' Solves bookmark desynchro when parent bookmark is used ?!?
Else
Set RowSet = CreateUnoService("com.sun.star.sdb.RowSet")
_IsClone = False
With RowSet
If IsNull(.ActiveConnection) Then Set .ActiveConnection = _ParentDatabase.Connection
.CommandType = _CommandType
.Command = _Command
If _ForwardOnly Then .ResultSetType = com.sun.star.sdbc.ResultSetType.FORWARD_ONLY _
Else .ResultSetType = com.sun.star.sdbc.ResultSetType.SCROLL_SENSITIVE
If _PassThrough Then .EscapeProcessing = False _
Else .EscapeProcessing = True
If _ReadOnly Then
.ResultSetConcurrency = com.sun.star.sdbc.ResultSetConcurrency.READ_ONLY
.TransactionIsolation = com.sun.star.sdbc.TransactionIsolation.READ_UNCOMMITTED ' Dirty read
Else
.ResultSetConcurrency = com.sun.star.sdbc.ResultSetConcurrency.UPDATABLE
.TransactionIsolation = com.sun.star.sdbc.TransactionIsolation.READ_COMMITTED
End If
End With
If Not IsMissing(pvFilter) Then ' Filter must be set before execute()
If pvFilter <> "" Then
RowSet.Filter = pvFilter
RowSet.ApplyFilter = True
End If
End If
On Local Error Goto SQL_Error
RowSet.execute()
On Local Error Goto Error_Sub
End If
_DataSet = True
'If the Recordset contains no records, the BOF and EOF properties are True, and there is no current record.
_BOF = ( RowSet.IsRowCountFinal And RowSet.RowCount = 0 )
_EOF = _BOF
Exit_Sub:
Exit Sub
SQL_Error:
TraceError(TRACEFATAL, ERRSQLSTATEMENT, Utils._CalledSub(), 0, , _Command)
Goto Exit_Sub
Error_Sub:
TraceError(TRACEABORT, Err, "Recordset._Initialize", Erl)
GoTo Exit_Sub
End Sub ' _Initialize
REM -----------------------------------------------------------------------------------------------------------------------
Public Function _Move(pvTarget As Variant, ByVal Optional pvBookmark As Variant, ByVal Optional pbAbsolute As Boolean) As Boolean
'Move to the first, last, next, or previous record in a specified Recordset object and make that record the current record.
Dim cstThisSub As String
cstThisSub = "Recordset.Move" & Iif(VarType(pvTarget) = vbString, pvTarget, "")
Utils._SetCalledSub(cstThisSub)
If _ErrorHandler() Then On Local Error Goto Error_Function
If IsNull(RowSet) Then Goto Trace_Closed
If Not _DataSet Then Goto Trace_NoData
If _BOF And _EOF Then Goto Trace_NoData
_Move = False
CancelUpdate() ' Any Move cancels all updates, even Move(0) !
Dim l As Long, lRow As Long
With RowSet
Select Case VarType(pvTarget)
Case vbString
Select Case UCase(pvTarget)
Case "FIRST"
If _ForwardOnly Then
If Not ( .isBeforeFirst() Or .isFirst() ) Then
Goto Trace_Forward
Else
.next()
End If
Else
.first()
End If
Case "LAST"
If _ForwardOnly Then
If .isAfterLast() Then Goto Trace_Forward
Do While Not ( .isRowCountFinal And .Row = .RowCount ) ' isLast() = True after reading of first records chunk
.next()
Loop
Else
.last()
End If
Case "NEXT"
If _EOF Then Goto Trace_OutOfRange
.next()
Case "PREVIOUS"
If _ForwardOnly Then Goto Trace_Forward
If _BOF Then Goto Trace_OutOfRange
.previous()
End Select
Case Else ' Relative or absolute move
If IsMissing(pbAbsolute) Then pbAbsolute = False ' Relative move is default
If _ForwardOnly And pvTarget < 0 then Goto Trace_Forward
If IsMissing(pvBookmark) Then
If pvTarget = 0 Then Goto Exit_Function ' Do nothing
If _ForwardOnly Then
If pbAbsolute Then lRow = .getRow() Else lRow = 0
For l = 1 To pvTarget - lRow
If .isAfterLast() Then Exit For
.next()
Next l
Else
If pbAbsolute Then .absolute(pvTarget) Else .relative(pvTarget)
End If
Else ' Move is always relative when bookmark argument present
If _ForwardOnly Then Goto Trace_Forward
If pvTarget = 0 Then
.moveToBookmark(pvBookmark)
Else
.moveRelativeToBookmark(pvBookmark, pvTarget)
End If
End If
End Select
Select Case True
Case .isBeforeFirst()
_BOF = True
_Move = False
Case .isAfterlast()
_EOF = True
_Move = False
Case Else
If .rowDeleted() Then Goto Error_RowDeleted
If .rowUpdated() Then .refreshRow()
_Move = True
End Select
End With
Exit_Function:
Utils._ResetCalledSub(cstThisSub)
Exit Function
Exit_Close: ' Force close of recordset when error raised
mClose()
Goto Exit_Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub, Erl)
GoTo Exit_Close
Trace_Forward:
TraceError(TRACEFATAL, ERRRECORDSETFORWARD, Utils._CalledSub(), 0)
Goto Exit_Close
Trace_NoData:
TraceError(TRACEFATAL, ERRRECORDSETNODATA, Utils._CalledSub(), 0)
Goto Exit_Close
Trace_OutOfRange:
TraceError(TRACEFATAL, ERRRECORDSETRANGE, Utils._CalledSub(), 0)
Goto Exit_Close
Error_RowDeleted:
TraceError(TRACEFATAL, ERRROWDELETED, Utils._CalledSub(), 0)
Goto Exit_Function
Trace_Closed:
TraceError(TRACEFATAL, ERRRECORDSETCLOSED, Utils._CalledSub(), 0)
Goto Exit_Close
End Function ' Move
REM -----------------------------------------------------------------------------------------------------------------------
Private Function _PropertiesList() As Variant
_PropertiesList = Array("AbsolutePosition", "BOF", "Bookmarkable", "Bookmark", "EditMode" _
, "EOF", "Filter", "LastModified", "Name", "ObjectType" , "RecordCount" _
End Function ' _PropertiesList
REM -----------------------------------------------------------------------------------------------------------------------
Private Function _PropertyGet(ByVal psProperty As String) As Variant
' Return property value of the psProperty property name
If _ErrorHandler() Then On Local Error Goto Error_Function
Dim cstThisSub As String
cstThisSub = "Recordset.get"
Utils._SetCalledSub(cstThisSub & psProperty)
Dim vEMPTY As Variant
_PropertyGet = vEMPTY
Select Case UCase(psProperty)
Case UCase("AbsolutePosition")
If IsNull(RowSet) Then Goto Trace_Closed
With RowSet
Select Case True
Case _BOF And _EOF : _PropertyGet = -1
Case .isBeforeFirst() Or .isAfterLast() : _PropertyGet = -1
Case Else : _PropertyGet = .getRow() ' Not getRow() - 1 as MSAccess requires
End Select
End With
Case UCase("BOF")
If IsNull(RowSet) Then Goto Trace_Closed
Select Case True
Case _BOF And _EOF : _PropertyGet = True
Case RowSet.isBeforeFirst() : _PropertyGet = True
Case Else : _PropertyGet = False
End Select
Case UCase("Bookmarkable")
If IsNull(RowSet) Then Goto Trace_Closed
If _ForwardOnly Then _PropertyGet = False Else _PropertyGet = RowSet.IsBookmarkable
Case UCase("Bookmark")
If IsNull(RowSet) Then Goto Trace_Closed
If RowSet.IsBookmarkable And Not _ForwardOnly Then
If _BOF Or _EOF Then _PropertyGet = Null Else _PropertyGet = RowSet.getBookmark()
Else
_PropertyGet = Null
If _ForwardOnly Then Goto Trace_Forward
End If
Case UCase("EditMode")
If IsNull(RowSet) Then Goto Trace_Closed
_PropertyGet = _EditMode
Case UCase("EOF")
If IsNull(RowSet) Then Goto Trace_Closed
Select Case True
Case _BOF And _EOF : _PropertyGet = True
Case RowSet.isAfterLast() : _PropertyGet = True
Case Else : _PropertyGet = False
End Select
Case UCase("Filter")
If IsNull(RowSet) Then Goto Trace_Closed
_PropertyGet = RowSet.Filter
Case UCase("LastModified")
If IsNull(RowSet) Then Goto Trace_Closed
If RowSet.IsBookmarkable And Not _ForwardOnly Then
_PropertyGet = _BookmarkLastModified
Else
_PropertyGet = Null
If _ForwardOnly Then Goto Trace_Forward
End If
Case UCase("Name")
_PropertyGet = _Name
Case UCase("ObjectType")
_PropertyGet = _Type
Case UCase("RecordCount")
If IsNull(RowSet) Then Goto Trace_Closed
_PropertyGet = RowSet.RowCount
Case Else
Goto Trace_Error
End Select
Exit_Function:
Utils._ResetCalledSub(cstThisSub & psProperty)
Exit Function
Trace_Error:
TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(), 0, , psProperty)
_PropertyGet = vEMPTY
Goto Exit_Function
Trace_Forward:
TraceError(TRACEFATAL, ERRRECORDSETFORWARD, Utils._CalledSub(), 0)
Goto Exit_Function
Trace_Closed:
TraceError(TRACEFATAL, ERRRECORDSETCLOSED, Utils._CalledSub(), 0)
Goto Exit_Function
Error_Function:
TraceError(TRACEABORT, Err, cstThisSub & "._PropertyGet", Erl)
_PropertyGet = vEMPTY
GoTo Exit_Function
End Function ' _PropertyGet
REM -----------------------------------------------------------------------------------------------------------------------
Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
Dim cstThisSub As String
cstThisSub = "Recordset.set"
Utils._SetCalledSub(cstThisSub & psProperty)
If _ErrorHandler() Then On Local Error Goto Error_Function
_PropertySet = True
'Execute
Dim iArgNr As Integer
Dim oObject As Object
If Len(_A2B_.CalledSub) > 10 And Left(_A2B_.CalledSub, 10) = "Recordset." Then iArgNr = 1 Else iArgNr = 2
Select Case UCase(psProperty)
Case UCase("AbsolutePosition")
If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
If pvValue < 1 Then Goto Trace_Error_Value
_Move(pvValue, , True)
Case UCase("Bookmark")
If IsNull(RowSet) Then Goto Trace_Closed
_Move(0, pvValue)
Case UCase("Filter")
If IsNull(RowSet) Then Goto Trace_Closed
If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
_Filter = _ParentDatabase._ReplaceSquareBrackets(pvValue)
Case Else
Goto Trace_Error
End Select
Exit_Function:
Utils._ResetCalledSub(cstThisSub & psProperty)
Exit Function
Trace_Error:
TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(), 0, 1, psProperty)
_PropertySet = False
Goto Exit_Function
Trace_Error_Value:
TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(), 0, 1, Array(pvValue, psProperty))
_PropertySet = False
Goto Exit_Function
Trace_Closed:
TraceError(TRACEFATAL, ERRRECORDSETCLOSED, Utils._CalledSub(), 0)
Goto Exit_Function
Error_Function:
TraceError(TRACEABORT, Err, Utils._CalledSub(), Erl)
_PropertySet = False
GoTo Exit_Function
End Function ' _PropertySet
REM -----------------------------------------------------------------------------------------------------------------------
REM --- CLASS PROPERTY SETs ---
REM --- Workaround to bug https://www.libreoffice.org/bugzilla/show_bug.cgi?id=60752 (LibreOffice 4.0) ---
REM -----------------------------------------------------------------------------------------------------------------------
Property Set Bookmark(ByVal pvValue As Variant)
Call _PropertySet("Bookmark", pvValue)
End Property ' Bookmark (set)
Property Set Filter(ByVal pvValue As Variant)
Call _PropertySet("Filter", pvValue)
End Property ' Filter (set)
</script:module>
|