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">REM =======================================================================================================================
4 REM === The Access2Base library is a part of the LibreOffice project. ===
5 REM === Full documentation is available on http://www.access2base.com ===
6 REM =======================================================================================================================
13 REM -----------------------------------------------------------------------------------------------------------------------
14 REM --- CLASS ROOT FIELDS ---
15 REM -----------------------------------------------------------------------------------------------------------------------
17 Private _Type As String
' Must be FIELD
18 Private _Name As String
19 Private _ParentName As String
20 Private _ParentType As String
21 Private _ParentDatabase As Object
22 Private _ParentRecordset As Object
23 Private Column As Object
' com.sun.star.sdb.OTableColumnWrapper
24 ' or org.openoffice.comp.dbaccess.OQueryColumn
25 ' or com.sun.star.sdb.ODataColumn
27 REM -----------------------------------------------------------------------------------------------------------------------
28 REM --- CONSTRUCTORS / DESTRUCTORS ---
29 REM -----------------------------------------------------------------------------------------------------------------------
30 Private Sub Class_Initialize()
33 _ParentName =
""
34 _ParentType =
""
36 End Sub
' Constructor
38 REM -----------------------------------------------------------------------------------------------------------------------
39 Private Sub Class_Terminate()
40 On Local Error Resume Next
41 Call Class_Initialize()
42 End Sub
' Destructor
44 REM -----------------------------------------------------------------------------------------------------------------------
46 Call Class_Terminate()
47 End Sub
' Explicit destructor
49 REM -----------------------------------------------------------------------------------------------------------------------
50 REM --- CLASS GET/LET/SET PROPERTIES ---
51 REM -----------------------------------------------------------------------------------------------------------------------
53 Property Get DataType() As Long
' AOO/LibO type
54 DataType = _PropertyGet(
"DataType
")
55 End Property
' DataType (get)
57 Property Get DataUpdatable() As Boolean
58 DataUpdatable = _PropertyGet(
"DataUpdatable
")
59 End Property
' DataUpdatable (get)
61 REM -----------------------------------------------------------------------------------------------------------------------
62 Property Get DbType() As Long
' MSAccess type
63 DbType = _PropertyGet(
"DbType
")
64 End Property
' DbType (get)
66 REM -----------------------------------------------------------------------------------------------------------------------
67 Property Get DefaultValue() As Variant
68 DefaultValue = _PropertyGet(
"DefaultValue
")
69 End Property
' DefaultValue (get)
71 Property Let DefaultValue(ByVal pvDefaultValue As Variant)
72 Call _PropertySet(
"DefaultValue
", pvDefaultValue)
73 End Property
' DefaultValue (set)
75 REM -----------------------------------------------------------------------------------------------------------------------
76 Property Get Description() As Variant
77 Description = _PropertyGet(
"Description
")
78 End Property
' Description (get)
80 Property Let Description(ByVal pvDescription As Variant)
81 Call _PropertySet(
"Description
", pvDescription)
82 End Property
' Description (set)
84 REM -----------------------------------------------------------------------------------------------------------------------
85 Property Get FieldSize() As Long
86 FieldSize = _PropertyGet(
"FieldSize
")
87 End Property
' FieldSize (get)
89 REM -----------------------------------------------------------------------------------------------------------------------
90 Property Get Name() As String
91 Name = _PropertyGet(
"Name
")
92 End Property
' Name (get)
94 REM -----------------------------------------------------------------------------------------------------------------------
95 Property Get ObjectType() As String
96 ObjectType = _PropertyGet(
"ObjectType
")
97 End Property
' ObjectType (get)
99 REM -----------------------------------------------------------------------------------------------------------------------
100 Property Get Size() As Long
101 Size = _PropertyGet(
"Size
")
102 End Property
' Size (get)
104 REM -----------------------------------------------------------------------------------------------------------------------
105 Property Get SourceField() As String
106 SourceField = _PropertyGet(
"SourceField
")
107 End Property
' SourceField (get)
109 REM -----------------------------------------------------------------------------------------------------------------------
110 Property Get SourceTable() As String
111 SourceTable = _PropertyGet(
"SourceTable
")
112 End Property
' SourceTable (get)
114 REM -----------------------------------------------------------------------------------------------------------------------
115 Property Get TypeName() As String
116 TypeName = _PropertyGet(
"TypeName
")
117 End Property
' TypeName (get)
119 REM -----------------------------------------------------------------------------------------------------------------------
120 Property Get Value() As Variant
121 Value = _PropertyGet(
"Value
")
122 End Property
' Value (get)
124 Property Let Value(ByVal pvValue As Variant)
125 Call _PropertySet(
"Value
", pvValue)
126 End Property
' Value (set)
128 REM -----------------------------------------------------------------------------------------------------------------------
129 REM --- CLASS METHODS ---
130 REM -----------------------------------------------------------------------------------------------------------------------
132 REM -----------------------------------------------------------------------------------------------------------------------
133 Public Function AppendChunk(ByRef Optional pvValue As Variant) As Boolean
134 ' Store a chunk of string or binary characters into the current field, presumably a large object (CLOB or BLOB)
136 If _ErrorHandler() Then On Local Error Goto Error_Function
137 Const cstThisSub =
"Field.AppendChunk
"
138 Utils._SetCalledSub(cstThisSub)
141 If IsMissing(pvValue) Then Call _TraceArguments()
143 If _ParentType
<> OBJRECORDSET Then Goto Trace_Error
' Not on table- or querydefs ... !
144 If Not Column.IsWritable Then Goto Trace_Error_Updatable
145 If Column.IsReadOnly Then Goto Trace_Error_Updatable
146 If _ParentDatabase.Recordsets(_ParentName)._EditMode = dbEditNone Then Goto Trace_Error_Update
148 Dim iChunkType As Integer
150 With com.sun.star.sdbc.DataType
151 Select Case Column.Type
' DOES NOT WORK FOR CHARACTER TYPES
152 ' Case .CHAR, .VARCHAR, .LONGVARCHAR, .CLOB
153 ' iChunkType = vbString
154 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB, .CHAR
' .CHAR added for Sqlite3
161 AppendChunk = _ParentRecordset._AppendChunk(_Name, pvValue, iChunkType)
164 Utils._ResetCalledSub(cstThisSub)
167 TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(),
0,
1)
170 Trace_Error_Updatable:
171 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(),
0,
1)
175 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , cstThisSub)
178 TraceError(TRACEABORT, Err, cstThisSub, Erl)
181 End Function
' AppendChunk V1.5
.0
183 REM -----------------------------------------------------------------------------------------------------------------------
184 Public Function GetChunk(ByVal Optional pvOffset As Variant, ByVal Optional pvBytes As Variant) As Variant
185 ' Get a chunk of string or binary characters from the current field, presumably a large object (CLOB or BLOB)
187 If _ErrorHandler() Then On Local Error Goto Error_Function
188 Const cstThisSub =
"Field.GetChunk
"
189 Utils._SetCalledSub(cstThisSub)
191 Dim oValue As Object, bNullable As Boolean, bNull As Boolean, vValue() As Variant
192 Dim lLength As Long, lOffset As Long, lValue As Long
194 If IsMissing(pvOffset) Or IsMissing(pvBytes) Then Call _TraceArguments()
195 If Not Utils._CheckArgument(pvOffset,
1, _AddNumeric()) Then Goto Exit_Function
196 If pvOffset
< 0 Then
197 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(
1, pvOffset))
200 If Not Utils._CheckArgument(pvBytes,
2, _AddNumeric()) Then Goto Exit_Function
201 If pvBytes
< 0 Then
202 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(
2, pvBytes))
206 bNullable = ( Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE )
210 With com.sun.star.sdbc.DataType
211 Select Case Column.Type
' DOES NOT WORK FOR CHARACTER TYPES
212 ' Case .CHAR, .VARCHAR, .LONGVARCHAR
213 ' Set oValue = Column.getCharacterStream()
215 ' Set oValue = Column.getClob.getCharacterStream()
216 Case .BINARY, .VARBINARY, .LONGVARBINARY
217 Set oValue = Column.getBinaryStream()
219 Set oValue = Column.getBlob.getBinaryStream()
223 If bNullable Then bNull = Column.wasNull()
225 lOffset = CLng(pvOffset)
226 If lOffset
> 0 Then oValue.skipBytes(lOffset)
227 lValue = oValue.readBytes(vValue, pvBytes)
234 Utils._ResetCalledSub(cstThisSub)
237 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , cstThisSub)
240 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(iArg, pvIndex))
244 TraceError(TRACEABORT, Err, cstThisSub, Erl)
246 End Function
' GetChunk V1.5
.0
248 REM -----------------------------------------------------------------------------------------------------------------------
249 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
250 ' Return property value of psProperty property name
252 Const cstThisSub =
"Field.getProperty
"
253 Utils._SetCalledSub(cstThisSub)
254 If IsMissing(pvProperty) Then Call _TraceArguments()
255 getProperty = _PropertyGet(pvProperty)
256 Utils._ResetCalledSub(cstThisSub)
258 End Function
' getProperty
260 REM -----------------------------------------------------------------------------------------------------------------------
261 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
262 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
264 Const cstThisSub =
"Field.hasProperty
"
265 Utils._SetCalledSub(cstThisSub)
266 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
267 Utils._ResetCalledSub(cstThisSub)
270 End Function
' hasProperty
272 REM -----------------------------------------------------------------------------------------------------------------------
273 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
275 ' a Collection object if pvIndex absent
276 ' a Property object otherwise
278 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String, sName As String
279 Const cstThisSub =
"Field.Properties
"
280 Utils._SetCalledSub(cstThisSub)
281 vPropertiesList = _PropertiesList()
282 sObject = Utils._PCase(_Type)
283 sName = _ParentType
& "/
" & _ParentName
& "/
" & _Name
284 If IsMissing(pvIndex) Then
285 vProperty = PropertiesGet._Properties(sObject, sName, vPropertiesList)
287 vProperty = PropertiesGet._Properties(sObject, sName, vPropertiesList, pvIndex)
288 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
290 Set vProperty._ParentDatabase = _ParentDatabase
293 Set Properties = vProperty
294 Utils._ResetCalledSub(cstThisSub)
296 End Function
' Properties
298 REM -----------------------------------------------------------------------------------------------------------------------
299 Public Function ReadAllBytes(ByVal Optional pvFile As Variant) As Boolean
300 ' Read the whole content of a file into Long Binary Field object
302 Const cstThisSub =
"Field.ReadAllBytes
"
303 Utils._SetCalledSub(cstThisSub)
304 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
305 ReadAllBytes = _ReadAll(pvFile,
"ReadAllBytes
")
308 Utils._ResetCalledSub(cstThisSub)
310 End Function
' ReadAllBytes
312 REM -----------------------------------------------------------------------------------------------------------------------
313 Public Function ReadAllText(ByVal Optional pvFile As Variant) As Boolean
314 ' Read the whole content of a file into a Long Char Field object
316 Const cstThisSub =
"Field.ReadAllText
"
317 Utils._SetCalledSub(cstThisSub)
318 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
319 ReadAllText = _ReadAll(pvFile,
"ReadAllText
")
322 Utils._ResetCalledSub(cstThisSub)
324 End Function
' ReadAllText
326 REM -----------------------------------------------------------------------------------------------------------------------
327 Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
328 ' Return True if property setting OK
329 Const cstThisSub =
"Field.setProperty
"
330 Utils._SetCalledSub(cstThisSub)
331 setProperty = _PropertySet(psProperty, pvValue)
332 Utils._ResetCalledSub(cstThisSub)
335 REM -----------------------------------------------------------------------------------------------------------------------
336 Public Function WriteAllBytes(ByVal Optional pvFile As Variant) As Boolean
337 ' Write the whole content of a Long Binary Field object to a file
339 Const cstThisSub =
"Field.WriteAllBytes
"
340 Utils._SetCalledSub(cstThisSub)
341 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
342 WriteAllBytes = _WriteAll(pvFile,
"WriteAllBytes
")
345 Utils._ResetCalledSub(cstThisSub)
347 End Function
' WriteAllBytes
349 REM -----------------------------------------------------------------------------------------------------------------------
350 Public Function WriteAllText(ByVal Optional pvFile As Variant) As Boolean
351 ' Write the whole content of a Long Char Field object to a file
353 Const cstThisSub =
"Field.WriteAllText
"
354 Utils._SetCalledSub(cstThisSub)
355 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
356 WriteAllText = _WriteAll(pvFile,
"WriteAllText
")
359 Utils._ResetCalledSub(cstThisSub)
361 End Function
' WriteAllText
363 REM -----------------------------------------------------------------------------------------------------------------------
364 REM --- PRIVATE FUNCTIONS ---
365 REM -----------------------------------------------------------------------------------------------------------------------
367 REM -----------------------------------------------------------------------------------------------------------------------
368 Private Function _PropertiesList() As Variant
370 Select Case _ParentType
372 _PropertiesList =Array(
"DataType
",
"dbType
",
"DefaultValue
" _
373 ,
"Description
",
"Name
",
"ObjectType
",
"Size
",
"SourceField
",
"SourceTable
" _
374 ,
"TypeName
" _
377 _PropertiesList = Array(
"DataType
",
"dbType
",
"DefaultValue
" _
378 ,
"Description
",
"Name
",
"ObjectType
",
"Size
",
"SourceField
",
"SourceTable
" _
379 ,
"TypeName
" _
382 _PropertiesList = Array(
"DataType
",
"DataUpdatable
",
"dbType
",
"DefaultValue
" _
383 ,
"Description
" ,
"FieldSize
",
"Name
",
"ObjectType
" _
384 ,
"Size
",
"SourceTable
",
"TypeName
",
"Value
" _
388 End Function
' _PropertiesList
390 REM -----------------------------------------------------------------------------------------------------------------------
391 Private Function _PropertyGet(ByVal psProperty As String) As Variant
392 ' Return property value of the psProperty property name
394 If _ErrorHandler() Then On Local Error Goto Error_Function
395 Dim cstThisSub As String
396 cstThisSub =
"Field.get
" & psProperty
397 Utils._SetCalledSub(cstThisSub)
399 If Not hasProperty(psProperty) Then Goto Trace_Error
401 Dim vEMPTY As Variant, bCond1 As Boolean, bCond2 As Boolean, vValue As Variant, oValue As Object, sValue As String
402 Dim oSize As Object, lSize As Long, bNullable As Boolean, bNull As Boolean
403 Const cstMaxTextLength =
65535
404 Const cstMaxBinlength =
2 *
65535
406 _PropertyGet = vEMPTY
408 Select Case UCase(psProperty)
409 Case UCase(
"DataType
")
410 _PropertyGet = Column.Type
411 Case UCase(
"DbType
")
412 With com.sun.star.sdbc.DataType
413 Select Case Column.Type
414 Case .BIT : _PropertyGet = dbBoolean
415 Case .TINYINT : _PropertyGet = dbInteger
416 Case .SMALLINT : _PropertyGet = dbLong
417 Case .INTEGER : _PropertyGet = dbLong
418 Case .BIGINT : _PropertyGet = dbBigInt
419 Case .FLOAT : _PropertyGet = dbFloat
420 Case .REAL : _PropertyGet = dbSingle
421 Case .DOUBLE : _PropertyGet = dbDouble
422 Case .NUMERIC : _PropertyGet = dbNumeric
423 Case .DECIMAL : _PropertyGet = dbDecimal
424 Case .CHAR : _PropertyGet = dbChar
425 Case .VARCHAR : _PropertyGet = dbText
426 Case .LONGVARCHAR : _PropertyGet = dbMemo
427 Case .CLOB : _PropertyGet = dbMemo
428 Case .DATE : _PropertyGet = dbDate
429 Case .TIME : _PropertyGet = dbTime
430 Case .TIMESTAMP : _PropertyGet = dbTimeStamp
431 Case .BINARY : _PropertyGet = dbBinary
432 Case .VARBINARY : _PropertyGet = dbVarBinary
433 Case .LONGVARBINARY : _PropertyGet = dbLongBinary
434 Case .BLOB : _PropertyGet = dbLongBinary
435 Case .BOOLEAN : _PropertyGet = dbBoolean
436 Case Else : _PropertyGet = dbUndefined
439 Case UCase(
"DataUpdatable
")
440 If Utils._hasUNOProperty(Column,
"IsWritable
") Then
441 _PropertyGet = Column.IsWritable
442 ElseIf Utils._hasUNOProperty(Column,
"IsReadOnly
") Then
443 _PropertyGet = Not Column.IsReadOnly
444 ElseIf Utils._hasUNOProperty(Column,
"IsDefinitelyWritable
") Then
445 _PropertyGet = Column.IsDefinitelyWritable
449 If Utils._hasUNOProperty(Column,
"IsAutoIncrement
") Then
450 If Column.IsAutoIncrement Then _PropertyGet = False
' Forces False if auto-increment (MSAccess)
452 Case UCase(
"DefaultValue
")
453 If Utils._hasUNOProperty(Column,
"DefaultValue
") Then
' Default value in database set via SQL statement
454 _PropertyGet = Column.DefaultValue
455 ElseIf Utils._hasUNOProperty(Column,
"ControlDefault
") Then
' Default value set in Base via table edition
456 If IsEmpty(Column.ControlDefault) Then _PropertyGet =
"" Else _PropertyGet = Column.ControlDefault
458 _PropertyGet =
""
460 Case UCase(
"Description
")
461 bCond1 = Utils._hasUNOProperty(Column,
"Description
")
462 bCond2 = Utils._hasUNOProperty(Column,
"HelpText
")
464 Case ( bCond1 And bCond2 )
465 If IsEmpty(Column.HelpText) Then _PropertyGet = Column.Description Else _PropertyGet = Column.HelpText
466 Case ( bCond1 And ( Not bCond2 ) )
467 _PropertyGet = Column.Description
468 Case ( ( Not bCond1 ) And bCond2 )
469 _PropertyGet = Column.HelpText
471 _PropertyGet =
""
473 Case UCase(
"FieldSize
")
474 With com.sun.star.sdbc.DataType
475 Select Case Column.Type
476 Case .VARCHAR, .LONGVARCHAR, .CLOB
477 Set oSize = Column.getCharacterStream
478 Case .LONGVARBINARY, .VARBINARY, .BINARY, .BLOB
479 Set oSize = Column.getBinaryStream
484 If Not IsNull(oSize) Then
485 bNullable = ( Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE )
487 If Column.wasNull() Then _PropertyGet =
0 Else _PropertyGet = CLng(oSize.getLength())
489 _PropertyGet = CLng(oSize.getLength())
493 _PropertyGet = vEMPTY
495 Case UCase(
"Name
")
497 Case UCase(
"ObjectType
")
499 Case UCase(
"Size
")
500 With com.sun.star.sdbc.DataType
501 Select Case Column.Type
502 Case .LONGVARCHAR, .LONGVARBINARY, .VARBINARY, .BINARY, .BLOB, .CLOB
503 _PropertyGet =
0 ' Always
0 (MSAccess)
505 If Utils._hasUNOProperty(Column,
"Precision
") Then _PropertyGet = Column.Precision Else _PropertyGet =
0
508 Case UCase(
"SourceField
")
509 Select Case _ParentType
512 Case OBJQUERYDEF
' RealName = not documented ?!?
513 If Utils._hasUNOProperty(Column,
"RealName
") Then _PropertyGet = Column.RealName Else _PropertyGet = _Name
515 Case UCase(
"SourceTable
")
516 Select Case _ParentType
518 _PropertyGet = _ParentName
519 Case OBJQUERYDEF, OBJRECORDSET
520 _PropertyGet = Column.TableName
522 Case UCase(
"TypeName
")
523 _PropertyGet = Column.TypeName
524 Case UCase(
"Value
")
525 bNullable = ( Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE )
527 With com.sun.star.sdbc.DataType
528 Select Case Column.Type
529 Case .BIT, .BOOLEAN : vValue = Column.getBoolean()
' vbBoolean
530 Case .TINYINT : vValue = Column.getShort()
' vbInteger
531 Case .SMALLINT, .INTEGER: vValue = Column.getInt()
' vbLong
532 Case .BIGINT : vValue = Column.getLong()
' vbBigint
533 Case .FLOAT : vValue = Column.getFloat()
' vbSingle
534 Case .REAL, .DOUBLE : vValue = Column.getDouble()
' vbDouble
535 Case .NUMERIC, .DECIMAL
536 If Utils._hasUNOProperty(Column,
"Scale
") Then
537 If Column.Scale
> 0 Then
538 vValue = Column.getDouble()
539 Else
' CLng checks local decimal point, getString does not !
540 sValue = Join(Split(Column.getString(),
".
"), Utils._DecimalPoint())
541 vValue = CLng(sValue)
' CDec disappeared from LO ?!?
544 vValue = CDec(Column.getString())
546 Case .CHAR : vValue = Column.getString()
547 Case .VARCHAR : vValue = Column.getString()
' vbString
548 Case .LONGVARCHAR, .CLOB
549 Set oValue = Column.getCharacterStream()
550 If bNullable Then bNull = Column.wasNull()
552 lSize = CLng(oValue.getLength())
554 If lSize
> cstMaxTextLength Then Goto Trace_Length
555 vValue = Column.getString()
' vbString
559 Case .DATE : Set oValue = Column.getDate()
' vbObject with members VarType Unsigned Short =
18
560 If bNullable Then bNull = Column.wasNull()
561 If Not bNull Then vValue = DateSerial(CInt(oValue.Year), CInt(oValue.Month), CInt(oValue.Day))
562 Case .TIME : Set oValue = Column.getTime()
' vbObject with members VarType Unsigned Short =
18
563 If bNullable Then bNull = Column.wasNull()
564 If Not bNull Then vValue = TimeSerial(oValue.Hours, oValue.Minutes, oValue.Seconds)
', oValue.HundredthSeconds)
565 Case .TIMESTAMP : Set oValue = Column.getTimeStamp()
566 If bNullable Then bNull = Column.wasNull()
567 If Not bNull Then vValue = DateSerial(CInt(oValue.Year), CInt(oValue.Month), CInt(oValue.Day)) _
568 + TimeSerial(oValue.Hours, oValue.Minutes, oValue.Seconds)
', oValue.HundredthSeconds)
569 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
570 Set oValue = Column.getBinaryStream()
571 If bNullable Then bNull = Column.wasNull()
573 lSize = CLng(oValue.getLength())
' vbLong =
> equivalent to FieldSize
574 If lSize
> cstMaxBinlength Then Goto Trace_Length
576 oValue.readBytes(vValue, lSize)
580 vValue = Column.getString()
'GIVE STRING A TRY
581 If IsNumeric(vValue) Then vValue = Val(vValue)
'Required when type =
"", sometimes numeric fields are returned as strings (query/MSAccess)
584 If Column.wasNull() Then vValue = Null
'getXXX must precede wasNull()
587 _PropertyGet = vValue
593 Utils._ResetCalledSub(cstThisSub)
596 TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
597 _PropertyGet = vEMPTY
600 TraceError(TRACEFATAL, ERROVERFLOW, Utils._CalledSub(),
0, , Array(lSize,
"GetChunk
"))
601 _PropertyGet = vEMPTY
604 TraceError(TRACEABORT, Err, cstThisSub, Erl)
605 _PropertyGet = vEMPTY
607 End Function
' _PropertyGet V1.1
.0
609 REM -----------------------------------------------------------------------------------------------------------------------
610 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
611 ' Return True if property setting OK
613 If _ErrorHandler() Then On Local Error Goto Error_Function
614 Dim cstThisSub As String
615 cstThisSub =
"Field.set
" & psProperty
616 Utils._SetCalledSub(cstThisSub)
618 Dim iArgNr As Integer, vTemp As Variant
619 Dim oParent As Object
621 Select Case UCase(_A2B_.CalledSub)
622 Case UCase(
"setProperty
") : iArgNr =
3
623 Case UCase(
"Field.setProperty
") : iArgNr =
2
624 Case UCase(cstThisSub) : iArgNr =
1
627 If Not hasProperty(psProperty) Then Goto Trace_Error
629 Select Case UCase(psProperty)
630 Case UCase(
"DefaultValue
")
631 If _ParentType
<> OBJTABLEDEF Then Goto Trace_Error
632 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
633 If Utils._hasUNOProperty(Column,
"ControlDefault
") Then
' Default value set in Base via table edition
634 Column.ControlDefault = pvValue
636 Case UCase(
"Description
")
637 If _ParentType
<> OBJTABLEDEF Then Goto Trace_Error
638 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
639 Column.HelpText = pvValue
640 Case UCase(
"Value
")
641 If _ParentType
<> OBJRECORDSET Then Goto Trace_Error
' Not on table- or querydefs ... !
642 If Not Column.IsWritable Then Goto Trace_Error_Updatable
643 If Column.IsReadOnly Then Goto Trace_Error_Updatable
644 If _ParentDatabase.Recordsets(_ParentName)._EditMode = dbEditNone Then Goto Trace_Error_Update
645 With com.sun.star.sdbc.DataType
646 If IsNull(pvValue) Then
647 If Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE Then Column.updateNull() Else Goto Trace_Null
649 Select Case Column.Type
651 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
652 Column.updateBoolean(pvValue)
654 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
655 If pvValue
< -
128 Or pvValue
> +
127 Then Goto Trace_Error_Value
656 Column.updateShort(CInt(pvValue))
658 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
659 If pvValue
< -
32768 Or pvValue
> 32767 Then Goto trace_Error_Value
660 Column.updateInt(CLng(pvValue))
662 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
663 If pvValue
< -
2147483648 Or pvValue
> 2147483647 Then Goto trace_Error_Value
664 Column.updateInt(CLng(pvValue))
666 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
667 Column.updateLong(pvValue)
' No proper type conversion for HYPER data type
669 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
670 If Abs(pvValue)
< 3.402823E38 And Abs(pvValue)
> 1.401298E-45 Then Column.updateFloat(CSng(pvValue)) Else Goto trace_Error_Value
672 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
673 'If Abs(pvValue)
< 1.79769313486232E308 And Abs(pvValue)
> 4.94065645841247E-307 Then Column.updateDouble(CDbl(pvValue)) Else Goto trace_Error_Value
674 Column.updateDouble(CDbl(pvValue))
675 Case .NUMERIC, .DECIMAL
676 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
677 If Utils._hasUNOProperty(Column,
"Scale
") Then
678 If Column.Scale
> 0 Then
679 'If Abs(pvValue)
< 1.79769313486232E308 And Abs(pvValue)
> 4.94065645841247E-307 Then Column.updateDouble(CDbl(pvValue)) Else Goto trace_Error_Value
680 Column.updateDouble(CDbl(pvValue))
682 Column.updateString(CStr(pvValue))
685 Column.updateString(CStr(pvValue))
687 Case .CHAR, .VARCHAR, .LONGVARCHAR, .CLOB
688 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
689 Column.updateString(pvValue)
' vbString
691 If Not Utils._CheckArgument(pvValue, iArgNr, vbDate, , False) Then Goto Trace_Error_Value
692 vTemp = New com.sun.star.util.Date
695 .Month = Month(pvValue)
696 .Year = Year(pvValue)
698 Column.updateDate(vTemp)
700 If Not Utils._CheckArgument(pvValue, iArgNr, vbDate, , False) Then Goto Trace_Error_Value
701 vTemp = New com.sun.star.util.Time
703 .Hours = Hour(pvValue)
704 .Minutes = Minute(pvValue)
705 .Seconds = Second(pvValue)
706 '.HundredthSeconds =
0 ' replaced with Long nanoSeconds in LO
4.1 ??
708 Column.updateTime(vTemp)
710 If Not Utils._CheckArgument(pvValue, iArgNr, vbDate, , False) Then Goto Trace_Error_Value
711 vTemp = New com.sun.star.util.DateTime
714 .Month = Month(pvValue)
715 .Year = Year(pvValue)
716 .Hours = Hour(pvValue)
717 .Minutes = Minute(pvValue)
718 .Seconds = Second(pvValue)
719 '.HundredthSeconds =
0
721 Column.updateTimestamp(vTemp)
722 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
723 If Not IsArray(pvValue) Then Goto Trace_Error_Value
724 If UBound(pvValue)
< LBound(pvValue) Then Goto Trace_Error_Value
725 If Not Utils._CheckArgument(pvValue(LBound(pvValue)), iArgNr, vbInteger, , False) Then Goto Trace_Error_Value
726 Column.updateBytes(pvValue)
737 Utils._ResetCalledSub(cstThisSub)
740 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
744 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
748 TraceError(TRACEFATAL, ERRNOTNULLABLE, Utils._CalledSub(),
0,
1, _Name)
752 TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(),
0,
1)
755 Trace_Error_Updatable:
756 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(),
0,
1)
760 TraceError(TRACEABORT, Err, cstThisSub, Erl)
763 End Function
' _PropertySet
765 REM -----------------------------------------------------------------------------------------------------------------------
766 Public Function _ReadAll(ByVal psFile As String, ByVal psMethod As String) As Boolean
767 ' Write the whole content of a file into a stream object
769 If _ErrorHandler() Then On Local Error Goto Error_Function
772 If _ParentType
<> OBJRECORDSET Then Goto Trace_Error
' Not on table- or querydefs ... !
773 If Not Column.IsWritable Then Goto Trace_Error_Updatable
774 If Column.IsReadOnly Then Goto Trace_Error_Updatable
775 If _ParentDatabase.Recordsets(_ParentName)._EditMode = dbEditNone Then Goto Trace_Error_Update
777 Dim sFile As String, oSimpleFileAccess As Object, sMethod As String, oStream As Object
778 Dim lFileLength As Long, sBuffer As String, sMemo As String, iFile As Integer
779 Const cstMaxLength =
64000
780 sFile = ConvertToURL(psFile)
782 oSimpleFileAccess = CreateUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
783 If Not oSimpleFileAccess.exists(sFile) Then Goto Trace_File
785 With com.sun.star.sdbc.DataType
786 Select Case Column.Type
787 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
788 If psMethod
<> "ReadAllBytes
" Then Goto Trace_Error
789 Set oStream = oSimpleFileAccess.openFileRead(sFile)
790 lFileLength = oStream.getLength()
791 If lFileLength =
0 Then Goto Trace_File
792 Column.updateBinaryStream(oStream, lFileLength)
794 Case .VARCHAR, .LONGVARCHAR, .CLOB
795 If psMethod
<> "ReadAllText
" Then Goto Trace_Error
799 Open sFile For Input Access Read Shared As iFile
800 Do While Not Eof(iFile)
801 Line Input #iFile, sBuffer
802 lFileLength = lFileLength + Len(sBuffer) +
1
803 If lFileLength
> cstMaxLength Then Exit Do
804 sMemo = sMemo
& sBuffer
& vbNewLine
806 If lFileLength =
0 Or lFileLength
> cstMaxLength Then
810 sMemo = Left(sMemo, lFileLength -
1)
811 Column.updateString(sMemo)
812 'Column.updateCharacterStream(oStream, lFileLength)
' DOES NOT WORK ?!?
823 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , psMethod)
826 TraceError(TRACEFATAL, ERRFILEACCESS, Utils._CalledSub(),
0, , sFile)
827 If Not IsNull(oStream) Then oStream.closeInput()
830 TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(),
0,
1)
831 If Not IsNull(oStream) Then oStream.closeInput()
833 Trace_Error_Updatable:
834 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(),
0,
1)
835 If Not IsNull(oStream) Then oStream.closeInput()
838 TraceError(TRACEABORT, Err, _CalledSub, Erl)
840 End Function
' ReadAll
842 REM -----------------------------------------------------------------------------------------------------------------------
843 Public Function _WriteAll(ByVal psFile As String, ByVal psMethod As String) As Boolean
844 ' Write the whole content of a stream object to a file
846 If _ErrorHandler() Then On Local Error Goto Error_Function
849 Dim sFile As String, oSimpleFileAccess As Object, sMethod As String, oStream As Object
850 sFile = ConvertToURL(psFile)
852 oSimpleFileAccess = CreateUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
853 With com.sun.star.sdbc.DataType
854 Select Case Column.Type
855 Case .BINARY, .VARBINARY, .LONGVARBINARY, .BLOB
856 If psMethod
<> "WriteAllBytes
" Then Goto Trace_Error
857 Set oStream = Column.getBinaryStream()
858 Case .VARCHAR, .LONGVARCHAR, .CLOB
859 If psMethod
<> "WriteAllText
" Then Goto Trace_Error
860 Set oStream = Column.getCharacterStream()
866 If Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE Then
867 If Column.wasNull() Then Goto Trace_Null
869 If oStream.getLength() =
0 Then Goto Trace_Null
870 On Local Error Goto Trace_File
871 If oSimpleFileAccess.exists(sFile) Then oSimpleFileAccess.kill(sFile)
872 oSimpleFileAccess.writeFile(sFile, oStream)
873 On Local Error Goto Error_Function
881 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , psMethod)
884 TraceError(TRACEFATAL, ERRFILEACCESS, Utils._CalledSub(),
0, , sFile)
885 If Not IsNull(oStream) Then oStream.closeInput()
888 TraceError(TRACEFATAL, ERRFIELDNULL, _CalledSub,
0)
889 If Not IsNull(oStream) Then oStream.closeInput()
892 TraceError(TRACEABORT, Err, _CalledSub, Erl)
894 End Function
' WriteAll