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=
"Field" script:
language=
"StarBasic">
4 REM =======================================================================================================================
5 REM === The Access2Base library is a part of the LibreOffice project. ===
6 REM === Full documentation is available on http://www.access2base.com ===
7 REM =======================================================================================================================
14 REM -----------------------------------------------------------------------------------------------------------------------
15 REM --- CLASS ROOT FIELDS ---
16 REM -----------------------------------------------------------------------------------------------------------------------
18 Private _Type As String
' Must be FIELD
19 Private _This As Object
' Workaround for absence of This builtin function
20 Private _Parent As Object
21 Private _Name As String
22 Private _Precision As Long
23 Private _ParentName As String
24 Private _ParentType As String
25 Private _ParentDatabase As Object
26 Private _ParentRecordset As Object
27 Private _DefaultValue As String
28 Private _DefaultValueSet As Boolean
29 Private Column As Object
' com.sun.star.sdb.OTableColumnWrapper
30 ' or org.openoffice.comp.dbaccess.OQueryColumn
31 ' or com.sun.star.sdb.ODataColumn
33 REM -----------------------------------------------------------------------------------------------------------------------
34 REM --- CONSTRUCTORS / DESTRUCTORS ---
35 REM -----------------------------------------------------------------------------------------------------------------------
36 Private Sub Class_Initialize()
41 _ParentName =
""
42 _ParentType =
""
43 _DefaultValue =
""
44 _DefaultValueSet = False
46 End Sub
' Constructor
48 REM -----------------------------------------------------------------------------------------------------------------------
49 Private Sub Class_Terminate()
50 On Local Error Resume Next
51 Call Class_Initialize()
52 End Sub
' Destructor
54 REM -----------------------------------------------------------------------------------------------------------------------
56 Call Class_Terminate()
57 End Sub
' Explicit destructor
59 REM -----------------------------------------------------------------------------------------------------------------------
60 REM --- CLASS GET/LET/SET PROPERTIES ---
61 REM -----------------------------------------------------------------------------------------------------------------------
63 Property Get DataType() As Long
' AOO/LibO type
64 DataType = _PropertyGet(
"DataType
")
65 End Property
' DataType (get)
67 Property Get DataUpdatable() As Boolean
68 DataUpdatable = _PropertyGet(
"DataUpdatable
")
69 End Property
' DataUpdatable (get)
71 REM -----------------------------------------------------------------------------------------------------------------------
72 Property Get DbType() As Long
' MSAccess type
73 DbType = _PropertyGet(
"DbType
")
74 End Property
' DbType (get)
76 REM -----------------------------------------------------------------------------------------------------------------------
77 Property Get DefaultValue() As Variant
78 DefaultValue = _PropertyGet(
"DefaultValue
")
79 End Property
' DefaultValue (get)
81 Property Let DefaultValue(ByVal pvDefaultValue As Variant)
82 Call _PropertySet(
"DefaultValue
", pvDefaultValue)
83 End Property
' DefaultValue (set)
85 REM -----------------------------------------------------------------------------------------------------------------------
86 Property Get Description() As Variant
87 Description = _PropertyGet(
"Description
")
88 End Property
' Description (get)
90 Property Let Description(ByVal pvDescription As Variant)
91 Call _PropertySet(
"Description
", pvDescription)
92 End Property
' Description (set)
94 REM -----------------------------------------------------------------------------------------------------------------------
95 Property Get FieldSize() As Long
96 FieldSize = _PropertyGet(
"FieldSize
")
97 End Property
' FieldSize (get)
99 REM -----------------------------------------------------------------------------------------------------------------------
100 Property Get Name() As String
101 Name = _PropertyGet(
"Name
")
102 End Property
' Name (get)
104 REM -----------------------------------------------------------------------------------------------------------------------
105 Property Get ObjectType() As String
106 ObjectType = _PropertyGet(
"ObjectType
")
107 End Property
' ObjectType (get)
109 REM -----------------------------------------------------------------------------------------------------------------------
110 Property Get Size() As Long
111 Size = _PropertyGet(
"Size
")
112 End Property
' Size (get)
114 REM -----------------------------------------------------------------------------------------------------------------------
115 Property Get SourceField() As String
116 SourceField = _PropertyGet(
"SourceField
")
117 End Property
' SourceField (get)
119 REM -----------------------------------------------------------------------------------------------------------------------
120 Property Get SourceTable() As String
121 SourceTable = _PropertyGet(
"SourceTable
")
122 End Property
' SourceTable (get)
124 REM -----------------------------------------------------------------------------------------------------------------------
125 Property Get TypeName() As String
126 TypeName = _PropertyGet(
"TypeName
")
127 End Property
' TypeName (get)
129 REM -----------------------------------------------------------------------------------------------------------------------
130 Property Get Value() As Variant
131 Value = _PropertyGet(
"Value
")
132 End Property
' Value (get)
134 Property Let Value(ByVal pvValue As Variant)
135 Call _PropertySet(
"Value
", pvValue)
136 End Property
' Value (set)
138 REM -----------------------------------------------------------------------------------------------------------------------
139 REM --- CLASS METHODS ---
140 REM -----------------------------------------------------------------------------------------------------------------------
142 REM -----------------------------------------------------------------------------------------------------------------------
143 Public Function AppendChunk(ByRef Optional pvValue As Variant) As Boolean
144 ' Store a chunk of string or binary characters into the current field, presumably a large object (CLOB or BLOB)
146 If _ErrorHandler() Then On Local Error Goto Error_Function
147 Const cstThisSub =
"Field.AppendChunk
"
148 Utils._SetCalledSub(cstThisSub)
151 If IsMissing(pvValue) Then Call _TraceArguments()
153 If _ParentType
<> OBJRECORDSET Then Goto Trace_Error
' Not on table- or querydefs ... !
154 If Not Column.IsWritable Then Goto Trace_Error_Updatable
155 If Column.IsReadOnly Then Goto Trace_Error_Updatable
156 If _ParentDatabase.Recordsets(_ParentName)._EditMode = dbEditNone Then Goto Trace_Error_Update
158 Dim iChunkType As Integer
160 With com.sun.star.sdbc.DataType
161 Select Case Column.Type
' DOES NOT WORK FOR CHARACTER TYPES
162 ' Case .CHAR, .VARCHAR, .LONGVARCHAR, .CLOB
163 ' iChunkType = vbString
164 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB, .CHAR
' .CHAR added for Sqlite3
171 AppendChunk = _ParentRecordset._AppendChunk(_Name, pvValue, iChunkType)
174 Utils._ResetCalledSub(cstThisSub)
177 TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(),
0,
1)
180 Trace_Error_Updatable:
181 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(),
0,
1)
185 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , cstThisSub)
188 TraceError(TRACEABORT, Err, cstThisSub, Erl)
191 End Function
' AppendChunk V1.5
.0
193 REM -----------------------------------------------------------------------------------------------------------------------
194 Public Function GetChunk(ByVal Optional pvOffset As Variant, ByVal Optional pvBytes As Variant) As Variant
195 ' Get a chunk of string or binary characters from the current field, presumably a large object (CLOB or BLOB)
197 If _ErrorHandler() Then On Local Error Goto Error_Function
198 Const cstThisSub =
"Field.GetChunk
"
199 Utils._SetCalledSub(cstThisSub)
201 Dim oValue As Object, bNullable As Boolean, bNull As Boolean, vValue() As Variant
202 Dim lLength As Long, lOffset As Long, lValue As Long
204 If IsMissing(pvOffset) Or IsMissing(pvBytes) Then Call _TraceArguments()
205 If Not Utils._CheckArgument(pvOffset,
1, _AddNumeric()) Then Goto Exit_Function
206 If pvOffset
< 0 Then
207 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(
1, pvOffset))
210 If Not Utils._CheckArgument(pvBytes,
2, _AddNumeric()) Then Goto Exit_Function
211 If pvBytes
< 0 Then
212 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(
2, pvBytes))
216 bNullable = ( Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE )
220 With com.sun.star.sdbc.DataType
221 Select Case Column.Type
' DOES NOT WORK FOR CHARACTER TYPES
222 ' Case .CHAR, .VARCHAR, .LONGVARCHAR
223 ' Set oValue = Column.getCharacterStream()
225 ' Set oValue = Column.getClob.getCharacterStream()
226 Case .BINARY, .VARBINARY, .LONGVARBINARY
227 Set oValue = Column.getBinaryStream()
229 Set oValue = Column.getBlob.getBinaryStream()
233 If bNullable Then bNull = Column.wasNull()
235 lOffset = CLng(pvOffset)
236 If lOffset
> 0 Then oValue.skipBytes(lOffset)
237 lValue = oValue.readBytes(vValue, pvBytes)
244 Utils._ResetCalledSub(cstThisSub)
247 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , cstThisSub)
250 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(iArg, pvIndex))
254 TraceError(TRACEABORT, Err, cstThisSub, Erl)
256 End Function
' GetChunk V1.5
.0
258 REM -----------------------------------------------------------------------------------------------------------------------
259 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
260 ' Return property value of psProperty property name
262 Const cstThisSub =
"Field.getProperty
"
263 Utils._SetCalledSub(cstThisSub)
264 If IsMissing(pvProperty) Then Call _TraceArguments()
265 getProperty = _PropertyGet(pvProperty)
266 Utils._ResetCalledSub(cstThisSub)
268 End Function
' getProperty
270 REM -----------------------------------------------------------------------------------------------------------------------
271 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
272 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
274 Const cstThisSub =
"Field.hasProperty
"
275 Utils._SetCalledSub(cstThisSub)
276 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
277 Utils._ResetCalledSub(cstThisSub)
280 End Function
' hasProperty
282 REM -----------------------------------------------------------------------------------------------------------------------
283 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
285 ' a Collection object if pvIndex absent
286 ' a Property object otherwise
288 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String, sName As String
289 Const cstThisSub =
"Field.Properties
"
290 Utils._SetCalledSub(cstThisSub)
291 vPropertiesList = _PropertiesList()
292 sObject = Utils._PCase(_Type)
293 sName = _ParentType
& "/
" & _ParentName
& "/
" & _Name
294 If IsMissing(pvIndex) Then
295 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList)
297 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList, pvIndex)
298 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
299 Set vProperty._ParentDatabase = _ParentDatabase
303 Set Properties = vProperty
304 Utils._ResetCalledSub(cstThisSub)
306 End Function
' Properties
308 REM -----------------------------------------------------------------------------------------------------------------------
309 Public Function ReadAllBytes(ByVal Optional pvFile As Variant) As Boolean
310 ' Read the whole content of a file into Long Binary Field object
312 Const cstThisSub =
"Field.ReadAllBytes
"
313 Utils._SetCalledSub(cstThisSub)
314 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
315 ReadAllBytes = _ReadAll(pvFile,
"ReadAllBytes
")
318 Utils._ResetCalledSub(cstThisSub)
320 End Function
' ReadAllBytes
322 REM -----------------------------------------------------------------------------------------------------------------------
323 Public Function ReadAllText(ByVal Optional pvFile As Variant) As Boolean
324 ' Read the whole content of a file into a Long Char Field object
326 Const cstThisSub =
"Field.ReadAllText
"
327 Utils._SetCalledSub(cstThisSub)
328 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
329 ReadAllText = _ReadAll(pvFile,
"ReadAllText
")
332 Utils._ResetCalledSub(cstThisSub)
334 End Function
' ReadAllText
336 REM -----------------------------------------------------------------------------------------------------------------------
337 Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
338 ' Return True if property setting OK
339 Const cstThisSub =
"Field.setProperty
"
340 Utils._SetCalledSub(cstThisSub)
341 setProperty = _PropertySet(psProperty, pvValue)
342 Utils._ResetCalledSub(cstThisSub)
345 REM -----------------------------------------------------------------------------------------------------------------------
346 Public Function WriteAllBytes(ByVal Optional pvFile As Variant) As Boolean
347 ' Write the whole content of a Long Binary Field object to a file
349 Const cstThisSub =
"Field.WriteAllBytes
"
350 Utils._SetCalledSub(cstThisSub)
351 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
352 WriteAllBytes = _WriteAll(pvFile,
"WriteAllBytes
")
355 Utils._ResetCalledSub(cstThisSub)
357 End Function
' WriteAllBytes
359 REM -----------------------------------------------------------------------------------------------------------------------
360 Public Function WriteAllText(ByVal Optional pvFile As Variant) As Boolean
361 ' Write the whole content of a Long Char Field object to a file
363 Const cstThisSub =
"Field.WriteAllText
"
364 Utils._SetCalledSub(cstThisSub)
365 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
366 WriteAllText = _WriteAll(pvFile,
"WriteAllText
")
369 Utils._ResetCalledSub(cstThisSub)
371 End Function
' WriteAllText
373 REM -----------------------------------------------------------------------------------------------------------------------
374 REM --- PRIVATE FUNCTIONS ---
375 REM -----------------------------------------------------------------------------------------------------------------------
377 REM -----------------------------------------------------------------------------------------------------------------------
378 Private Function _PropertiesList() As Variant
380 Select Case _ParentType
382 _PropertiesList =Array(
"DataType
",
"dbType
",
"DefaultValue
" _
383 ,
"Description
",
"Name
",
"ObjectType
",
"Size
",
"SourceField
",
"SourceTable
" _
384 ,
"TypeName
" _
387 _PropertiesList = Array(
"DataType
",
"dbType
",
"DefaultValue
" _
388 ,
"Description
",
"Name
",
"ObjectType
",
"Size
",
"SourceField
",
"SourceTable
" _
389 ,
"TypeName
" _
392 _PropertiesList = Array(
"DataType
",
"DataUpdatable
",
"dbType
",
"DefaultValue
" _
393 ,
"Description
" ,
"FieldSize
",
"Name
",
"ObjectType
" _
394 ,
"Size
",
"SourceTable
",
"TypeName
",
"Value
" _
398 End Function
' _PropertiesList
400 REM -----------------------------------------------------------------------------------------------------------------------
401 Private Function _PropertyGet(ByVal psProperty As String) As Variant
402 ' Return property value of the psProperty property name
404 If _ErrorHandler() Then On Local Error Goto Error_Function
405 Dim cstThisSub As String
406 cstThisSub =
"Field.get
" & psProperty
407 Utils._SetCalledSub(cstThisSub)
409 If Not hasProperty(psProperty) Then Goto Trace_Error
411 Dim bCond1 As Boolean, bCond2 As Boolean, vValue As Variant, oValue As Object, sValue As String
412 Dim oSize As Object, lSize As Long, bNullable As Boolean, bNull As Boolean
413 Const cstMaxBinlength =
2 *
65535
417 Select Case UCase(psProperty)
418 Case UCase(
"DataType
")
419 _PropertyGet = Column.Type
420 Case UCase(
"DbType
")
421 With com.sun.star.sdbc.DataType
422 Select Case Column.Type
423 Case .BIT : _PropertyGet = dbBoolean
424 Case .TINYINT : _PropertyGet = dbInteger
425 Case .SMALLINT : _PropertyGet = dbLong
426 Case .INTEGER : _PropertyGet = dbLong
427 Case .BIGINT : _PropertyGet = dbBigInt
428 Case .FLOAT : _PropertyGet = dbFloat
429 Case .REAL : _PropertyGet = dbSingle
430 Case .DOUBLE : _PropertyGet = dbDouble
431 Case .NUMERIC : _PropertyGet = dbNumeric
432 Case .DECIMAL : _PropertyGet = dbDecimal
433 Case .CHAR : _PropertyGet = dbChar
434 Case .VARCHAR : _PropertyGet = dbText
435 Case .LONGVARCHAR : _PropertyGet = dbMemo
436 Case .CLOB : _PropertyGet = dbMemo
437 Case .DATE : _PropertyGet = dbDate
438 Case .TIME : _PropertyGet = dbTime
439 Case .TIMESTAMP : _PropertyGet = dbTimeStamp
440 Case .BINARY : _PropertyGet = dbBinary
441 Case .VARBINARY : _PropertyGet = dbVarBinary
442 Case .LONGVARBINARY : _PropertyGet = dbLongBinary
443 Case .BLOB : _PropertyGet = dbLongBinary
444 Case .BOOLEAN : _PropertyGet = dbBoolean
445 Case Else : _PropertyGet = dbUndefined
448 Case UCase(
"DataUpdatable
")
449 If Utils._hasUNOProperty(Column,
"IsWritable
") Then
450 _PropertyGet = Column.IsWritable
451 ElseIf Utils._hasUNOProperty(Column,
"IsReadOnly
") Then
452 _PropertyGet = Not Column.IsReadOnly
453 ElseIf Utils._hasUNOProperty(Column,
"IsDefinitelyWritable
") Then
454 _PropertyGet = Column.IsDefinitelyWritable
458 If Utils._hasUNOProperty(Column,
"IsAutoIncrement
") Then
459 If Column.IsAutoIncrement Then _PropertyGet = False
' Forces False if auto-increment (MSAccess)
461 Case UCase(
"DefaultValue
")
462 ' default value buffered to avoid multiple calls
463 If Not _DefaultValueSet Then
464 If Utils._hasUNOProperty(Column,
"DefaultValue
") Then
' Default value in database set via SQL statement
465 _DefaultValue = Column.DefaultValue
466 ElseIf Utils._hasUNOProperty(Column,
"ControlDefault
") Then
' Default value set in Base via table edition
467 If IsEmpty(Column.ControlDefault) Then _DefaultValue =
"" Else _DefaultValue = Column.ControlDefault
469 _DefaultValue =
""
471 _DefaultValueSet = True
473 _PropertyGet = _DefaultValue
474 Case UCase(
"Description
")
475 bCond1 = Utils._hasUNOProperty(Column,
"Description
")
476 bCond2 = Utils._hasUNOProperty(Column,
"HelpText
")
478 Case ( bCond1 And bCond2 )
479 If IsEmpty(Column.HelpText) Then _PropertyGet = Column.Description Else _PropertyGet = Column.HelpText
480 Case ( bCond1 And ( Not bCond2 ) )
481 _PropertyGet = Column.Description
482 Case ( ( Not bCond1 ) And bCond2 )
483 _PropertyGet = Column.HelpText
485 _PropertyGet =
""
487 Case UCase(
"FieldSize
")
488 With com.sun.star.sdbc.DataType
489 Select Case Column.Type
490 Case .VARCHAR, .LONGVARCHAR, .CLOB
491 Set oSize = Column.getCharacterStream
492 Case .LONGVARBINARY, .VARBINARY, .BINARY, .BLOB
493 Set oSize = Column.getBinaryStream
498 If Not IsNull(oSize) Then
499 bNullable = ( Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE )
501 If Column.wasNull() Then _PropertyGet =
0 Else _PropertyGet = CLng(oSize.getLength())
503 _PropertyGet = CLng(oSize.getLength())
509 Case UCase(
"Name
")
511 Case UCase(
"ObjectType
")
513 Case UCase(
"Size
")
514 With com.sun.star.sdbc.DataType
515 Select Case Column.Type
516 Case .LONGVARCHAR, .LONGVARBINARY, .VARBINARY, .BINARY, .BLOB, .CLOB
517 _PropertyGet =
0 ' Always
0 (MSAccess)
519 If Utils._hasUNOProperty(Column,
"Precision
") Then _PropertyGet = Column.Precision Else _PropertyGet =
0
522 Case UCase(
"SourceField
")
523 Select Case _ParentType
526 Case OBJQUERYDEF
' RealName = not documented ?!?
527 If Utils._hasUNOProperty(Column,
"RealName
") Then _PropertyGet = Column.RealName Else _PropertyGet = _Name
529 Case UCase(
"SourceTable
")
530 Select Case _ParentType
532 _PropertyGet = _ParentName
533 Case OBJQUERYDEF, OBJRECORDSET
534 _PropertyGet = Column.TableName
536 Case UCase(
"TypeName
")
537 _PropertyGet = Column.TypeName
538 Case UCase(
"Value
")
539 bNullable = ( Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE )
541 With com.sun.star.sdbc.DataType
542 Select Case Column.Type
543 Case .BIT, .BOOLEAN : vValue = Column.getBoolean()
' vbBoolean
544 Case .TINYINT : vValue = Column.getShort()
' vbInteger
545 Case .SMALLINT, .INTEGER: vValue = Column.getInt()
' vbLong
546 Case .BIGINT : vValue = Column.getLong()
' vbBigint
547 Case .FLOAT : vValue = Column.getFloat()
' vbSingle
548 Case .REAL, .DOUBLE : vValue = Column.getDouble()
' vbDouble
549 Case .NUMERIC, .DECIMAL
550 If Utils._hasUNOProperty(Column,
"Scale
") Then
551 If Column.Scale
> 0 Then
552 vValue = Column.getDouble()
553 Else
' Try Long otherwise Double (CDec not implemented anymore in LO ?!?)
554 On Local Error Resume Next
' Avoid overflow error
555 ' CLng checks local decimal point, getString does not !
556 sValue = Join(Split(Column.getString(),
".
"), Utils._DecimalPoint())
557 vValue = CLng(sValue)
558 If Err
<> 0 Then
559 vValue = CDbl(sValue)
561 On Local Error Goto Error_Function
565 vValue = CDbl(Column.getString())
567 Case .CHAR : vValue = Column.getString()
568 Case .VARCHAR : vValue = Column.getString()
' vbString
569 Case .LONGVARCHAR, .CLOB
570 Set oValue = Column.getCharacterStream()
571 If bNullable Then bNull = Column.wasNull()
573 lSize = CLng(oValue.getLength())
575 vValue = Column.getString()
' vbString
579 Case .DATE : Set oValue = Column.getDate()
' vbObject with members VarType Unsigned Short =
18
580 If bNullable Then bNull = Column.wasNull()
581 If Not bNull Then vValue = DateSerial(CInt(oValue.Year), CInt(oValue.Month), CInt(oValue.Day))
582 Case .TIME : Set oValue = Column.getTime()
' vbObject with members VarType Unsigned Short =
18
583 If bNullable Then bNull = Column.wasNull()
584 If Not bNull Then vValue = TimeSerial(oValue.Hours, oValue.Minutes, oValue.Seconds)
', oValue.HundredthSeconds)
585 Case .TIMESTAMP : Set oValue = Column.getTimeStamp()
586 If bNullable Then bNull = Column.wasNull()
587 If Not bNull Then vValue = DateSerial(CInt(oValue.Year), CInt(oValue.Month), CInt(oValue.Day)) _
588 + TimeSerial(oValue.Hours, oValue.Minutes, oValue.Seconds)
', oValue.HundredthSeconds)
589 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
590 Set oValue = Column.getBinaryStream()
591 If bNullable Then bNull = Column.wasNull()
593 lSize = CLng(oValue.getLength())
' vbLong =
> equivalent to FieldSize
594 If lSize
> cstMaxBinlength Then Goto Trace_Length
596 oValue.readBytes(vValue, lSize)
600 vValue = Column.getString()
'GIVE STRING A TRY
601 If IsNumeric(vValue) Then vValue = Val(vValue)
'Required when type =
"", sometimes numeric fields are returned as strings (query/MSAccess)
604 If Column.wasNull() Then vValue = Null
'getXXX must precede wasNull()
607 _PropertyGet = vValue
613 Utils._ResetCalledSub(cstThisSub)
616 TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
620 TraceError(TRACEFATAL, ERROVERFLOW, Utils._CalledSub(),
0, , Array(lSize,
"GetChunk
"))
624 TraceError(TRACEABORT, Err, cstThisSub, Erl)
627 End Function
' _PropertyGet V1.1
.0
629 REM -----------------------------------------------------------------------------------------------------------------------
630 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
631 ' Return True if property setting OK
633 If _ErrorHandler() Then On Local Error Goto Error_Function
634 Dim cstThisSub As String
635 cstThisSub =
"Field.set
" & psProperty
636 Utils._SetCalledSub(cstThisSub)
638 Dim iArgNr As Integer, vTemp As Variant
639 Dim oParent As Object
641 Select Case UCase(_A2B_.CalledSub)
642 Case UCase(
"setProperty
") : iArgNr =
3
643 Case UCase(
"Field.setProperty
") : iArgNr =
2
644 Case UCase(cstThisSub) : iArgNr =
1
647 If Not hasProperty(psProperty) Then Goto Trace_Error
649 Select Case UCase(psProperty)
650 Case UCase(
"DefaultValue
")
651 If _ParentType
<> OBJTABLEDEF Then Goto Trace_Error
652 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
653 If Utils._hasUNOProperty(Column,
"ControlDefault
") Then
' Default value set in Base via table edition
654 Column.ControlDefault = pvValue
655 _DefaultValue = pvValue
656 _DefaultValueSet = True
658 Case UCase(
"Description
")
659 If _ParentType
<> OBJTABLEDEF Then Goto Trace_Error
660 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
661 Column.HelpText = pvValue
662 Case UCase(
"Value
")
663 If _ParentType
<> OBJRECORDSET Then Goto Trace_Error
' Not on table- or querydefs ... !
664 If Not Column.IsWritable Then Goto Trace_Error_Updatable
665 If Column.IsReadOnly Then Goto Trace_Error_Updatable
666 If _ParentDatabase.Recordsets(_ParentName)._EditMode = dbEditNone Then Goto Trace_Error_Update
667 With com.sun.star.sdbc.DataType
668 If IsNull(pvValue) Then
669 If Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE Then Column.updateNull() Else Goto Trace_Null
671 Select Case Column.Type
673 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
674 Column.updateBoolean(pvValue)
676 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
677 If pvValue
< -
128 Or pvValue
> +
127 Then Goto Trace_Error_Value
678 Column.updateShort(CInt(pvValue))
680 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
681 If pvValue
< -
32768 Or pvValue
> 32767 Then Goto trace_Error_Value
682 Column.updateInt(CLng(pvValue))
684 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
685 If pvValue
< -
2147483648 Or pvValue
> 2147483647 Then Goto trace_Error_Value
686 Column.updateInt(CLng(pvValue))
688 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
689 Column.updateLong(pvValue)
' No proper type conversion for HYPER data type
691 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
692 If Abs(pvValue)
< 3.402823E38 And Abs(pvValue)
> 1.401298E-45 Then Column.updateFloat(CSng(pvValue)) Else Goto trace_Error_Value
694 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
695 'If Abs(pvValue)
< 1.79769313486232E308 And Abs(pvValue)
> 4.94065645841247E-307 Then Column.updateDouble(CDbl(pvValue)) Else Goto trace_Error_Value
696 Column.updateDouble(CDbl(pvValue))
697 Case .NUMERIC, .DECIMAL
698 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
699 If Utils._hasUNOProperty(Column,
"Scale
") Then
700 If Column.Scale
> 0 Then
701 'If Abs(pvValue)
< 1.79769313486232E308 And Abs(pvValue)
> 4.94065645841247E-307 Then Column.updateDouble(CDbl(pvValue)) Else Goto trace_Error_Value
702 Column.updateDouble(CDbl(pvValue))
704 Column.updateString(CStr(pvValue))
707 Column.updateString(CStr(pvValue))
709 Case .CHAR, .VARCHAR, .LONGVARCHAR, .CLOB
710 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
711 If _Precision
> 0 And Len(pvValue)
> _Precision Then Goto Trace_Error_Length
712 Column.updateString(pvValue)
' vbString
714 If Not Utils._CheckArgument(pvValue, iArgNr, vbDate, , False) Then Goto Trace_Error_Value
715 vTemp = New com.sun.star.util.Date
718 .Month = Month(pvValue)
719 .Year = Year(pvValue)
721 Column.updateDate(vTemp)
723 If Not Utils._CheckArgument(pvValue, iArgNr, vbDate, , False) Then Goto Trace_Error_Value
724 vTemp = New com.sun.star.util.Time
726 .Hours = Hour(pvValue)
727 .Minutes = Minute(pvValue)
728 .Seconds = Second(pvValue)
729 '.HundredthSeconds =
0 ' replaced with Long nanoSeconds in LO
4.1 ??
731 Column.updateTime(vTemp)
733 If Not Utils._CheckArgument(pvValue, iArgNr, vbDate, , False) Then Goto Trace_Error_Value
734 vTemp = New com.sun.star.util.DateTime
737 .Month = Month(pvValue)
738 .Year = Year(pvValue)
739 .Hours = Hour(pvValue)
740 .Minutes = Minute(pvValue)
741 .Seconds = Second(pvValue)
742 '.HundredthSeconds =
0
744 Column.updateTimestamp(vTemp)
745 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
746 If Not IsArray(pvValue) Then Goto Trace_Error_Value
747 If UBound(pvValue)
< LBound(pvValue) Then Goto Trace_Error_Value
748 If Not Utils._CheckArgument(pvValue(LBound(pvValue)), iArgNr, vbInteger, , False) Then Goto Trace_Error_Value
749 Column.updateBytes(pvValue)
760 Utils._ResetCalledSub(cstThisSub)
763 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
767 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
771 TraceError(TRACEFATAL, ERRNOTNULLABLE, Utils._CalledSub(),
0,
1, _Name)
775 TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(),
0,
1)
778 Trace_Error_Updatable:
779 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(),
0,
1)
783 TraceError(TRACEFATAL, ERROVERFLOW, Utils._CalledSub(),
0, , Array(Len(pvValue),
"AppendChunk
"))
787 TraceError(TRACEABORT, Err, cstThisSub, Erl)
790 End Function
' _PropertySet
792 REM -----------------------------------------------------------------------------------------------------------------------
793 Public Function _ReadAll(ByVal psFile As String, ByVal psMethod As String) As Boolean
794 ' Write the whole content of a file into a stream object
796 If _ErrorHandler() Then On Local Error Goto Error_Function
799 If _ParentType
<> OBJRECORDSET Then Goto Trace_Error
' Not on table- or querydefs ... !
800 If Not Column.IsWritable Then Goto Trace_Error_Updatable
801 If Column.IsReadOnly Then Goto Trace_Error_Updatable
802 If _ParentDatabase.Recordsets(_ParentName)._EditMode = dbEditNone Then Goto Trace_Error_Update
804 Dim sFile As String, oSimpleFileAccess As Object, sMethod As String, oStream As Object
805 Dim lFileLength As Long, sBuffer As String, sMemo As String, iFile As Integer
806 Const cstMaxLength =
64000
807 sFile = ConvertToURL(psFile)
809 oSimpleFileAccess = CreateUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
810 If Not oSimpleFileAccess.exists(sFile) Then Goto Trace_File
812 With com.sun.star.sdbc.DataType
813 Select Case Column.Type
814 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
815 If psMethod
<> "ReadAllBytes
" Then Goto Trace_Error
816 Set oStream = oSimpleFileAccess.openFileRead(sFile)
817 lFileLength = oStream.getLength()
818 If lFileLength =
0 Then Goto Trace_File
819 Column.updateBinaryStream(oStream, lFileLength)
821 Case .VARCHAR, .LONGVARCHAR, .CLOB
822 If psMethod
<> "ReadAllText
" Then Goto Trace_Error
826 Open sFile For Input Access Read Shared As iFile
827 Do While Not Eof(iFile)
828 Line Input #iFile, sBuffer
829 lFileLength = lFileLength + Len(sBuffer) +
1
830 If lFileLength
> cstMaxLength Then Exit Do
831 sMemo = sMemo
& sBuffer
& vbNewLine
833 If lFileLength =
0 Or lFileLength
> cstMaxLength Then
837 sMemo = Left(sMemo, lFileLength -
1)
838 Column.updateString(sMemo)
839 'Column.updateCharacterStream(oStream, lFileLength)
' DOES NOT WORK ?!?
850 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , psMethod)
853 TraceError(TRACEFATAL, ERRFILEACCESS, Utils._CalledSub(),
0, , sFile)
854 If Not IsNull(oStream) Then oStream.closeInput()
857 TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(),
0,
1)
858 If Not IsNull(oStream) Then oStream.closeInput()
860 Trace_Error_Updatable:
861 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(),
0,
1)
862 If Not IsNull(oStream) Then oStream.closeInput()
865 TraceError(TRACEABORT, Err, _CalledSub, Erl)
867 End Function
' ReadAll
869 REM -----------------------------------------------------------------------------------------------------------------------
870 Public Function _WriteAll(ByVal psFile As String, ByVal psMethod As String) As Boolean
871 ' Write the whole content of a stream object to a file
873 If _ErrorHandler() Then On Local Error Goto Error_Function
876 Dim sFile As String, oSimpleFileAccess As Object, sMethod As String, oStream As Object
877 sFile = ConvertToURL(psFile)
879 oSimpleFileAccess = CreateUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
880 With com.sun.star.sdbc.DataType
881 Select Case Column.Type
882 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
883 If psMethod
<> "WriteAllBytes
" Then Goto Trace_Error
884 Set oStream = Column.getBinaryStream()
885 Case .VARCHAR, .LONGVARCHAR, .CLOB
886 If psMethod
<> "WriteAllText
" Then Goto Trace_Error
887 Set oStream = Column.getCharacterStream()
893 If Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE Then
894 If Column.wasNull() Then Goto Trace_Null
896 If oStream.getLength() =
0 Then Goto Trace_Null
897 On Local Error Goto Trace_File
898 If oSimpleFileAccess.exists(sFile) Then oSimpleFileAccess.kill(sFile)
899 oSimpleFileAccess.writeFile(sFile, oStream)
900 On Local Error Goto Error_Function
908 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , psMethod)
911 TraceError(TRACEFATAL, ERRFILEACCESS, Utils._CalledSub(),
0, , sFile)
912 If Not IsNull(oStream) Then oStream.closeInput()
915 TraceError(TRACEFATAL, ERRFIELDNULL, _CalledSub,
0)
916 If Not IsNull(oStream) Then oStream.closeInput()
919 TraceError(TRACEABORT, Err, _CalledSub, Erl)
921 End Function
' WriteAll