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 <connectivity/sqlparse.hxx>
31 #include "connectivity/sqliterator.hxx"
32 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
33 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
34 #include <com/sun/star/sdbc/XResultSet.hpp>
35 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
36 #include <com/sun/star/sdbc/XRow.hpp>
37 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/beans/PropertyState.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <unotools/processfactory.hxx>
42 #include <cppuhelper/servicefactory.hxx>
43 #include <com/sun/star/sdbc/XConnection.hpp>
44 #include <com/sun/star/sdbc/XDriver.hpp>
45 #include "connectivity/sqlnode.hxx"
46 
47 using namespace connectivity;
48 using namespace com::sun::star::sdbc;
49 using namespace com::sun::star;
50 using namespace com::sun::star::uno;
51 using namespace com::sun::star::beans;
52 using namespace rtl;
53 using namespace cppu;
54 
55 
56 #if (defined UNX) || (defined OS2)
57 void main( int argc, char * argv[] )
58 #else
59 void _cdecl main( int argc, char * argv[] )
60 #endif
61 
62 {
63 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>	m_xConnection;
64 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver>		m_xDriver;
65 
66 	try{
67 		Reference< ::com::sun::star::lang::XMultiServiceFactory > xFac =
68 				createRegistryServiceFactory(OUString::createFromAscii("g:\\office50\\program\\applicat.rdb"),OUString());
69 		if(!xFac.is())
70 			return;
71 
72 		m_xDriver = Reference<XDriver>(xFac->createInstance(OUString::createFromAscii("com.sun.star.sdbc.driver.dbase.Driver")),UNO_QUERY);
73 		if(m_xDriver.is())
74 		{
75 
76 			Sequence<PropertyValue> aValue;
77 	//		aValue.getArray()[0] = PropertyValue( OUString::createFromAscii("user"),0,makeAny(OUString::createFromAscii("TEST1")),PropertyState_DIRECT_VALUE);
78 	//		aValue.getArray()[1] = PropertyValue( OUString::createFromAscii("password"),0,makeAny(OUString::createFromAscii("TEST1")),PropertyState_DIRECT_VALUE);
79 	//
80 			m_xConnection = m_xDriver->connect(OUString::createFromAscii("sdbc:dbase:g:\\"),aValue);
81 			if(m_xConnection.is())
82 			{
83 				Reference<XStatement> xStmt = m_xConnection->createStatement();
84 				if(xStmt.is())
85 				{
86 					Reference<XResultSet> xRes = xStmt->executeQuery(OUString::createFromAscii("SELECT * FROM Tele"));
87 					if(xRes.is())
88 					{
89 						::rtl::OUString aPat = ::rtl::OUString::createFromAscii("%s\t");
90 						Reference<XRow> xRow(xRes,UNO_QUERY);
91 						Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData();
92 						for(sal_Int32 i=1;i<xMeta->getColumnCount();++i)
93 						{
94 							wprintf(aPat.getStr(), xMeta->getColumnName(i).getStr());
95 						}
96 						printf("----------------------------------------------------------------------\n");
97 						while(xRes->next())
98 						{
99 							for(sal_Int32 j=1;j<xMeta->getColumnCount();++j)
100 								wprintf(aPat.getStr(), xRow->getString(j).getStr());
101 							printf("\n");
102 						}
103 					}
104 				}
105 			}
106 
107 		}
108 	}
109 	catch(...)
110 	{
111 		printf("Exception thrown!\n");
112 
113 	}
114 	sal_Int32 d;
115 	scanf("%d",&d);
116 }
117 
118