update dev300-m58
[ooovba.git] / connectivity / workben / little / main.cxx
bloba821721f86e6c76bd6dea4ca73101c864e7cb600
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: main.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include <connectivity/sqlparse.hxx>
34 #include "connectivity/sqliterator.hxx"
35 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
36 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
37 #include <com/sun/star/sdbc/XResultSet.hpp>
38 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
39 #include <com/sun/star/sdbc/XRow.hpp>
40 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/beans/PropertyState.hpp>
43 #include <com/sun/star/beans/PropertyValue.hpp>
44 #include <unotools/processfactory.hxx>
45 #include <cppuhelper/servicefactory.hxx>
46 #include <com/sun/star/sdbc/XConnection.hpp>
47 #include <com/sun/star/sdbc/XDriver.hpp>
48 #include "connectivity/sqlnode.hxx"
50 using namespace connectivity;
51 using namespace com::sun::star::sdbc;
52 using namespace com::sun::star;
53 using namespace com::sun::star::uno;
54 using namespace com::sun::star::beans;
55 using namespace rtl;
56 using namespace cppu;
59 #if (defined UNX) || (defined OS2)
60 void main( int argc, char * argv[] )
61 #else
62 void _cdecl main( int argc, char * argv[] )
63 #endif
66 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> m_xConnection;
67 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver> m_xDriver;
69 try{
70 Reference< ::com::sun::star::lang::XMultiServiceFactory > xFac =
71 createRegistryServiceFactory(OUString::createFromAscii("g:\\office50\\program\\applicat.rdb"),OUString());
72 if(!xFac.is())
73 return;
75 m_xDriver = Reference<XDriver>(xFac->createInstance(OUString::createFromAscii("com.sun.star.sdbc.driver.dbase.Driver")),UNO_QUERY);
76 if(m_xDriver.is())
79 Sequence<PropertyValue> aValue;
80 // aValue.getArray()[0] = PropertyValue( OUString::createFromAscii("user"),0,makeAny(OUString::createFromAscii("TEST1")),PropertyState_DIRECT_VALUE);
81 // aValue.getArray()[1] = PropertyValue( OUString::createFromAscii("password"),0,makeAny(OUString::createFromAscii("TEST1")),PropertyState_DIRECT_VALUE);
83 m_xConnection = m_xDriver->connect(OUString::createFromAscii("sdbc:dbase:g:\\"),aValue);
84 if(m_xConnection.is())
86 Reference<XStatement> xStmt = m_xConnection->createStatement();
87 if(xStmt.is())
89 Reference<XResultSet> xRes = xStmt->executeQuery(OUString::createFromAscii("SELECT * FROM Tele"));
90 if(xRes.is())
92 ::rtl::OUString aPat = ::rtl::OUString::createFromAscii("%s\t");
93 Reference<XRow> xRow(xRes,UNO_QUERY);
94 Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData();
95 for(sal_Int32 i=1;i<xMeta->getColumnCount();++i)
97 wprintf(aPat.getStr(), xMeta->getColumnName(i).getStr());
99 printf("----------------------------------------------------------------------\n");
100 while(xRes->next())
102 for(sal_Int32 j=1;j<xMeta->getColumnCount();++j)
103 wprintf(aPat.getStr(), xRow->getString(j).getStr());
104 printf("\n");
112 catch(...)
114 printf("Exception thrown!\n");
117 sal_Int32 d;
118 scanf("%d",&d);