Updated core
[LibreOffice.git] / connectivity / workben / little / main.cxx
blobd8d00fc6d1d191b80552cb8675ff06f24d2df95d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <connectivity/sqlparse.hxx>
21 #include "connectivity/sqliterator.hxx"
22 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
23 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
24 #include <com/sun/star/sdbc/XResultSet.hpp>
25 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
26 #include <com/sun/star/sdbc/XRow.hpp>
27 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/beans/PropertyState.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <cppuhelper/servicefactory.hxx>
32 #include <com/sun/star/sdbc/XConnection.hpp>
33 #include <com/sun/star/sdbc/XDriver.hpp>
34 #include "connectivity/sqlnode.hxx"
36 using namespace connectivity;
37 using namespace com::sun::star::sdbc;
38 using namespace com::sun::star;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::beans;
41 using namespace cppu;
45 #if (defined UNX)
46 void main( int argc, char * argv[] )
47 #else
48 void _cdecl main( int argc, char * argv[] )
49 #endif
52 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> m_xConnection;
53 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver> m_xDriver;
55 try{
56 Reference< ::com::sun::star::lang::XMultiServiceFactory > xFac =
57 createRegistryServiceFactory(OUString("g:\\office50\\program\\applicat.rdb"),OUString());
58 if(!xFac.is())
59 return;
61 m_xDriver = Reference<XDriver>(xFac->createInstance(OUString("com.sun.star.sdbc.driver.dbase.Driver")),UNO_QUERY);
62 if(m_xDriver.is())
65 Sequence<PropertyValue> aValue;
66 // aValue.getArray()[0] = PropertyValue( OUString("user"),0,makeAny(OUString("TEST1")),PropertyState_DIRECT_VALUE);
67 // aValue.getArray()[1] = PropertyValue( OUString("password"),0,makeAny(OUString("TEST1")),PropertyState_DIRECT_VALUE);
69 m_xConnection = m_xDriver->connect(OUString("sdbc:dbase:g:\\"),aValue);
70 if(m_xConnection.is())
72 Reference<XStatement> xStmt = m_xConnection->createStatement();
73 if(xStmt.is())
75 Reference<XResultSet> xRes = xStmt->executeQuery(OUString("SELECT * FROM Tele"));
76 if(xRes.is())
78 OUString aPat( "%s\t" );
79 Reference<XRow> xRow(xRes,UNO_QUERY);
80 Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData();
81 for(sal_Int32 i=1;i<xMeta->getColumnCount();++i)
83 wprintf(aPat.getStr(), xMeta->getColumnName(i).getStr());
85 printf("----------------------------------------------------------------------\n");
86 while(xRes->next())
88 for(sal_Int32 j=1;j<xMeta->getColumnCount();++j)
89 wprintf(aPat.getStr(), xRow->getString(j).getStr());
90 printf("\n");
98 catch(...)
100 printf("Exception thrown!\n");
103 sal_Int32 d;
104 scanf("%d",&d);
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */