IBM Domino: Merge NotesDocument From Two Databases - lotus-domino

I'm working on a function to union documents from two databases (normal database and archive database, the structures are same). I tried this code
Set result = db.CreateDocumentCollection
Call result.AddDocument(doc) 'doc is from another database
but there is an error "Error 4427: Document is from a different database". And I saw notesDocumentCollection.Merge also needs the documents to be in the same database. Is there any way to merge documents from two databases?

A NotesDocumentCollection object has a Parent property, which is a NotesDatabase. Internally, it is just a list of NoteIDs representing NotesDocument objects. Since NoteIds are not unique across databases, those NoteDocument objects have to be from the same NotesDatabase. The same thing is true for the NotesNoteCollection, too. If you need a collection that includes NotesDocuments from multiple databases, you're going to have to build your own class for that.

Related

Alternative to dynamic sql and for each loop

I need to execute the same select statement against 5 different instances of the same source db - 1 per clinic - and union the result set together for further processing. The existing script I've been tasked with maintaining executes a for each loop (1 iteration per instance) and substitutes the db name in the select statements for each iteration. Currently the db names are obtained from selecting the dbs from master where name in 'db 1, db2, db3, db4, db5'.
I'd prefer to hold a reference table with each of the db names and a flag for whether they are included. But is there an alternative to the for each loop?
So you have 5 different clinics and each one has a database with names: db1, db2, db3, db4, db5.
And the database names are all stored in a string variable as "db1, db2, db3, db4, db5" which you can then use as an array to sort through the database names.
Of course it seems clunky having all these different databases to have to deal with but looks like that is how things were when you got it and may have some advantages in that at least someone hacking or otherwise mishandling one clinic can't mess things up in the other databases.
And at least the looping isn't using something simple iteration like this:
For i = 1 to 5
strDBName = "db" & i
Next
A problem with using i to iterate is that what if clinic 2 is no longer active and thus db2 should no longer be used. And of course it there is a new clinic added then the "For i = 1 to 5" would need to be changed all over to be "For i = 1 to 6".
So considering the above worse ways of doing things I kind of like the current way (DB names in a string variable that can be looped through as an array). And the idea of possibly "hold a reference table with each of the db names and a flag for whether they are included" to me seems like a fancy way of doing what you're already doing and personally I'm all in favor of "keep it simple" and "if it ain't broke don't fix it."
EDIT:
But the more I think about it taking your "hold a reference table with each of the db names and a flag for whether they are included" idea and running with it a little bit the following does seem natural (but of course perhaps be sure only Admin users can see any fields about the specific database):
Clinics Table with Fields Such As:
ClinicID
ClinicName
ClinicAddress
ClinicDBName - Note could store the DB name here
ClinicIsInactive

How best to fill classes with hierarchical data from a relational database in VB.Net?

I have some relational data in a SQL Server 2008 database split across 3 tables, which I would like to use to populate some classes that represent them.
The hierarchy is: Products -> Variants -> Options.
I have considered passing back 3 result sets and using LINQ to check if there are any related/child records in the related tables. I've also considered passing back a single de-normalised table containing all of the data from the three tables and reading through the rows, manually figuring out where a product/variant/option begins and ends. Having little to no prior experience with LINQ, I opted to go for the latter, which sort of worked but required many lines of code for something that I had hoped would be pretty straight forward.
Is there an easier way of accomplishing this?
The end goal is to serialize the resulting classes to JSON, for use in a Web Service Application.
I've searched and searched on Google for an answer, but I guess I'm not searching for the right keywords.
After a bit of playing around, I've figured out a way of accomplishing this...
Firstly, create a stored procedure in SQL Server that will return the data as XML. It's relatively easy to generate an XML document containing hierarchical data.
CREATE PROCEDURE usp_test
AS
BEGIN
SELECT
1 AS ProductID
, 'Test' AS ProductDesc
, (
SELECT 1 AS VariantID
'Test'AS VariantDesc
FOR XML PATH('ProductVariant'), ROOT('ProductVariants'), TYPE
)
FOR XML PATH('Product'), ROOT('ArrayOfProduct'), TYPE
END
This gives you an XML document with a parent-child relationship:
<ArrayOfProduct>
<Product>
<ProductID>1</ProductID>
<ProductDesc>Test</ProductDesc>
<ProductVariants>
<ProductVariant>
<VariantID>1</VariantID>
<VariantDesc>Test</VariantDesc>
</ProductVariant>
</ProductVariants>
</Product>
</ArrayOfProduct>
Next, read in the results into the VB.Net application using a SqlDataReader. Declare an empty object to hold the data and deserialize the XML into the object using an XmlSerializer.
At this point, the data that once was in SQL tables is now represented as classes in your VB.Net application.
From here, you can then serialize the object into JSON using JavaScriptSerializer.Serialize.

