Hi,
I am trying to build a VBA code that would write multiple series to the database at once. I have successfully managed to implement an IDatabase.WriteObject Method but it is rather slow because it stores only one series at a time. According to "EViews Database Extension Interface" manual there is also an API method to write multiple objects into the database at once, called IDatabase.WriteObjects Method. Does anyone know how to implement this successfully?
Thank you,
Matej
API reference - IDatabase.WriteObjects Method
Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator
-
- Posts: 3
- Joined: Wed Jul 11, 2018 4:09 am
-
- EViews Developer
- Posts: 798
- Joined: Tue Sep 16, 2008 3:00 pm
- Location: Irvine, CA
Re: API reference - IDatabase.WriteObjects Method
Hmm, it seems like we left out the documentation for the EDX WriteObjects method in our docs. I guess most of our EDXs are read-only so most haven't run into this issue yet. We'll have to fix that.
In any case, I looked up how EViews calls WriteObjects and what get's passed in and what is expected back:
Basically, if an EViews STORE command is called for multiple objects (whether multiple names are specified or a name pattern is used), then WriteObjects will be called instead of the normal WriteObject.
WriteObjects takes the following parameters:
objectIds, attr, vals, & ids are similar to the parameters in WriteObject, but in WriteObjects these parameters represent an array of each associated value. For example, WriteObject::objectId is normally a single string name, but WriteObjects::objectIds is an array of string names. WriteObject::vals is an array of values for the object, but WriteObjects::vals is an array of an array of values (2 dimensional). Basically, whatever value is being passed into WriteObject, WriteObjects will get as an array of those same values, one for each object.
overwriteMode is the same as in WriteObject.
errors is the only new property and is designed to let your WriteObjects method report back potential multiple errors, one for each object. It is initially an empty value when passed in, but if you need to report an error, you'll have to initialize it as an array with the same number of elements as the objectIds array, then set the error code at the corresponding index for the object that you're currently working on. This error value should be the error code that you would normally throw as a COMException in a WriteObject method, for example:
To be clear, don't throw a COMException from WriteObjects if you only need to report an error for a single object, instead put the appropriate error code into the errors array (you can still throw a COMException if you run into a big issue that affects all of the objects). Once you return a non-empty errors array, EViews will loop thru it and report each problem back to the user.
In any case, I looked up how EViews calls WriteObjects and what get's passed in and what is expected back:
Basically, if an EViews STORE command is called for multiple objects (whether multiple names are specified or a name pattern is used), then WriteObjects will be called instead of the normal WriteObject.
WriteObjects takes the following parameters:
Code: Select all
Public Sub WriteObjects(ByRef errors As Object, _
ByRef objectIds As Object, _
ByVal attr As Object, _
ByVal vals As Object, _
ByVal ids As Object, _
ByVal overwriteMode As EViewsEdx.WriteType) Implements EViewsEdx.IDatabase.WriteObjects
objectIds, attr, vals, & ids are similar to the parameters in WriteObject, but in WriteObjects these parameters represent an array of each associated value. For example, WriteObject::objectId is normally a single string name, but WriteObjects::objectIds is an array of string names. WriteObject::vals is an array of values for the object, but WriteObjects::vals is an array of an array of values (2 dimensional). Basically, whatever value is being passed into WriteObject, WriteObjects will get as an array of those same values, one for each object.
overwriteMode is the same as in WriteObject.
errors is the only new property and is designed to let your WriteObjects method report back potential multiple errors, one for each object. It is initially an empty value when passed in, but if you need to report an error, you'll have to initialize it as an array with the same number of elements as the objectIds array, then set the error code at the corresponding index for the object that you're currently working on. This error value should be the error code that you would normally throw as a COMException in a WriteObject method, for example:
Code: Select all
Public Sub WriteObject(ByRef objectId As String, _
ByVal attr As Object, _
ByVal vals As Object, _
ByVal ids As Object, _
ByVal overwriteMode As EViewsEdx.WriteType) Implements EViewsEdx.IDatabase.WriteObject
Dim lsFilePath As String = msDatabaseId & "\" & LCase(objectId) & ".xml"
Select Case overwriteMode
Case EViewsEdx.WriteType.WriteProtect
'if the file already exists, don't overwrite it...
If System.IO.File.Exists(lsFilePath) Then
Throw New COMException("", EViewsEdx.ErrorCode.RECORD_NAME_IN_USE)
End If
To be clear, don't throw a COMException from WriteObjects if you only need to report an error for a single object, instead put the appropriate error code into the errors array (you can still throw a COMException if you run into a big issue that affects all of the objects). Once you return a non-empty errors array, EViews will loop thru it and report each problem back to the user.
-
- Posts: 3
- Joined: Wed Jul 11, 2018 4:09 am
Re: API reference - IDatabase.WriteObjects Method
This code throws Run-time error '445' Object doesn't support this action.
Any idea what I'm doing wrong?
Thank you.
Matej
Any idea what I'm doing wrong?
Thank you.
Matej
Code: Select all
Dim dbEV As IDatabase
dbPath = "C:\work\fmd\fmd.edb"
Dim dbMgr As EViewsEdx.EViewsDatabaseManager
Set dbMgr = New EViewsEdx.EViewsDatabaseManager
Set dbEV = dbMgr.OpenDb(dbPath, EViewsEdx.OpenCreateMode.FileOpen, EViewsEdx.ReadWriteMode.FileReadWrite, "", "", "")
Dim err_codes(1 To 2) As EViewsEdx.ErrorCode
Dim sname(1 To 2) As String
sname(1) = "ser1"
sname(2) = "ser2"
Dim vals(1 To 2, 1 To 2) As Double
vals(1, 1) = 1
vals(1, 2) = 2
vals(2, 1) = 3
vals(2, 2) = 4
Dim ids(1 To 2, 1 To 2) As Variant
ids(1, 1) = 2000
ids(1, 2) = 2001
ids(2, 1) = 2000
ids(2, 2) = 2001
Dim attr(1 To 2) As String
attr(1) = "freq=A"
attr(2) = "freq=A"
dbEV.WriteObjects err_codes, sname, attr, vals, ids, EViewsEdx.WriteType.WriteOverwrite
dbEV.Close
dbMgr.Close
-
- EViews Developer
- Posts: 798
- Joined: Tue Sep 16, 2008 3:00 pm
- Location: Irvine, CA
Re: API reference - IDatabase.WriteObjects Method
I looked at the object being returned by EViewsDatabaseManager and that object only implemented WriteObject. WriteObjects throws a "Not implemented" COM error like you're seeing. But I can tell you that even if WriteObjects had been implemented, our code can really only write a single object into the database at a time so I don't think it would save you that much time. This method is more of a convenience method.
If you're looking for fast ways to write data to an EViews database, have you tried our COM Automation interface?
Steve
If you're looking for fast ways to write data to an EViews database, have you tried our COM Automation interface?
Steve
-
- Posts: 3
- Joined: Wed Jul 11, 2018 4:09 am
Re: API reference - IDatabase.WriteObjects Method
Thank you for suggesting an alternative. I will try to implement it and see if there is a difference.
Who is online
Users browsing this forum: No registered users and 31 guests