PC Review


Reply
Thread Tools Rate Thread

How do I determine the relationships between these tables?

 
 
NorCan
Guest
Posts: n/a
 
      15th Aug 2005
Hi

I'm writing an application that will update a database with data from a
legacy application. The data is provided as small XML fragments, one for
each insert/update/delete required. For example:

<COMPANY>
<INSERT>
<COMPANY_ID value='269'/>
<COMPANY_NAME value='Acme Inc'/>
</INSERT>
</COMPANY>

<EMPLOYEE>
<INSERT>
<EMPLOYEE_ID value='1008'/>
<COMPANY_ID value='269'/>
<EMPLOYEE_NAME value='Bill Gates'/>
</INSERT>
</EMPLOYEE>

The root element is the name of the table, the next is what action to
take (insert, update or delete), then follows the actual data.

After reading all of these fragments into a dataset I have a dataset
with several tables, but no relations or constraints. This is a problem
when it comes to updating the database, where this is in place.

The main problem, however, is that the tables involved can vary (it's
not always the COMPANY and EMPLOYEE tables, it can be any tables,
sometimes more than two). This means that I can't hard-code anything, or
make any assumptions on the table names or their relations.

So once I have this dataset with all the data, how do I figure out the
order in which I should update the tables? My plan was to retrieve the
necessary relationship and constraint information from the database, but
how do I do that?

I may also need a way to determine which columns are the primary key(s)
of the tables involved. Is it possible to get this from a query, without
querying the system tables?

PS: The database is a FireBird database and I'm using an OdbcDataAdapter
to connect.


Thanks in advance.

-Frode
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
Guest
Posts: n/a
 
      15th Aug 2005
I am not sure you really have an "on the fly" need, but it can be done via
ADOX. In .NET, you will need to use Interop. ADOX is a COM library that
installs with the MDAC (which will be installed on your machine due to a .NET
requirement).

I had some R&D code with ADOX, but I am not sure where it is now. If I find
it (against a Cache database), I can post it. It will not be Firebird, but
the basic methodology is the same:

1. Set up a proper conn string
2. Connect
3. Query schema

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************


"NorCan" wrote:

> Hi
>
> I'm writing an application that will update a database with data from a
> legacy application. The data is provided as small XML fragments, one for
> each insert/update/delete required. For example:
>
> <COMPANY>
> <INSERT>
> <COMPANY_ID value='269'/>
> <COMPANY_NAME value='Acme Inc'/>
> </INSERT>
> </COMPANY>
>
> <EMPLOYEE>
> <INSERT>
> <EMPLOYEE_ID value='1008'/>
> <COMPANY_ID value='269'/>
> <EMPLOYEE_NAME value='Bill Gates'/>
> </INSERT>
> </EMPLOYEE>
>
> The root element is the name of the table, the next is what action to
> take (insert, update or delete), then follows the actual data.
>
> After reading all of these fragments into a dataset I have a dataset
> with several tables, but no relations or constraints. This is a problem
> when it comes to updating the database, where this is in place.
>
> The main problem, however, is that the tables involved can vary (it's
> not always the COMPANY and EMPLOYEE tables, it can be any tables,
> sometimes more than two). This means that I can't hard-code anything, or
> make any assumptions on the table names or their relations.
>
> So once I have this dataset with all the data, how do I figure out the
> order in which I should update the tables? My plan was to retrieve the
> necessary relationship and constraint information from the database, but
> how do I do that?
>
> I may also need a way to determine which columns are the primary key(s)
> of the tables involved. Is it possible to get this from a query, without
> querying the system tables?
>
> PS: The database is a FireBird database and I'm using an OdbcDataAdapter
> to connect.
>
>
> Thanks in advance.
>
> -Frode
>

 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      15th Aug 2005
Hi Gregory,

