wizards/source/access2base/Field.xba     |   25 ++++++++++++++++++-------
 wizards/source/access2base/Recordset.xba |   20 +++++++-------------
 2 files changed, 25 insertions(+), 20 deletions(-)

New commits:
commit e005b0a37feedffafc3fb89c61f054b692dc0c43
Author: Jean-Pierre Ledure <j...@ledure.be>
Date:   Thu Apr 27 16:21:06 2017 +0200

    Access2Base - Optimize default value in field class
    
    Buffer default value to optimize multiple records insertions
    
    Change-Id: Ia339e8f4b4d00419978503d6351b331a0b987826

diff --git a/wizards/source/access2base/Field.xba 
b/wizards/source/access2base/Field.xba
index 5a7fcc4cd870..bae69310e92d 100644
--- a/wizards/source/access2base/Field.xba
+++ b/wizards/source/access2base/Field.xba
@@ -21,6 +21,8 @@ Private _ParentName                           As String
 Private _ParentType                            As String
 Private _ParentDatabase                        As Object
 Private _ParentRecordset               As Object
+Private _DefaultValue                  As String
+Private _DefaultValueSet               As Boolean
 Private Column                                 As Object                       
        &apos;  com.sun.star.sdb.OTableColumnWrapper
                                                                                
        &apos;                  or      
org.openoffice.comp.dbaccess.OQueryColumn
                                                                                
        &apos;                  or      com.sun.star.sdb.ODataColumn
@@ -33,6 +35,8 @@ Private Sub Class_Initialize()
        _Name = &quot;&quot;
        _ParentName = &quot;&quot;
        _ParentType = &quot;&quot;
+       _DefaultValue = &quot;&quot;
+       _DefaultValueSet = False
        Set Column = Nothing
 End Sub                &apos;  Constructor
 
@@ -379,7 +383,7 @@ Private Function _PropertiesList() As Variant
                                                                , 
&quot;Description&quot;, &quot;Name&quot;, &quot;ObjectType&quot;, 
&quot;Size&quot;, &quot;SourceField&quot;, &quot;SourceTable&quot; _
                                                                , 
&quot;TypeName&quot; _
                                                                )
