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