OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Problems declaring and opening a flat file data source - com

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
n4hpg
General User
General User


Joined: 21 Jan 2004
Posts: 12
Location: north carolina

PostPosted: Thu Jan 29, 2004 3:04 pm    Post subject: Problems declaring and opening a flat file data source - com Reply with quote

Hi All,

Work in progress. I'm trying to open OO and merge from the command line. The problem that I'm having is being able to get the flat file data source to be open for editiing. The application is setting up the flat file data source, but OO won't open it.

DataSource appears to be empty. I can see the data source when operating from the dialog inside OO. The metadata shows only "sdbc:flat" and not the full URL to the data source.

HELP!

Thanks,

Bill
Sub Main
Dim Frame as Object
Dim Doc as Object
Dim Merge as Object
Dim MergeProps as Object
Dim Dummy as Array
Dim DataSource as Object
Dim DatabaseContext as Object
Dim Tables as Object
Dim TableName as String
Dim TableDescriptor as Object
Dim Connection as Object
msgbox("hi mom")
' start our testing
Frame = createUnoService("com.sun.star.frame.Desktop")
if Frame.isactive then
msgbox("frame is active")
end if
DocFile = "file:///home/mfx400/bill.sxw"
DatFile = "sdbc:flat:file:///home/mfx400/mfx.txt"
OutFile = "file:///home/mfx400/out.ps"
TableName = "mfx.txt"
Doc = Frame.loadComponentFromURL(DocFile, "_blank", 0, Dummy())
' jim's stuff
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DatabaseContext.revokeObject("MfxDataSource")
DataSource = DatabaseContext.createInstance()
DataSource.URL = Datfile
DatabaseContext.registerObject("MfxDataSource", DataSource)

Connection = DataSource.getConnection("", "")
msgbox(connection.getmetadata().geturl) ' this shows only "sdbc:flat"
'AT THIS POINT, WE DON'T SEE THE FULL CONNECTION INFORMATION
s = ""
'Loop through .Info array of DataSource
for i = LBound (DataSource.Info) to UBound (DataSource.Info)
'Get name & value for each element in .Info array
s = s & DataSource.Info(i).Name & "=" & DataSource.Info(i).Value & chr(10)
next i
msgbox s

msgbox ("hi dad")
' DatabaseContext.revokeObject("MfxDataSource")
End Sub
Rolling Eyes
Back to top
View user's profile Send private message Visit poster's website
avantman42
Super User
Super User


Joined: 28 Jul 2003
Posts: 751
Location: Staffordshire, UK

PostPosted: Fri Jan 30, 2004 2:08 am    Post subject: Re: Problems declaring and opening a flat file data source - Reply with quote

I think the problem is here:

Code:

   DataSource.URL = Datfile
    DatabaseContext.registerObject("MfxDataSource", DataSource)


I suspect you might have to register the object, then set the URL. Try swapping those two lines around.

Russ
Back to top
View user's profile Send private message
n4hpg
General User
General User


Joined: 21 Jan 2004
Posts: 12
Location: north carolina

PostPosted: Fri Jan 30, 2004 5:36 am    Post subject: Still no luck Reply with quote

Russ,

I moved the lines around as you suggested. The DataSource is still not linked.

I think there is an issue with declaring a table as well. When I use the dialog to create a datasource, it sets the URL to the directory level. I then need to go and select a file to use, the type of file, delimiters, etc. This is all missing from this code module and I've not been able to find the documentation for it.

OO has lots of documentation!

Bill
Back to top
View user's profile Send private message Visit poster's website
avantman42
Super User
Super User


Joined: 28 Jul 2003
Posts: 751
Location: Staffordshire, UK

PostPosted: Fri Jan 30, 2004 5:40 am    Post subject: Reply with quote

Is this post of any use?
http://www.oooforum.org/forum/viewtopic.php?p=19192#19192

Russ
Back to top
View user's profile Send private message
n4hpg
General User
General User


Joined: 21 Jan 2004
Posts: 12
Location: north carolina

PostPosted: Fri Jan 30, 2004 5:57 am    Post subject: I don't see the table declaration in the reply Reply with quote

Russ,

Thanks for the link.

I've looked thorough it and still don't see how the other fellow is linking to the file.

The handy diagnostic loop that you show as the last part of the thread is already included in my macro. the MsgBox does display at that point in script execution; however, it shows no data.

It appears that the DataSource.URL is pointed at the directory level. This is consistent with the dialog box. What seems to be missing is the table type definition with the properties for the table such as header, delimiter, text delimiter, etc. Then the actual selection of the TABLE to complete the link.

User jbotte works with me. He and I have examined the internal XML storage and see that OO is storing the name of the file: in our case mfx.txt as 2 separate components. One with mfx and the .txt extension in another XML. Presumably the rest of the properties are there as well. Therefore, I presume that I must declare the properties using the macro in order to complete the connection.

Once the connection is completed, the user may then select the fields.

After this macro runs, we have the bill.sxw on the screen, MfxDataSource is registerd. Going to the the MailMerge dialog and clicking on MfxDataSource shows a number of 'tables' all of which are hidden files in the linux directory whereas I want mfx.txt to show as the table. Clicking on the mfx table should reveal the header row merge fields.

bill
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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