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

Jean-Pierre Ledure jp at ledure.be
Sun May 22 15:29:54 UTC 2016


 wizards/source/access2base/Database.xba |    4 +-
 wizards/source/access2base/Utils.xba    |   55 ++++++++++++++++++++++++++------
 2 files changed, 48 insertions(+), 11 deletions(-)

New commits:
commit 4b9c8b6682c7912fc4485baae3aa6ecb99fa0bb3
Author: Jean-Pierre Ledure <jp at ledure.be>
Date:   Sun May 22 17:23:34 2016 +0200

    Access2Base - Long binary and char fields in database functions
    
    Review of Utils._getResultSetColumnValue()
    to include LOGVARCHAR and LONGVARBINARY field types
    
    Change-Id: Id1bd073a8f7d910377d7e1ecca96d682cd856946

diff --git a/wizards/source/access2base/Database.xba b/wizards/source/access2base/Database.xba
index 968d394..d022d4c 100644
--- a/wizards/source/access2base/Database.xba
+++ b/wizards/source/access2base/Database.xba
@@ -1013,7 +1013,7 @@ Dim sTarget as String, sWhere As String, sOrderBy As String, sLimit As String
 		Set oResult = .executeQuery(sSql)
 	    If Not IsNull(oResult) And Not IsEmpty(oResult) Then
    				If Not oResult.next() Then Goto Exit_Function
-       		    vResult = Utils._getResultSetColumnValue(oResult, 1)
+       		    vResult = Utils._getResultSetColumnValue(oResult, 1, True)		'	Force return of binary field
     	End If
    	End With
 
@@ -1026,7 +1026,7 @@ Exit_Function:
 Error_Function:
     TraceError(TRACEABORT, ERRDFUNCTION, _A2B_.CalledSub, 0, , sSQL)
     Goto Exit_Function
-End Function		'	DFunction		V1.1.0
+End Function		'	DFunction		V1.5.0
 
 REM -----------------------------------------------------------------------------------------------------------------------
 Private Function _FilterOptionsDefault(ByVal plEncoding As Long) As String
diff --git a/wizards/source/access2base/Utils.xba b/wizards/source/access2base/Utils.xba
index 6f9135c..8390dee 100644
--- a/wizards/source/access2base/Utils.xba
+++ b/wizards/source/access2base/Utils.xba
@@ -198,28 +198,48 @@ Dim oPip As Object, sLocation As String
 End Function	'	ExtensionLocation
 
 REM -----------------------------------------------------------------------------------------------------------------------
-Private Function _getResultSetColumnValue(poResultSet As Object, Byval piColIndex As Integer) As Variant
+Private Function _getResultSetColumnValue(poResultSet As Object _
+											, ByVal piColIndex As Integer _
+											, Optional ByVal pbReturnBinary As Boolean _
+											) As Variant
 REM Modified from Roberto Benitez's BaseTools
 REM get the data for the column specified by ColIndex
+REM If pbReturnBinary = False (default) then return length of binary field
 REM get type name from metadata
 	
 Dim vValue As Variant, sType As String, vDateTime As Variant, oValue As Object
+Dim bNullable As Boolean, lSize As Long
+Const cstMaxTextLength = 65535
+Const cstMaxBinlength = 2 * 65535
 
 	On Local Error Goto 0			'	Disable error handler
 	vValue = Null					'	Default value if error
-	sType = poResultSet.MetaData.getColumnTypeName(piColIndex)
+	If IsMissing(pbReturnBinary) Then pbReturnBinary = False
 	With poResultSet
+		sType = .MetaData.getColumnTypeName(piColIndex)
+		bNullable = ( .MetaData.IsNullable(piColIndex) = com.sun.star.sdbc.ColumnValue.NULLABLE )
 		Select Case sType
 			Case "ARRAY":							vValue = .getArray(piColIndex)
