1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "adabas/BKeyColumns.hxx"
31 #ifndef _CONNECTIVITY_ADABAS_KEYCOLUMN_HXX_
32 #include "adabas/BKeyColumn.hxx"
33 #endif
34 #include <com/sun/star/sdbc/XRow.hpp>
35 #include <com/sun/star/sdbc/XResultSet.hpp>
36 #include <com/sun/star/sdbc/DataType.hpp>
37 #include <com/sun/star/sdbc/ColumnValue.hpp>
38 #include "adabas/BTable.hxx"
39 
40 using namespace connectivity::adabas;
41 // -------------------------------------------------------------------------
42 sdbcx::ObjectType OKeyColumns::createObject(const ::rtl::OUString& _rName)
43 {
44 
45 	Reference< starsdbc::XResultSet >
46 		xResult = m_pTable->getConnection()->getMetaData()->getImportedKeys(Any(),
47 					m_pTable->getSchema(),m_pTable->getName());
48 
49 	::rtl::OUString aRefColumnName;
50 	if(xResult.is())
51 	{
52 		Reference< starsdbc::XRow > xRow(xResult,UNO_QUERY);
53 		while(xResult->next())
54 		{
55 			if(xRow->getString(8) == _rName)
56 			{
57 				aRefColumnName = xRow->getString(4);
58 				break;
59 			}
60 		}
61 	}
62 
63 	 xResult = m_pTable->getConnection()->getMetaData()->getColumns(Any(),
64 		m_pTable->getSchema(),m_pTable->getName(),_rName);
65 
66 	sdbcx::ObjectType xRet = NULL;
67 	if(xResult.is())
68 	{
69 		Reference< starsdbc::XRow > xRow(xResult,UNO_QUERY);
70 		if(xResult->next())
71 		{
72 			if(xRow->getString(4) == _rName)
73 			{
74 				OKeyColumn* pRet = new OKeyColumn(aRefColumnName,
75 													_rName,
76 													xRow->getString(6),
77 													xRow->getString(13),
78 													xRow->getInt(11),
79 													xRow->getInt(7),
80 													xRow->getInt(9),
81 													xRow->getInt(5),
82 													sal_False);
83 				xRet = pRet;
84 			}
85 		}
86 	}
87 
88 	return xRet;
89 }
90 // -------------------------------------------------------------------------
91 Reference< XPropertySet > OKeyColumns::createDescriptor()
92 {
93 	OKeyColumn* pNew = new OKeyColumn();
94 	return pNew;
95 }
96 // -------------------------------------------------------------------------
97 
98