| View previous topic :: View next topic |
| Author |
Message |
Crusty General User

Joined: 11 Mar 2004 Posts: 8
|
Posted: Wed Jun 30, 2004 6:40 am Post subject: Add CSV Datasource with Visual FoxPro |
|
|
Hello,
I tried to add an csv-datasource but the result of this code is an exception of OpenOffice ( UnknownPropertyException - code 1001) (In the last line of code..).
The parameters in the the array are ok, because I tested them with StarBasic... There were no errors....
Has anyone an idea where the mistake of this code-snippet is?
Eventuelly a wrong datatype or something else?
| Code: |
DBContext = oo.omanager.CreateInstance("com.sun.star.sdb.DatabaseContext")
dsource = oo.omanager.CreateInstance("com.sun.star.sdb.DataSource")
DBContext.registerObject("test", dsource)
DIMENSION laFlatProp[7]
laFlatProp[1] = oo.oManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laFlatProp[1].NAME = "Extension"
laFlatProp[1].VALUE = "csv"
laFlatProp[2] = oo.oManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laFlatProp[2].NAME = "FixedLength"
laFlatProp[2].VALUE = .T.
laFlatProp[3] = oo.oManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laFlatProp[3].NAME = "HeaderLine"
laFlatProp[3].VALUE = .T.
laFlatProp[4] = oo.oManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laFlatProp[4].NAME = "FieldDelimiter"
laFlatProp[4].VALUE = ","
laFlatProp[5] = oo.oManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laFlatProp[5].NAME = "StringDelimiter"
laFlatProp[5].VALUE = "'"
laFlatProp[6] = oo.oManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laFlatProp[6].NAME = "DecimalDelimiter"
laFlatProp[6].VALUE = "."
laFlatProp[7] = oo.oManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laFlatProp[7].NAME = "ThousandDelimiter"
laFlatProp[7].VALUE = ","
loDataSource = DBContext.getByName("test")
COMARRAY(loDataSource,10)
loDataSource.setPropertyValue("URL", "sdbc:flat:file:///c:/temp/")
loDataSource.setPropertyValue("info", @laflatProp)
|
|
|
| Back to top |
|
 |
Guest
|
Posted: Thu Jul 01, 2004 2:29 am Post subject: |
|
|
Now I found one mistake...
The info parameter (with the array) musst be written like "Info" and not "info"..
The Exception is now "illegalAgumentException" called. I don't understand which of this
parameters should be wrong!?!?!  |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Thu Jul 01, 2004 5:45 am Post subject: |
|
|
I tried your example in OOo Basic....
| Code: | Sub Main
oDBContext = createUnoService( "com.sun.star.sdb.DatabaseContext" )
If Not oDBContext.hasByName( "test" ) Then
oDataSource = createUnoService( "com.sun.star.sdb.DataSource" )
oDBContext.registerObject( "test", oDataSource )
EndIf
oDataSource = oDBContext.getByName( "test" )
oDataSource.setPropertyValue( "URL", "sdbc:flat:file:///c:/temp/" )
oDataSource.setPropertyValue( "info",_
Array(_
MakePropertyValue( "Extension", "csv" ),_
MakePropertyValue( "FixedLength", True ),_
MakePropertyValue( "HeaderLine", True ),_
MakePropertyValue( "FieldDelimiter", "," ),_
MakePropertyValue( "StringDelimiter", "'" ),_
MakePropertyValue( "DecimalDelimiter", "." ),_
MakePropertyValue( "ThousandDelimiter", "," ) ) )
End Sub
Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function
|
I get the same exception.
So I independantly discovered the same thing, that if I rewrite to....
| Code: | oDataSource.Info = _
Array(_
MakePropertyValue( "Extension", "csv" ),_
MakePropertyValue( "FixedLength", True ),_
MakePropertyValue( "HeaderLine", True ),_
MakePropertyValue( "FieldDelimiter", "," ),_
MakePropertyValue( "StringDelimiter", "'" ),_
MakePropertyValue( "DecimalDelimiter", "." ),_
MakePropertyValue( "ThousandDelimiter", "," ) )
|
It works. I do not get any exception. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
Crusty General User

Joined: 11 Mar 2004 Posts: 8
|
Posted: Thu Jul 01, 2004 6:23 am Post subject: |
|
|
In your first sample you wrote "info" but you must write "Info".. I think that is the actuator of the exception  |
|
| Back to top |
|
 |
Crusty General User

Joined: 11 Mar 2004 Posts: 8
|
Posted: Thu Jul 01, 2004 6:31 am Post subject: |
|
|
This is another variant , that runs without execeptions.
But my problem is to understand differences between this BASIC Code and my Visual FoxPro Code? Why work the VFP code not without exceptions?
| Code: |
sub Main
DBContext = createUnoService("com.sun.star.sdb.DatabaseContext")
dsource = createUnoService("com.sun.star.sdb.DataSource")
If DBContext.hasByName("test") Then
DBContext.revokeObject("test")
Endif
DBContext.registerObject("test", dsource)
Dim flatProp(0) As New com.sun.star.beans.PropertyValue
flatProp(0).Name = "Extension"
flatProp(0).Value = "csv" ' string
flatProp(0).Name = "HeaderLine"
flatProp(0).Value = True ' boolean
flatProp(1).Name = "FieldDelimiter"
flatProp(1).Value = ";" ' string
flatProp(3).Name = "DecimalDelimiter"
flatProp(3).Value = "." ' string
flatProp(4).Name = "ThousandDelimiter"
flatProp(4).Value = "," ' string
dsource.setPropertyValue("URL", "sdbc:flat:file:///c:/temp/")
dsource.setPropertyValue("Info", flatProp())
end sub
|
|
|
| Back to top |
|
 |
Crusty General User

Joined: 11 Mar 2004 Posts: 8
|
Posted: Thu Jul 01, 2004 6:34 am Post subject: |
|
|
sorry, a little mistake...
that is the right BASIC code:
| Code: |
sub Main
DBContext = createUnoService("com.sun.star.sdb.DatabaseContext")
dsource = createUnoService("com.sun.star.sdb.DataSource")
If DBContext.hasByName("test") Then
DBContext.revokeObject("test")
Endif
DBContext.registerObject("test", dsource)
Dim flatProp(0) As New com.sun.star.beans.PropertyValue
flatProp(0).Name = "Extension"
flatProp(0).Value = "csv" ' string
flatProp(1).Name = "CharSet"
flatProp(1).Value = ' string
flatProp(2).Name = "FixedLength"
flatProp(2).Value = True ' boolean
flatProp(3).Name = "HeaderLine"
flatProp(3).Value = True ' boolean
flatProp(4).Name = "FieldDelimiter"
flatProp(4).Value = ";" ' string
flatProp(5).Name = "StringDelimiter"
flatProp(5).Value = ' string
flatProp(6).Name = "DecimalDelimiter"
flatProp(6).Value = "." ' string
flatProp(7).Name = "ThousandDelimiter"
flatProp(7).Value = "," ' string
dsource.setPropertyValue("URL", "sdbc:flat:file:///c:/temp/")
dsource.setPropertyValue("Info", flatProp())
end sub
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|