-			Case "BINARY", "VARBINARY", "LONGVARBINARY"
+			Case "BINARY", "VARBINARY", "LONGVARBINARY", "BLOB"
 													Set oValue = .getBinaryStream(piColIndex)
-													If Not .wasNull() Then vValue = CLng(oValue.getLength())		'	Return length, not content
+													If bNullable Then
+														If Not .wasNull() Then
+															If Not _hasUNOMethod(oValue, "getLength") Then	'	When no recordset
+																lSize = cstMaxBinLength
+															Else
+																lSize = CLng(oValue.getLength())
+															End If
+															If lSize <= cstMaxBinLength And pbReturnBinary Then
+																vValue = Array()
+																oValue.readBytes(vValue, lSize)
+															Else	'	Return length of field, not content
+															End If
+														End If
+													End If
 													oValue.closeInput()
-			Case "BLOB":							vValue = .getBlob(piColIndex)
 			Case "BIT", "BOOLEAN":					vValue = .getBoolean(piColIndex)
 			Case "BYTE":							vValue = .getByte(piColIndex)
 			Case "BYTES":							vValue = .getBytes(piColIndex)
-			Case "CLOB":							vValue = .getClob(piColIndex)
 			Case "DATE":							vDateTime = .getDate(piColIndex)
 													If Not .wasNull() Then vValue = DateSerial(CInt(vDateTime.Year), CInt(vDateTime.Month), CInt(vDateTime.Day))
 			Case "DOUBLE", "REAL":					vValue = .getDouble(piColIndex)
@@ -231,7 +251,22 @@ Dim vValue As Variant, sType As String, vDateTime As Variant, oValue As Object
 			Case "OBJECT":							vValue = Null	'	.getObject(piColIndex)	does not work that well in Basic ...
 			Case "REF":								vValue = .getRef(piColIndex)
 			Case "SHORT", "TINYINT":				vValue = .getShort(piColIndex)
-			Case "CHAR", "VARCHAR", "LONGVARCHAR":	vValue = .getString(piColIndex)
+			Case "CHAR", "VARCHAR":					vValue = .getString(piColIndex)
+			Case "LONGVARCHAR", "CLOB"
+													Set oValue = .getCharacterStream(piColIndex)
+													If bNullable Then
+														If Not .wasNull() Then
+															If Not _hasUNOMethod(oValue, "getLength") Then	'	When no recordset
+																lSize = cstMaxTextLength
+															Else
+																lSize = CLng(oValue.getLength())
+															End If
+															oValue.closeInput()
+															If lSize <= cstMaxBinLength Then vValue = .getString(piColIndex) Else vValue = ""
+														End If
+													Else
+														oValue.closeInput()
+													End If
 			Case "TIME":							vDateTime = .getTime(piColIndex)
 													If Not .wasNull() Then vValue = TimeSerial(vDateTime.Hours, vDateTime.Minutes, vDateTime.Seconds)', vDateTime.HundredthSeconds)
 			Case "TIMESTAMP":						vDateTime = .getTimeStamp(piColIndex)
@@ -241,12 +276,14 @@ Dim vValue As Variant, sType As String, vDateTime As Variant, oValue As Object
 				vValue = .getString(piColIndex)						'GIVE STRING A TRY
 				If IsNumeric(vValue) Then vValue = Val(vValue)		'Required when type = "", sometimes numeric fields are returned as strings (query/MSAccess)
 		End Select
-		If .wasNull() Then vValue = Null
+		If bNullable Then
+			If .wasNull() Then vValue = Null
+		End If
 	End With
 	
 	_getResultSetColumnValue = vValue
 	
-End Function	'	getResultSetColumnValue		V 1.1.0
+End Function	'	getResultSetColumnValue		V 1.5.0
 
 REM -----------------------------------------------------------------------------------------------------------------------
 Public Function _FinalProperty(psShortcut As String) As String


More information about the Libreoffice-commits mailing list