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 Column As Object
' com.sun.star.sdb.OTableColumnWrapper
23 ' or org.openoffice.comp.dbaccess.OQueryColumn
24 ' or com.sun.star.sdb.ODataColumn
26 REM -----------------------------------------------------------------------------------------------------------------------
27 REM --- CONSTRUCTORS / DESTRUCTORS ---
28 REM -----------------------------------------------------------------------------------------------------------------------
29 Private Sub Class_Initialize()
32 _ParentName =
""
33 _ParentType =
""
35 End Sub
' Constructor
37 REM -----------------------------------------------------------------------------------------------------------------------
38 Private Sub Class_Terminate()
39 On Local Error Resume Next
40 Call Class_Initialize()
41 End Sub
' Destructor
43 REM -----------------------------------------------------------------------------------------------------------------------
45 Call Class_Terminate()
46 End Sub
' Explicit destructor
48 REM -----------------------------------------------------------------------------------------------------------------------
49 REM --- CLASS GET/LET/SET PROPERTIES ---
50 REM -----------------------------------------------------------------------------------------------------------------------
52 Property Get DataType() As Long
' AOO/LibO type
53 DataType = _PropertyGet(
"DataType
")
54 End Property
' DataType (get)
56 Property Get DataUpdatable() As Boolean
57 DataUpdatable = _PropertyGet(
"DataUpdatable
")
58 End Property
' DataUpdatable (get)
60 REM -----------------------------------------------------------------------------------------------------------------------
61 Property Get DbType() As Long
' MSAccess type
62 DbType = _PropertyGet(
"DbType
")
63 End Property
' DbType (get)
65 REM -----------------------------------------------------------------------------------------------------------------------
66 Property Get DefaultValue() As Variant
67 DefaultValue = _PropertyGet(
"DefaultValue
")
68 End Property
' DefaultValue (get)
70 Property Let DefaultValue(ByVal pvDefaultValue As Variant)
71 Call _PropertySet(
"DefaultValue
", pvDefaultValue)
72 End Property
' DefaultValue (set)
74 REM -----------------------------------------------------------------------------------------------------------------------
75 Property Get Description() As Variant
76 Description = _PropertyGet(
"Description
")
77 End Property
' Description (get)
79 Property Let Description(ByVal pvDescription As Variant)
80 Call _PropertySet(
"Description
", pvDescription)
81 End Property
' Description (set)
83 REM -----------------------------------------------------------------------------------------------------------------------
84 Property Get FieldSize() As Long
85 FieldSize = _PropertyGet(
"FieldSize
")
86 End Property
' FieldSize (get)
88 REM -----------------------------------------------------------------------------------------------------------------------
89 Property Get Name() As String
90 Name = _PropertyGet(
"Name
")
91 End Property
' Name (get)
93 REM -----------------------------------------------------------------------------------------------------------------------
94 Property Get ObjectType() As String
95 ObjectType = _PropertyGet(
"ObjectType
")
96 End Property
' ObjectType (get)
98 REM -----------------------------------------------------------------------------------------------------------------------
99 Property Get Size() As Long
100 Size = _PropertyGet(
"Size
")
101 End Property
' Size (get)
103 REM -----------------------------------------------------------------------------------------------------------------------
104 Property Get SourceField() As String
105 SourceField = _PropertyGet(
"SourceField
")
106 End Property
' SourceField (get)
108 REM -----------------------------------------------------------------------------------------------------------------------
109 Property Get SourceTable() As String
110 SourceTable = _PropertyGet(
"SourceTable
")
111 End Property
' SourceTable (get)
113 REM -----------------------------------------------------------------------------------------------------------------------
114 Property Get TypeName() As String
115 TypeName = _PropertyGet(
"TypeName
")
116 End Property
' TypeName (get)
118 REM -----------------------------------------------------------------------------------------------------------------------
119 Property Get Value() As Variant
120 Value = _PropertyGet(
"Value
")
121 End Property
' Value (get)
123 Property Let Value(ByVal pvValue As Variant)
124 Call _PropertySet(
"Value
", pvValue)
125 End Property
' Value (set)
127 REM -----------------------------------------------------------------------------------------------------------------------
128 REM --- CLASS METHODS ---
129 REM -----------------------------------------------------------------------------------------------------------------------
131 REM -----------------------------------------------------------------------------------------------------------------------
132 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
133 ' Return property value of psProperty property name
135 Const cstThisSub =
"Field.getProperty
"
136 Utils._SetCalledSub(cstThisSub)
137 If IsMissing(pvProperty) Then Call _TraceArguments()
138 getProperty = _PropertyGet(pvProperty)
139 Utils._ResetCalledSub(cstThisSub)
141 End Function
' getProperty
143 REM -----------------------------------------------------------------------------------------------------------------------
144 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
145 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
147 Const cstThisSub =
"Field.hasProperty
"
148 Utils._SetCalledSub(cstThisSub)
149 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
150 Utils._ResetCalledSub(cstThisSub)
153 End Function
' hasProperty
155 REM -----------------------------------------------------------------------------------------------------------------------
156 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
158 ' a Collection object if pvIndex absent
159 ' a Property object otherwise
161 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String, sName As String
162 Const cstThisSub =
"Field.Properties
"
163 Utils._SetCalledSub(cstThisSub)
164 vPropertiesList = _PropertiesList()
165 sObject = Utils._PCase(_Type)
166 sName = _ParentType
& "/
" & _ParentName
& "/
" & _Name
167 If IsMissing(pvIndex) Then
168 vProperty = PropertiesGet._Properties(sObject, sName, vPropertiesList)
170 vProperty = PropertiesGet._Properties(sObject, sName, vPropertiesList, pvIndex)
171 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
173 Set vProperty._ParentDatabase = _ParentDatabase
176 Set Properties = vProperty
177 Utils._ResetCalledSub(cstThisSub)
179 End Function
' Properties
181 REM -----------------------------------------------------------------------------------------------------------------------
182 Public Function ReadAllBytes(ByVal Optional pvFile As Variant) As Boolean
183 ' Read the whole content of a file into Long Binary Field object
185 Const cstThisSub =
"Field.ReadAllBytes
"
186 Utils._SetCalledSub(cstThisSub)
187 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
188 ReadAllBytes = _ReadAll(pvFile,
"ReadAllBytes
")
191 Utils._ResetCalledSub(cstThisSub)
193 End Function
' ReadAllBytes
195 REM -----------------------------------------------------------------------------------------------------------------------
196 Public Function ReadAllText(ByVal Optional pvFile As Variant) As Boolean
197 ' Read the whole content of a file into a Long Char Field object
199 Const cstThisSub =
"Field.ReadAllText
"
200 Utils._SetCalledSub(cstThisSub)
201 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
202 ReadAllText = _ReadAll(pvFile,
"ReadAllText
")
205 Utils._ResetCalledSub(cstThisSub)
207 End Function
' ReadAllText
209 REM -----------------------------------------------------------------------------------------------------------------------
210 Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
211 ' Return True if property setting OK
212 Const cstThisSub =
"Field.setProperty
"
213 Utils._SetCalledSub(cstThisSub)
214 setProperty = _PropertySet(psProperty, pvValue)
215 Utils._ResetCalledSub(cstThisSub)
218 REM -----------------------------------------------------------------------------------------------------------------------
219 Public Function WriteAllBytes(ByVal Optional pvFile As Variant) As Boolean
220 ' Write the whole content of a Long Binary Field object to a file
222 Const cstThisSub =
"Field.WriteAllBytes
"
223 Utils._SetCalledSub(cstThisSub)
224 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
225 WriteAllBytes = _WriteAll(pvFile,
"WriteAllBytes
")
228 Utils._ResetCalledSub(cstThisSub)
230 End Function
' WriteAllBytes
232 REM -----------------------------------------------------------------------------------------------------------------------
233 Public Function WriteAllText(ByVal Optional pvFile As Variant) As Boolean
234 ' Write the whole content of a Long Char Field object to a file
236 Const cstThisSub =
"Field.WriteAllText
"
237 Utils._SetCalledSub(cstThisSub)
238 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
239 WriteAllText = _WriteAll(pvFile,
"WriteAllText
")
242 Utils._ResetCalledSub(cstThisSub)
244 End Function
' WriteAllText
246 REM -----------------------------------------------------------------------------------------------------------------------
247 REM --- PRIVATE FUNCTIONS ---
248 REM -----------------------------------------------------------------------------------------------------------------------
250 REM -----------------------------------------------------------------------------------------------------------------------
251 Private Function _PropertiesList() As Variant
253 Select Case _ParentType
255 _PropertiesList =Array(
"DataType
",
"dbType
",
"DefaultValue
" _
256 ,
"Description
",
"Name
",
"ObjectType
",
"Size
",
"SourceField
",
"SourceTable
" _
257 ,
"TypeName
" _
260 _PropertiesList = Array(
"DataType
",
"dbType
",
"DefaultValue
" _
261 ,
"Description
",
"Name
",
"ObjectType
",
"Size
",
"SourceField
",
"SourceTable
" _
262 ,
"TypeName
" _
265 _PropertiesList = Array(
"DataType
",
"DataUpdatable
",
"dbType
",
"DefaultValue
" _
266 ,
"Description
" ,
"FieldSize
",
"Name
",
"ObjectType
" _
267 ,
"Size
",
"SourceTable
",
"TypeName
",
"Value
" _
271 End Function
' _PropertiesList
273 REM -----------------------------------------------------------------------------------------------------------------------
274 Private Function _PropertyGet(ByVal psProperty As String) As Variant
275 ' Return property value of the psProperty property name
277 If _ErrorHandler() Then On Local Error Goto Error_Function
278 Dim cstThisSub As String
279 cstThisSub =
"Field.get
" & psProperty
280 Utils._SetCalledSub(cstThisSub)
282 If Not hasProperty(psProperty) Then Goto Trace_Error
284 Dim vEMPTY As Variant, bCond1 As Boolean, bCond2 As Boolean, vValue As Variant, oValue As Object, sValue As String
285 Dim oSize As Object, lSize As Long, bNullable As Boolean, bNull As Boolean
286 Const cstMaxTextLength =
65535
287 _PropertyGet = vEMPTY
289 Select Case UCase(psProperty)
290 Case UCase(
"DataType
")
291 _PropertyGet = Column.Type
292 Case UCase(
"DbType
")
293 With com.sun.star.sdbc.DataType
294 Select Case Column.Type
295 Case .BIT : _PropertyGet = dbUndefined
296 Case .TINYINT : _PropertyGet = dbInteger
297 Case .SMALLINT : _PropertyGet = dbLong
298 Case .INTEGER : _PropertyGet = dbLong
299 Case .BIGINT : _PropertyGet = dbBigInt
300 Case .FLOAT : _PropertyGet = dbFloat
301 Case .REAL : _PropertyGet = dbSingle
302 Case .DOUBLE : _PropertyGet = dbDouble
303 Case .NUMERIC : _PropertyGet = dbNumeric
304 Case .DECIMAL : _PropertyGet = dbDecimal
305 Case .CHAR : _PropertyGet = dbText
306 Case .VARCHAR : _PropertyGet = dbChar
307 Case .LONGVARCHAR : _PropertyGet = dbMemo
308 Case .DATE : _PropertyGet = dbDate
309 Case .TIME : _PropertyGet = dbTime
310 Case .TIMESTAMP : _PropertyGet = dbTimeStamp
311 Case .BINARY : _PropertyGet = dbBinary
312 Case .VARBINARY : _PropertyGet = dbVarBinary
313 Case .LONGVARBINARY : _PropertyGet = dbLongBinary
314 Case .BOOLEAN : _PropertyGet = dbBoolean
315 Case Else : _PropertyGet = dbUndefined
318 Case UCase(
"DataUpdatable
")
319 If Utils._hasUNOProperty(Column,
"IsWritable
") Then
320 _PropertyGet = Column.IsWritable
321 ElseIf Utils._hasUNOProperty(Column,
"IsReadOnly
") Then
322 _PropertyGet = Not Column.IsReadOnly
323 ElseIf Utils._hasUNOProperty(Column,
"IsDefinitelyWritable
") Then
324 _PropertyGet = Column.IsDefinitelyWritable
328 If Utils._hasUNOProperty(Column,
"IsAutoIncrement
") Then
329 If Column.IsAutoIncrement Then _PropertyGet = False
' Forces False if auto-increment (MSAccess)
331 Case UCase(
"DefaultValue
")
332 If Utils._hasUNOProperty(Column,
"DefaultValue
") Then
' Default value in database set via SQL statement
333 _PropertyGet = Column.DefaultValue
334 ElseIf Utils._hasUNOProperty(Column,
"ControlDefault
") Then
' Default value set in Base via table edition
335 If IsEmpty(Column.ControlDefault) Then _PropertyGet =
"" Else _PropertyGet = Column.ControlDefault
337 _PropertyGet =
""
339 Case UCase(
"Description
")
340 bCond1 = Utils._hasUNOProperty(Column,
"Description
")
341 bCond2 = Utils._hasUNOProperty(Column,
"HelpText
")
343 Case ( bCond1 And bCond2 )
344 If IsEmpty(Column.HelpText) Then _PropertyGet = Column.Description Else _PropertyGet = Column.HelpText
345 Case ( bCond1 And ( Not bCond2 ) )
346 _PropertyGet = Column.Description
347 Case ( ( Not bCond1 ) And bCond2 )
348 _PropertyGet = Column.HelpText
350 _PropertyGet =
""
352 Case UCase(
"FieldSize
")
' Probably physical size =
2 * unicode string length
353 With com.sun.star.sdbc.DataType
354 Select Case Column.Type
356 Set oSize = Column.getCharacterStream
357 Case .LONGVARBINARY, .VARBINARY, .BINARY
358 Set oSize = Column.getBinaryStream
363 If Not IsNull(oSize) Then
364 bNullable = ( Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE )
366 If Column.wasNull() Then _PropertyGet =
0 Else _PropertyGet = CLng(oSize.getLength())
368 _PropertyGet = CLng(oSize.getLength())
372 _PropertyGet = vEMPTY
374 Case UCase(
"Name
")
376 Case UCase(
"ObjectType
")
378 Case UCase(
"Size
")
379 With com.sun.star.sdbc.DataType
380 Select Case Column.Type
381 Case .LONGVARCHAR, .LONGVARBINARY
382 _PropertyGet =
0 ' Always
0 (MSAccess)
384 If Utils._hasUNOProperty(Column,
"Precision
") Then _PropertyGet = Column.Precision Else _PropertyGet =
0
387 Case UCase(
"SourceField
")
388 Select Case _ParentType
391 Case OBJQUERYDEF
' RealName = not documented ?!?
392 If Utils._hasUNOProperty(Column,
"RealName
") Then _PropertyGet = Column.RealName Else _PropertyGet = _Name
394 Case UCase(
"SourceTable
")
395 Select Case _ParentType
397 _PropertyGet = _ParentName
398 Case OBJQUERYDEF, OBJRECORDSET
399 _PropertyGet = Column.TableName
401 Case UCase(
"TypeName
")
402 _PropertyGet = Column.TypeName
403 Case UCase(
"Value
")
404 bNullable = ( Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE )
406 With com.sun.star.sdbc.DataType
407 Select Case Column.Type
408 Case .BIT, .BOOLEAN : vValue = Column.getBoolean()
' vbBoolean
409 Case .TINYINT : vValue = Column.getShort()
' vbInteger
410 Case .SMALLINT, .INTEGER: vValue = Column.getInt()
' vbLong
411 Case .BIGINT : vValue = Column.getLong()
' vbBigint
412 Case .FLOAT : vValue = Column.getFloat()
' vbSingle
413 Case .REAL, .DOUBLE : vValue = Column.getDouble()
' vbDouble
414 Case .NUMERIC, .DECIMAL
415 If Utils._hasUNOProperty(Column,
"Scale
") Then
416 If Column.Scale
> 0 Then
417 vValue = Column.getDouble()
418 Else
' CLng checks local decimal point, getString does not !
419 sValue = Join(Split(Column.getString(),
".
"), Utils._DecimalPoint())
420 vValue = CLng(sValue)
' CDec disappeared from LO ?!?
423 vValue = CDec(Column.getString())
425 Case .CHAR : vValue = Column.getString()
426 Case .VARCHAR : vValue = Column.getString()
' vbString
428 Set oValue = Column.getCharacterStream()
429 If bNullable Then bNull = Column.wasNull()
431 lSize = CLng(oValue.getLength())
433 If lSize
> cstMaxTextLength Then Goto Trace_Length
434 vValue = Column.getString()
' vbString
438 Case .DATE : Set oValue = Column.getDate()
' vbObject with members VarType Unsigned Short =
18
439 If bNullable Then bNull = Column.wasNull()
440 If Not bNull Then vValue = DateSerial(CInt(oValue.Year), CInt(oValue.Month), CInt(oValue.Day))
441 Case .TIME : Set oValue = Column.getTime()
' vbObject with members VarType Unsigned Short =
18
442 If bNullable Then bNull = Column.wasNull()
443 If Not bNull Then vValue = TimeSerial(oValue.Hours, oValue.Minutes, oValue.Seconds)
', oValue.HundredthSeconds)
444 Case .TIMESTAMP : Set oValue = Column.getTimeStamp()
445 If bNullable Then bNull = Column.wasNull()
446 If Not bNull Then vValue = DateSerial(CInt(oValue.Year), CInt(oValue.Month), CInt(oValue.Day)) _
447 + TimeSerial(oValue.Hours, oValue.Minutes, oValue.Seconds)
', oValue.HundredthSeconds)
448 Case .BINARY, .VARBINARY, .LONGVARBINARY
449 Set oValue = Column.getBinaryStream()
450 If bNullable Then bNull = Column.wasNull()
451 If Not bNull Then vValue = CLng(oValue.getLength())
' vbLong =
> equivalent to FieldSize
453 Case .BLOB : vValue = Column.getBlob()
' TBC HSQLDB
2.0 ?
454 Case .CLOB : vValue = Column.getClob()
458 vValue = Column.getString()
'GIVE STRING A TRY
459 If IsNumeric(vValue) Then vValue = Val(vValue)
'Required when type =
"", sometimes numeric fields are returned as strings (query/MSAccess)
462 If Column.wasNull() Then vValue = Nothing
'getXXX must precede wasNull()
465 _PropertyGet = vValue
471 Utils._ResetCalledSub(cstThisSub)
474 TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
475 _PropertyGet = vEMPTY
478 TraceError(TRACEFATAL, ERRMEMOLENGTH, Utils._CalledSub(),
0, , lSize)
479 _PropertyGet = vEMPTY
482 TraceError(TRACEABORT, Err, cstThisSub, Erl)
483 _PropertyGet = vEMPTY
485 End Function
' _PropertyGet V1.1
.0
487 REM -----------------------------------------------------------------------------------------------------------------------
488 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
489 ' Return True if property setting OK
491 If _ErrorHandler() Then On Local Error Goto Error_Function
492 Dim cstThisSub As String
493 cstThisSub =
"Field.set
" & psProperty
494 Utils._SetCalledSub(cstThisSub)
496 Dim iArgNr As Integer, vTemp As Variant
497 Dim oParent As Object
499 Select Case UCase(_A2B_.CalledSub)
500 Case UCase(
"setProperty
") : iArgNr =
3
501 Case UCase(
"Field.setProperty
") : iArgNr =
2
502 Case UCase(cstThisSub) : iArgNr =
1
505 If Not hasProperty(psProperty) Then Goto Trace_Error
507 Select Case UCase(psProperty)
508 Case UCase(
"DefaultValue
")
509 If _ParentType
<> OBJTABLEDEF Then Goto Trace_Error
510 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
511 If Utils._hasUNOProperty(Column,
"ControlDefault
") Then
' Default value set in Base via table edition
512 Column.ControlDefault = pvValue
514 Case UCase(
"Description
")
515 If _ParentType
<> OBJTABLEDEF Then Goto Trace_Error
516 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
517 Column.HelpText = pvValue
518 Case UCase(
"Value
")
519 If _ParentType
<> OBJRECORDSET Then Goto Trace_Error
' Not on table- or querydefs ... !
520 If Not Column.IsWritable Then Goto Trace_Error_Updatable
521 If Column.IsReadOnly Then Goto Trace_Error_Updatable
522 If _ParentDatabase.Recordsets(_ParentName)._EditMode = dbEditNone Then Goto Trace_Error_Update
523 With com.sun.star.sdbc.DataType
524 If IsNull(pvValue) Then
525 If Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE Then Column.updateNull() Else Goto Trace_Null
527 Select Case Column.Type
529 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
530 Column.updateBoolean(pvValue)
532 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
533 If pvValue
< -
128 Or pvValue
> +
127 Then Goto Trace_Error_Value
534 Column.updateShort(CInt(pvValue))
536 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
537 If pvValue
< -
32768 Or pvValue
> 32767 Then Goto trace_Error_Value
538 Column.updateInt(CLng(pvValue))
540 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
541 If pvValue
< -
2147483648 Or pvValue
> 2147483647 Then Goto trace_Error_Value
542 Column.updateInt(CLng(pvValue))
544 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
545 Column.updateLong(pvValue)
' No proper type conversion for HYPER data type
547 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
548 If Abs(pvValue)
< 3.402823E38 And Abs(pvValue)
> 1.401298E-45 Then Column.updateFloat(CSng(pvValue)) Else Goto trace_Error_Value
550 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
551 'If Abs(pvValue)
< 1.79769313486232E308 And Abs(pvValue)
> 4.94065645841247E-307 Then Column.updateDouble(CDbl(pvValue)) Else Goto trace_Error_Value
552 Column.updateDouble(CDbl(pvValue))
553 Case .NUMERIC, .DECIMAL
554 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
555 If Utils._hasUNOProperty(Column,
"Scale
") Then
556 If Column.Scale
> 0 Then
557 'If Abs(pvValue)
< 1.79769313486232E308 And Abs(pvValue)
> 4.94065645841247E-307 Then Column.updateDouble(CDbl(pvValue)) Else Goto trace_Error_Value
558 Column.updateDouble(CDbl(pvValue))
560 Column.updateString(CStr(pvValue))
563 Column.updateString(CStr(pvValue))
565 Case .CHAR, .VARCHAR, .LONGVARCHAR
566 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
567 Column.updateString(pvValue)
' vbString
569 If Not Utils._CheckArgument(pvValue, iArgNr, vbDate, , False) Then Goto Trace_Error_Value
570 vTemp = New com.sun.star.util.Date
573 .Month = Month(pvValue)
574 .Year = Year(pvValue)
576 Column.updateDate(vTemp)
578 If Not Utils._CheckArgument(pvValue, iArgNr, vbDate, , False) Then Goto Trace_Error_Value
579 vTemp = New com.sun.star.util.Time
581 .Hours = Hour(pvValue)
582 .Minutes = Minute(pvValue)
583 .Seconds = Second(pvValue)
584 '.HundredthSeconds =
0 ' replaced with Long nanoSeconds in LO
4.1 ??
586 Column.updateTime(vTemp)
588 If Not Utils._CheckArgument(pvValue, iArgNr, vbDate, , False) Then Goto Trace_Error_Value
589 vTemp = New com.sun.star.util.DateTime
592 .Month = Month(pvValue)
593 .Year = Year(pvValue)
594 .Hours = Hour(pvValue)
595 .Minutes = Minute(pvValue)
596 .Seconds = Second(pvValue)
597 '.HundredthSeconds =
0
599 Column.updateTimestamp(vTemp)
600 ' Case .BINARY, .VARBINARY, .LONGVARBINARY
613 Utils._ResetCalledSub(cstThisSub)
616 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
620 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
624 TraceError(TRACEFATAL, ERRNOTNULLABLE, Utils._CalledSub(),
0,
1, _Name)
628 TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(),
0,
1)
631 Trace_Error_Updatable:
632 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(),
0,
1)
636 TraceError(TRACEABORT, Err, cstThisSub, Erl)
639 End Function
' _PropertySet
641 REM -----------------------------------------------------------------------------------------------------------------------
642 Public Function _ReadAll(ByVal psFile As String, ByVal psMethod As String) As Boolean
643 ' Write the whole content of a file into a stream object
645 If _ErrorHandler() Then On Local Error Goto Error_Function
648 If _ParentType
<> OBJRECORDSET Then Goto Trace_Error
' Not on table- or querydefs ... !
649 If Not Column.IsWritable Then Goto Trace_Error_Updatable
650 If Column.IsReadOnly Then Goto Trace_Error_Updatable
651 If _ParentDatabase.Recordsets(_ParentName)._EditMode = dbEditNone Then Goto Trace_Error_Update
653 Dim sFile As String, oSimpleFileAccess As Object, sMethod As String, oStream As Object
654 Dim lFileLength As Long, sBuffer As String, sMemo As String, iFile As Integer
655 Const cstMaxLength =
64000
656 sFile = ConvertToURL(psFile)
658 oSimpleFileAccess = CreateUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
659 If Not oSimpleFileAccess.exists(sFile) Then Goto Trace_File
661 With com.sun.star.sdbc.DataType
662 Select Case Column.Type
663 Case .BINARY, .VARBINARY, .LONGVARBINARY
664 If psMethod
<> "ReadAllBytes
" Then Goto Trace_Error
665 Set oStream = oSimpleFileAccess.openFileRead(sFile)
666 lFileLength = oStream.getLength()
667 If lFileLength =
0 Then Goto Trace_File
668 Column.updateBinaryStream(oStream, lFileLength)
671 If psMethod
<> "ReadAllText
" Then Goto Trace_Error
675 Open sFile For Input Access Read Shared As iFile
676 Do While Not Eof(iFile)
677 Line Input #iFile, sBuffer
678 lFileLength = lFileLength + Len(sBuffer) +
1
679 If lFileLength
> cstMaxLength Then Exit Do
680 sMemo = sMemo
& sBuffer
& Chr(
10)
682 If lFileLength =
0 Or lFileLength
> cstMaxLength Then
686 sMemo = Left(sMemo, lFileLength -
1)
687 Column.updateString(sMemo)
688 'Column.updateCharacterStream(oStream, lFileLength)
' DOES NOT WORK ?!?
699 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , psMethod)
702 TraceError(TRACEFATAL, ERRFILEACCESS, Utils._CalledSub(),
0, , sFile)
703 If Not IsNull(oStream) Then oStream.closeInput()
706 TraceError(TRACEFATAL, ERRUPDATESEQUENCE, Utils._CalledSub(),
0,
1)
707 If Not IsNull(oStream) Then oStream.closeInput()
709 Trace_Error_Updatable:
710 TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(),
0,
1)
711 If Not IsNull(oStream) Then oStream.closeInput()
714 TraceError(TRACEABORT, Err, _CalledSub, Erl)
716 End Function
' ReadAll
718 REM -----------------------------------------------------------------------------------------------------------------------
719 Public Function _WriteAll(ByVal psFile As String, ByVal psMethod As String) As Boolean
720 ' Write the whole content of a stream object to a file
722 If _ErrorHandler() Then On Local Error Goto Error_Function
725 Dim sFile As String, oSimpleFileAccess As Object, sMethod As String, oStream As Object
726 sFile = ConvertToURL(psFile)
728 oSimpleFileAccess = CreateUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
729 With com.sun.star.sdbc.DataType
730 Select Case Column.Type
731 Case .BINARY, .VARBINARY, .LONGVARBINARY
732 If psMethod
<> "WriteAllBytes
" Then Goto Trace_Error
733 Set oStream = Column.getBinaryStream()
735 If psMethod
<> "WriteAllText
" Then Goto Trace_Error
736 Set oStream = Column.getCharacterStream()
742 If Column.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE Then
743 If Column.wasNull() Then Goto Trace_Null
745 If oStream.getLength() =
0 Then Goto Trace_Null
746 On Local Error Goto Trace_File
747 If oSimpleFileAccess.exists(sFile) Then oSimpleFileAccess.kill(sFile)
748 oSimpleFileAccess.writeFile(sFile, oStream)
749 On Local Error Goto Error_Function
757 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0, , psMethod)
760 TraceError(TRACEFATAL, ERRFILEACCESS, Utils._CalledSub(),
0, , sFile)
761 If Not IsNull(oStream) Then oStream.closeInput()
764 TraceError(TRACEFATAL, ERRFIELDNULL, _CalledSub,
0)
765 If Not IsNull(oStream) Then oStream.closeInput()
768 TraceError(TRACEABORT, Err, _CalledSub, Erl)
770 End Function
' WriteAll