[Libreoffice-commits] core.git: wizards/source

Jean-Pierre Ledure jp at ledure.be
Thu Apr 27 14:23:33 UTC 2017


 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 <jp at 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				'	com.sun.star.sdb.OTableColumnWrapper
 											'			or	org.openoffice.comp.dbaccess.OQueryColumn
 											'			or	com.sun.star.sdb.ODataColumn
@@ -33,6 +35,8 @@ Private Sub Class_Initialize()
 	_Name = ""
 	_ParentName = ""
 	_ParentType = ""
+	_DefaultValue = ""
+	_DefaultValueSet = False
 	Set Column = Nothing
 End Sub		'	Constructor
 
@@ -379,7 +383,7 @@ Private Function _PropertiesList() As Variant
 								, "Description", "Name", "ObjectType", "Size", "SourceField", "SourceTable" _
 								, "TypeName" _
 								)
-		Case OBJRECORDSET
+		Case OBJRECORDSET			
 			_PropertiesList = Array("DataType", "DataUpdatable",  "dbType", "DefaultValue" _
 								, "Description" , "FieldSize", "Name", "ObjectType" _
 								, "Size", "SourceTable", "TypeName", "Value" _
@@ -450,13 +454,18 @@ Const cstMaxBinlength = 2 * 65535
 				If Column.IsAutoIncrement Then _PropertyGet = False			'	Forces False if auto-increment (MSAccess)
 			End If
 		Case UCase("DefaultValue")
-			If Utils._hasUNOProperty(Column, "DefaultValue") Then			'	Default value in database set via SQL statement
-				_PropertyGet = Column.DefaultValue
-			ElseIf Utils._hasUNOProperty(Column, "ControlDefault") Then		'	Default value set in Base via table edition
-			 	If IsEmpty(Column.ControlDefault) Then _PropertyGet = "" Else _PropertyGet = Column.ControlDefault
-			Else
-			 	_PropertyGet = ""
+			'	default value buffered to avoid multiple calls
+			If Not _DefaultValueSet Then
+				If Utils._hasUNOProperty(Column, "DefaultValue") Then			'	Default value in database set via SQL statement
+					_DefaultValue = Column.DefaultValue
+				ElseIf Utils._hasUNOProperty(Column, "ControlDefault") Then		'	Default value set in Base via table edition
+				 	If IsEmpty(Column.ControlDefault) Then _DefaultValue = "" Else _DefaultValue = Column.ControlDefault
+				Else
+				 	_DefaultValue = ""
+				End If
+				_DefaultValueSet = True
 			End If
+			_PropertyGet = _DefaultValue
 		Case UCase("Description")
 			bCond1 = Utils._hasUNOProperty(Column, "Description")
 			bCond2 = Utils._hasUNOProperty(Column, "HelpText")
@@ -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, "ControlDefault") Then			'	Default value set in Base via table edition
 			 	Column.ControlDefault = pvValue
+			 	_DefaultValue = pvValue
+			 	_DefaultValueSet = True
 			End If
 		Case UCase("Description")
 			If _ParentType <> 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 = "Recordset.AddNew"
 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, "DefaultValue") Then			'	Default value in database set via SQL statement
-				sDefault = oColumn.DefaultValue
-			ElseIf Utils._hasUNOProperty(oColumn, "ControlDefault") Then	'	Default value set in Base via table edition
-					If IsEmpty(oColumn.ControlDefault) Then sdefault = "" Else sDefault = oColumn.ControlDefault
-			Else
-					sdefault = ""
-			End If
-			If sDefault = "" Then
+			sDefault = oField.DefaultValue
+			If sDefault = "" Then				'	No default value
 				If oColumn.IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE Then oColumn.updateNull()
-			Else				'	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
 									'If Abs(dbValue) < 1.79769313486232E308 And Abs(dbValue) > 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)						'	vbString
+							oColumn.updateString(sDefault)						'	vbString
 						Case .DATE
 							dValue = DateValue(sDefault)
 							vTemp = New com.sun.star.util.Date


More information about the Libreoffice-commits mailing list