This functionatlity in .net 1.x is wrapped in
OleDbSchema.GetOleDbScemaTable.
If you are using ODBC then you are stuck with Firebird specific DDL (data
definition language).
OP: Why aren't you using Firebird's native or OleDb provieder?
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Cowboy (Gregory A. Beamer) - MVP" <(E-Mail Removed)> wrote
in message news:F0D3B3E6-FB0F-4BD1-A8D3-(E-Mail Removed)...
>I am not sure you really have an "on the fly" need, but it can be done via
> ADOX. In .NET, you will need to use Interop. ADOX is a COM library that
> installs with the MDAC (which will be installed on your machine due to a
> .NET
> requirement).
>
> I had some R&D code with ADOX, but I am not sure where it is now. If I
> find
> it (against a Cache database), I can post it. It will not be Firebird, but
> the basic methodology is the same:
>
> 1. Set up a proper conn string
> 2. Connect
> 3. Query schema
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> ***************************
> Think Outside the Box!
> ***************************
>
>
> "NorCan" wrote:
>
>> Hi
>>
>> I'm writing an application that will update a database with data from a
>> legacy application. The data is provided as small XML fragments, one for
>> each insert/update/delete required. For example:
>>
>> <COMPANY>
>> <INSERT>
>> <COMPANY_ID value='269'/>
>> <COMPANY_NAME value='Acme Inc'/>
>> </INSERT>
>> </COMPANY>
>>
>> <EMPLOYEE>
>> <INSERT>
>> <EMPLOYEE_ID value='1008'/>
>> <COMPANY_ID value='269'/>
>> <EMPLOYEE_NAME value='Bill Gates'/>
>> </INSERT>
>> </EMPLOYEE>
>>
>> The root element is the name of the table, the next is what action to
>> take (insert, update or delete), then follows the actual data.
>>
>> After reading all of these fragments into a dataset I have a dataset
>> with several tables, but no relations or constraints. This is a problem
>> when it comes to updating the database, where this is in place.
>>
>> The main problem, however, is that the tables involved can vary (it's
>> not always the COMPANY and EMPLOYEE tables, it can be any tables,
>> sometimes more than two). This means that I can't hard-code anything, or
>> make any assumptions on the table names or their relations.
>>
>> So once I have this dataset with all the data, how do I figure out the
>> order in which I should update the tables? My plan was to retrieve the
>> necessary relationship and constraint information from the database, but
>> how do I do that?
>>
>> I may also need a way to determine which columns are the primary key(s)
>> of the tables involved. Is it possible to get this from a query, without
>> querying the system tables?
>>
>> PS: The database is a FireBird database and I'm using an OdbcDataAdapter
>> to connect.
>>
>>
>> Thanks in advance.
>>
>> -Frode
>>



 
Reply With Quote
 
NorCan
Guest
Posts: n/a
 
      16th Aug 2005
Thank you for your response, I will check this out further to see of it
meets my needs.

I have just started at this job, and was asked to stick to ODBC because
they don't want the code to be tied to a specific database provider, in
case they decide to replace Firebird in the future.


Regards,
Frode

Miha Markic [MVP C#] wrote:
> Hi Gregory,
>
> This functionatlity in .net 1.x is wrapped in
> OleDbSchema.GetOleDbScemaTable.
> If you are using ODBC then you are stuck with Firebird specific DDL (data
> definition language).
> OP: Why aren't you using Firebird's native or OleDb provieder?

 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      16th Aug 2005
You have two other options then:
- use a factory pattern and use database specific managed providers (most
powerfull)
- use OleDb which is a better choice over Odbc I would say

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"NorCan" <(E-Mail Removed)> wrote in message
news:%237%(E-Mail Removed)...
> Thank you for your response, I will check this out further to see of it
> meets my needs.
>
> I have just started at this job, and was asked to stick to ODBC because
> they don't want the code to be tied to a specific database provider, in
> case they decide to replace Firebird in the future.
>
>
> Regards,
> Frode
>
> Miha Markic [MVP C#] wrote:
>> Hi Gregory,
>>
>> This functionatlity in .net 1.x is wrapped in
>> OleDbSchema.GetOleDbScemaTable.
>> If you are using ODBC then you are stuck with Firebird specific DDL (data
>> definition language).
>> OP: Why aren't you using Firebird's native or OleDb provieder?



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Database, trying to determine keys and relationships joe@businesstechnologies1.com Microsoft Access Getting Started 1 10th Jun 2009 12:01 AM
how to determine relationships between xp services? jjoensuu Windows XP General 5 15th May 2007 06:46 PM
how to determine relationships between xp services? jjoensuu Windows XP Performance 5 15th May 2007 06:46 PM
how to determine relationships between xp services? jjoensuu Windows XP Security 5 15th May 2007 06:46 PM
Relationships and Tables =?Utf-8?B?VGlh?= Microsoft Access 8 28th Apr 2005 08:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:00 AM.