-               Case OBJRECORDSET
+               Case OBJRECORDSET                       
                        _PropertiesList = Array(&quot;DataType&quot;, 
&quot;DataUpdatable&quot;,  &quot;dbType&quot;, &quot;DefaultValue&quot; _
                                                                , 
&quot;Description&quot; , &quot;FieldSize&quot;, &quot;Name&quot;, 
&quot;ObjectType&quot; _
                                                                , 
&quot;Size&quot;, &quot;SourceTable&quot;, &quot;TypeName&quot;, 
&quot;Value&quot; _
@@ -450,13 +454,18 @@ Const cstMaxBinlength = 2 * 65535
                                If Column.IsAutoIncrement Then _PropertyGet = 
False                     &apos;  Forces False if auto-increment (MSAccess)
                        End If
                Case UCase(&quot;DefaultValue&quot;)
-                       If Utils._hasUNOProperty(Column, 
&quot;DefaultValue&quot;) Then                 &apos;  Default value in 
database set via SQL statement
-                               _PropertyGet = Column.DefaultValue
-                       ElseIf Utils._hasUNOProperty(Column, 
&quot;ControlDefault&quot;) Then           &apos;  Default value set in Base 
via table edition
-                               If IsEmpty(Column.ControlDefault) Then 
_PropertyGet = &quot;&quot; Else _PropertyGet = Column.ControlDefault
-                       Else
-                               _PropertyGet = &quot;&quot;
+                       &apos;  default value buffered to avoid multiple calls
+                       If Not _DefaultValueSet Then
+                               If Utils._hasUNOProperty(Column, 
&quot;DefaultValue&quot;) Then                 &apos;  Default value in 
database set via SQL statement
+                                       _DefaultValue = Column.DefaultValue
+                               ElseIf Utils._hasUNOProperty(Column, 
&quot;ControlDefault&quot;) Then           &apos;  Default value set in Base 
via table edition
+                                       If IsEmpty(Column.ControlDefault) Then 
_DefaultValue = &quot;&quot; Else _DefaultValue = Column.ControlDefault
+                               Else
+                                       _DefaultValue = &quot;&quot;
+                               End If
+                               _DefaultValueSet = True
                        End If
+                       _PropertyGet = _DefaultValue
                Case UCase(&quot;Description&quot;)
                        bCond1 = Utils._hasUNOProperty(Column, 
&quot;Description&quot;)
                        bCond2 = Utils._hasUNOProperty(Column, 
&quot;HelpText&quot;)
@@ -631,6 +640,8 @@ Dim oParent As Object
                        If Not Utils._CheckArgument(pvValue, iArgNr, vbString, 
, False) Then Goto Trace_Error_Value
                        If Utils._hasUNOProperty(Column, 
&quot;ControlDefault&quot;) Then                       &apos;  Default value 
set in Base via table edition
                                Column.ControlDefault = pvValue
+                               _DefaultValue = pvValue
+                               _DefaultValueSet = True
                        End If
                Case UCase(&quot;Description&quot;)
                        If _ParentType &lt;&gt; OBJTABLEDEF Then Goto 
Trace_Error
diff --git a/wizards/source/access2base/Recordset.xba 
b/wizards/source/access2base/Recordset.xba
index 8348b0f81207..57e3641b065b 100644
--- a/wizards/source/access2base/Recordset.xba
+++ b/wizards/source/access2base/Recordset.xba
@@ -161,7 +161,7 @@ Public Function AddNew() As Boolean
 
 Const cstThisSub = &quot;Recordset.AddNew&quot;
 Dim i As Integer, iFieldsCount As Integer, oField As Object
-Dim sdefault As String, oColumn As Object
+Dim sDefault As String, oColumn As Object
 Dim iValue As Integer, lValue As Long, sgValue As Single, dbValue As Double, 
dValue As Date
 Dim vTemp As Variant
        If _ErrorHandler() Then On Local Error Goto Error_Function
@@ -192,16 +192,10 @@ Dim vTemp As Variant
                For i = 0 To iFieldsCount - 1
                        Set oField = Fields(i)
                        Set oColumn = oField.Column
-                       If Utils._hasUNOProperty(oColumn, 
&quot;DefaultValue&quot;) Then                        &apos;  Default value in 
database set via SQL statement
-                               sDefault = oColumn.DefaultValue
-                       ElseIf Utils._hasUNOProperty(oColumn, 
&quot;ControlDefault&quot;) Then  &apos;  Default value set in Base via table 
edition
-                                       If IsEmpty(oColumn.ControlDefault) Then 
sdefault = &quot;&quot; Else sDefault = oColumn.ControlDefault
-                       Else
-                                       sdefault = &quot;&quot;
-                       End If
-                       If sDefault = &quot;&quot; Then
+                       sDefault = oField.DefaultValue
+                       If sDefault = &quot;&quot; Then                         
&apos;  No default value
                                If oColumn.IsNullable = 
com.sun.star.sdbc.ColumnValue.NULLABLE Then oColumn.updateNull()
-                       Else                            &apos;  No default value
+                       Else
                                With com.sun.star.sdbc.DataType
                                        Select Case oColumn.Type
                                                Case .BIT, .BOOLEAN
@@ -232,13 +226,13 @@ Dim vTemp As Variant
                                                                        
&apos;If Abs(dbValue) &lt; 1.79769313486232E308 And Abs(dbValue) &gt; 
4.94065645841247E-307 Then oColumn.updateDouble(dbValue)
                                                                        
oColumn.updateDouble(dbValue)
                                                                Else
-                                                                       
oColumn.updateString(sdefault)
+                                                                       
oColumn.updateString(sDefault)
                                                                End If
                                                        Else
-                                                               
oColumn.updateString(sdefault)
+                                                               
oColumn.updateString(sDefault)
                                                        End If
                                                Case .CHAR, .VARCHAR, 
.LONGVARCHAR
-                                                       
oColumn.updateString(sdefault)                                          &apos;  
vbString
+                                                       
oColumn.updateString(sDefault)                                          &apos;  
vbString
                                                Case .DATE
                                                        dValue = 
DateValue(sDefault)
                                                        vTemp = New 
com.sun.star.util.Date
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to