1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include <connectivity/sqlparse.hxx>
27cdf0e10cSrcweir #include "connectivity/sqliterator.hxx"
28cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
34cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
36cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
37cdf0e10cSrcweir #include <unotools/processfactory.hxx>
38cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
39cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriver.hpp>
41cdf0e10cSrcweir #include "connectivity/sqlnode.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace connectivity;
44cdf0e10cSrcweir using namespace com::sun::star::sdbc;
45cdf0e10cSrcweir using namespace com::sun::star;
46cdf0e10cSrcweir using namespace com::sun::star::uno;
47cdf0e10cSrcweir using namespace com::sun::star::beans;
48cdf0e10cSrcweir using namespace rtl;
49cdf0e10cSrcweir using namespace cppu;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #if (defined UNX) || (defined OS2)
main(int argc,char * argv[])53cdf0e10cSrcweir void main( int argc, char * argv[] )
54cdf0e10cSrcweir #else
55cdf0e10cSrcweir void _cdecl main( int argc, char * argv[] )
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir 
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>	m_xConnection;
60cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver>		m_xDriver;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	try{
63cdf0e10cSrcweir 		Reference< ::com::sun::star::lang::XMultiServiceFactory > xFac =
64cdf0e10cSrcweir 				createRegistryServiceFactory(OUString::createFromAscii("g:\\office50\\program\\applicat.rdb"),OUString());
65cdf0e10cSrcweir 		if(!xFac.is())
66cdf0e10cSrcweir 			return;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 		m_xDriver = Reference<XDriver>(xFac->createInstance(OUString::createFromAscii("com.sun.star.sdbc.driver.dbase.Driver")),UNO_QUERY);
69cdf0e10cSrcweir 		if(m_xDriver.is())
70cdf0e10cSrcweir 		{
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 			Sequence<PropertyValue> aValue;
73cdf0e10cSrcweir 	//		aValue.getArray()[0] = PropertyValue( OUString::createFromAscii("user"),0,makeAny(OUString::createFromAscii("TEST1")),PropertyState_DIRECT_VALUE);
74cdf0e10cSrcweir 	//		aValue.getArray()[1] = PropertyValue( OUString::createFromAscii("password"),0,makeAny(OUString::createFromAscii("TEST1")),PropertyState_DIRECT_VALUE);
75cdf0e10cSrcweir 	//
76cdf0e10cSrcweir 			m_xConnection = m_xDriver->connect(OUString::createFromAscii("sdbc:dbase:g:\\"),aValue);
77cdf0e10cSrcweir 			if(m_xConnection.is())
78cdf0e10cSrcweir 			{
79cdf0e10cSrcweir 				Reference<XStatement> xStmt = m_xConnection->createStatement();
80cdf0e10cSrcweir 				if(xStmt.is())
81cdf0e10cSrcweir 				{
82cdf0e10cSrcweir 					Reference<XResultSet> xRes = xStmt->executeQuery(OUString::createFromAscii("SELECT * FROM Tele"));
83cdf0e10cSrcweir 					if(xRes.is())
84cdf0e10cSrcweir 					{
85cdf0e10cSrcweir 						::rtl::OUString aPat = ::rtl::OUString::createFromAscii("%s\t");
86cdf0e10cSrcweir 						Reference<XRow> xRow(xRes,UNO_QUERY);
87cdf0e10cSrcweir 						Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData();
88cdf0e10cSrcweir 						for(sal_Int32 i=1;i<xMeta->getColumnCount();++i)
89cdf0e10cSrcweir 						{
90cdf0e10cSrcweir 							wprintf(aPat.getStr(), xMeta->getColumnName(i).getStr());
91cdf0e10cSrcweir 						}
92cdf0e10cSrcweir 						printf("----------------------------------------------------------------------\n");
93cdf0e10cSrcweir 						while(xRes->next())
94cdf0e10cSrcweir 						{
95cdf0e10cSrcweir 							for(sal_Int32 j=1;j<xMeta->getColumnCount();++j)
96cdf0e10cSrcweir 								wprintf(aPat.getStr(), xRow->getString(j).getStr());
97cdf0e10cSrcweir 							printf("\n");
98cdf0e10cSrcweir 						}
99cdf0e10cSrcweir 					}
100cdf0e10cSrcweir 				}
101cdf0e10cSrcweir 			}
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 		}
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 	catch(...)
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		printf("Exception thrown!\n");
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 	sal_Int32 d;
111cdf0e10cSrcweir 	scanf("%d",&d);
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114