How to query a specific collection from a RavenDB?

In one database, I am storing two separate documents - CumulativeSprintData and Features. I'm trying to query from javascript. Right now I'm just using the default:
http://servername:8080/databases/sprintprogress/indexes/dynamic?
The problem is that this default query pulls in documents of both types. How do I specify which document type I want to pull down?
Thanks!
You can use:
http://servername:8080/databases/sprintprogress/indexes/dynamic/Features
http://servername:8080/databases/sprintprogress/indexes/dynamic/CumulativeSprintDatas

How to manage multiple tables with the same structure (redux)

I found this question, which is similar to a problem that I would like to solve:
How to manage multiple tables with the same structure
However, due to the craptastical nature of VB, the solution doesn't really work. It specifically doesn't work because VB.NET requires the implementation of each method/property in the interface to be explicitly declared.
As for the problem that I'm really trying to solve, here it is:
I have many lookup/domain tables in the database that all have the same structure
The items in these tables are typically used for drop downs in the interface
I would like to avoid a bunch of boilerplate repository methods to retrieve the contents of these tables (one method per table really sucks when you have 40 tables)
I am not using the One True Lookup Table anti-pattern and this is not an option
Does anyone have another solution for this that work work in VB?
Generic Repository should work in this case. There are many available online or you can write a simpler one for just the lookup tables.
Here is the code that we ended up using:
Public Function GetDomainTableList(tableName As String) As IEnumerable(Of Object)
Dim table = CType(GetType(FECEntities).GetProperty(tableName).GetValue(DB, Nothing), IEnumerable(Of Object))
Dim dt = From r In table
Select r
Return dt.ToList()
End Function
I had originally thought that this wouldn't work for us since I was trying to project each object returned into a DomainTableItem class that I had written. But then I realized that the SelectList constructor didn't really care about the type of object that it takes in. You just pass in a String containing the property name and it uses reflection to pull out the value.
So everything works out peachy this way and I avoided writing one method per domain/lookup table.

Querying Access 2007 multi-valued fields using ODBC

I have an Access 2007 database that uses the "Attachment" datatype (new in Access 2007) for one of its field. This field is a magical "multi-valued" field that can contain several attachments.
I would like to be able to easily see the contents of this field, for all the rows in the database, using a single ODBC query. Ideally, each row of the original table should be exactly one row, and I'd like all the attachments returned as a single database cell. In a perfect world, it would be possible to reinsert that set of attachments into another table using a single INSERT INTO query.
I think that might be a tall order, so if I have to, I'd settle for:
An SQL query that tells me the number of attachments in a given attachment field
or worst case:
An SQL query that tells me whether or not the attachments in a given row are empty or not.
I can't seem to find any good docs about multi-valued fields around on the net. Perhaps they're too new.
Thoughts?
(P.S. Don't bother telling me that multi-valued fields are evil. I already know. I'm not the one who made the database.)
If you can use ADO then connect to the data source without using OLEDB:Support Complex Data=True in the connection string and query the column: you should get a column of type adLongVarWChar (i.e. MEMO) where the value is the file names delimited by semicolon characters. Therefore, getting a list of files will merely involve a simple parse.
It may be possible to get the attachments using ADO but I've yet to see it done. Using OLEDB:Support Complex Data=True means you will get a column of type adIDispatch i.e. an object. What that object is, I do not know (I hoped it would be a an ADODB.Recordset but no go).
See http://www.access-freak.com/tutorials.html#Tutorial07 for some information although he doesn't have a good screenshot or SQL of the query. His website isn't the best formatted or readable either.
This assumes you're running the query from inside Access 2007. If you want to run it via ODBC see http://groups.google.ca/group/microsoft.public.data.odbc/browse_thread/thread/d0ee29cc5e54e0fb