Update ooo320-m1
[ooovba.git] / connectivity / workben / testmoz / main.cxx
blobb96eeb171364a94a514c4b05dc9e161646a4eccb
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.10 $
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 <com/sun/star/sdbc/XDriverAccess.hpp>
49 #include <com/sun/star/sdbcx/XRowLocate.hpp>
50 #include <com/sun/star/sdbc/XRowUpdate.hpp>
51 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
52 #include <com/sun/star/sdbcx/XDeleteRows.hpp>
53 #include <com/sun/star/sdbc/XCloseable.hpp>
54 #include <com/sun/star/sdb/XDatabaseEnvironment.hpp>
55 #include <com/sun/star/uno/Any.hxx>
57 #include "connectivity/sqlnode.hxx"
58 #include <ucbhelper/contentbroker.hxx>
59 #include <comphelper/regpathhelper.hxx>
60 #include <rtl/ustring.hxx>
61 #include <rtl/ustrbuf.hxx>
62 #include <osl/process.h>
64 #include <cppuhelper/bootstrap.hxx>
65 #include <cppuhelper/servicefactory.hxx>
66 #include <com/sun/star/lang/XComponent.hpp>
67 #include <com/sun/star/registry/XImplementationRegistration.hpp>
68 #include <com/sun/star/ucb/XContentProviderManager.hpp>
70 #include <ucbhelper/content.hxx>
71 #include <osl/module.h>
72 #include <tools/config.hxx>
74 #include <stdio.h>
76 using namespace comphelper;
77 using namespace cppu;
78 using namespace rtl;
79 using namespace com::sun::star::uno;
80 using namespace com::sun::star::lang;
81 using namespace com::sun::star::registry;
82 using namespace com::sun::star::ucb;
83 using namespace com::sun::star::beans;
85 //using namespace com::sun::star;
86 using namespace connectivity;
87 using namespace com::sun::star::sdb;
88 using namespace com::sun::star::sdbc;
89 using namespace com::sun::star::sdbcx;
90 using namespace ::com::sun::star::container;
91 using namespace com::sun::star::registry;
93 #define OUtoCStr( x ) (OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US ).getStr())
94 Reference< XContentProviderManager > globalUcb;
95 #define PRINTSTR(x) printf("%s",x);
97 int autoTest(Reference<XResultSet> &xRes);
99 void printColumns( Reference<XResultSet> &xRes )
101 if(xRes.is()) {
102 char* aPat = " %-22s ";
103 char* aPat_Short = " %-12s ";
104 Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData();
105 printf( "ColumnCount = %d\n", xMeta->getColumnCount());
106 for(sal_Int32 i=1;i<=xMeta->getColumnCount();++i)
108 // printf(aPat.getStr(), xMeta->getColumnName(i).getStr());
109 const char *str = OUtoCStr(xMeta->getColumnName(i));
110 // if ( i < 3 ) {
111 // printf( aPat_Short, str );
112 // } else {
113 printf( aPat, str );
114 // }
116 printf("\n");
117 printf("------------------------------------------------------------------------------------------\n");
118 } else {
119 printf(": FAILED to get a ResultSet \n");
122 void printXResultSet( Reference<XResultSet> &xRes )
124 if(xRes.is()) {
125 char* aPat = " %-22s ";
126 char* aPat_Short = " %-12s ";
127 Reference<XRow> xRow(xRes,UNO_QUERY);
128 Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData();
129 for(sal_Int32 j=1;j<=xMeta->getColumnCount();++j)
131 try {
132 const char *str = OUtoCStr(xRow->getString(j));
133 // if ( j < 3 ) {
134 // printf( aPat_Short, str );
135 // } else {
136 printf( aPat_Short, str );
137 // }
138 } catch (...) {
139 printf(" Ex ");
142 printf("\n");
143 } else {
144 printf(": FAILED to get a ResultSet \n");
148 void printXResultSets( Reference<XResultSet> &xRes )
150 if(xRes.is()) {
151 printColumns(xRes);
152 sal_Int32 nRows = 0;
153 while( xRes.is() && xRes->next())
155 printXResultSet(xRes);
156 nRows++;
158 printf( "%d Row(s)\n", nRows);
159 } else {
160 printf(": FAILED to get a ResultSet \n");
164 //#define OUtoCStr( x ) ( ::rtl::OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US).getStr())
165 static const char * const components[] =
167 SAL_MODULENAME( "ucb1" ) // KSO, ABI
168 , SAL_MODULENAME( "ucpfile1" )
169 , SAL_MODULENAME( "cfgmgr2" )
170 , "sax.uno" SAL_DLLEXTENSION
171 , "stocservices.uno" SAL_DLLEXTENSION
172 , SAL_MODULENAME( "fileacc" )
173 , SAL_MODULENAME( "mcnttype" ) //Clipboard Ask Oliver Braun
174 , "i18npool.uno" SAL_DLLEXTENSION
175 // Reading of files in specific encodings like UTF-8 using
176 // createUnoService( "com.sun.star.io.TextInputStream" ) and such
177 , "textinstream.uno" SAL_DLLEXTENSION
178 , "textoutstream.uno" SAL_DLLEXTENSION
179 , "introspection.uno" SAL_DLLEXTENSION
180 , "corereflection.uno" SAL_DLLEXTENSION
181 // RemoteUno
182 , "connector.uno" SAL_DLLEXTENSION
183 , "bridgefac.uno" SAL_DLLEXTENSION
184 , "remotebridge.uno" SAL_DLLEXTENSION
185 , "dbtools2" SAL_DLLEXTENSION
186 , "mozab2" SAL_DLLEXTENSION
187 , "mozabdrv2" SAL_DLLEXTENSION
188 , "sdbc2" SAL_DLLEXTENSION
189 , "dbpool2" SAL_DLLEXTENSION
190 #ifdef SAL_UNX
191 , SVLIBRARY( "dtransX11" ) // OBR
192 #endif
193 #ifdef SAL_W32
194 , SAL_MODULENAME( "sysdtrans" )
195 , SAL_MODULENAME( "ftransl" )
196 , SAL_MODULENAME( "dnd" )
197 #endif
201 Reference< XMultiServiceFactory > InitializeFac( void )
203 OUString path;
204 if( osl_Process_E_None != osl_getExecutableFile( (rtl_uString**)&path ) )
206 printf("Exit.\n");
207 exit( 1 );
209 OSL_ASSERT( path.lastIndexOf( '/' ) >= 0 );
212 ::rtl::OUStringBuffer bufServices( path.copy( 0, path.lastIndexOf( '/' )+1 ) );
213 bufServices.appendAscii("services.rdb");
214 OUString services = bufServices.makeStringAndClear();
216 ::rtl::OUStringBuffer bufTypes( path.copy( 0, path.lastIndexOf( '/' )+1 ) );
217 bufTypes.appendAscii("types.rdb");
218 OUString types = bufTypes.makeStringAndClear();
220 printf("Create Registry.\n");
222 Reference< XMultiServiceFactory > xSMgr;
225 xSMgr = createRegistryServiceFactory( types, services, sal_True );
227 catch( com::sun::star::uno::Exception & )
232 Reference< XMultiServiceFactory > interimSmgr =
233 createRegistryServiceFactory( types, sal_True );
234 Reference< XImplementationRegistration > xIR(
235 interimSmgr->createInstance(
236 OUString::createFromAscii(
237 "com.sun.star.registry.ImplementationRegistration" ) ), UNO_QUERY );
239 Reference< XSimpleRegistry > xReg(
240 interimSmgr->createInstance(
241 OUString::createFromAscii(
242 "com.sun.star.registry.SimpleRegistry" ) ), UNO_QUERY );
243 if ( xReg.is() )
245 xReg->open(services, sal_False, sal_True);
246 if ( xReg->isValid() )
248 OUString loader( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.loader.SharedLibrary" ));
249 for( sal_Int32 i = 0; components[i] ; i ++ )
251 printf("Registering %s ... ", components[i]);
252 xIR->registerImplementation(
253 loader, OUString::createFromAscii(components[i]),xReg);
254 printf("done\n");
256 xReg->close();
257 } else
259 printf("Cannot open Registry. Terminating Program\n");
260 exit (1);
264 Reference< XComponent > xComp( interimSmgr, UNO_QUERY );
265 if( xComp.is() )
266 xComp->dispose();
269 // now try it again readonly
270 printf("Opening Registry readonly\n");
271 xSMgr = createRegistryServiceFactory( types, services, sal_True );
273 catch( com::sun::star::uno::Exception & exc )
275 fprintf( stderr, "Couldn't bootstrap uno servicemanager for reason : %s\n" ,
276 OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
280 printf("set global factory.\n");
282 //////////////////////////////////////////////////////////////////////
283 // set global factory
284 setProcessServiceFactory( xSMgr );
286 /* // Create simple ConfigManager
287 Sequence< Any > aConfArgs(3);
288 aConfArgs[0] <<= PropertyValue( OUString::createFromAscii("servertype"), 0, makeAny( OUString::createFromAscii("local") ), ::com::sun::star::beans::PropertyState_DIRECT_VALUE );
289 aConfArgs[1] <<= PropertyValue( OUString::createFromAscii("sourcepath"), 0, makeAny( OUString::createFromAscii("g:\\") ), ::com::sun::star::beans::PropertyState_DIRECT_VALUE );
290 aConfArgs[2] <<= PropertyValue( OUString::createFromAscii("updatepath"), 0, makeAny( OUString::createFromAscii("g:\\") ), ::com::sun::star::beans::PropertyState_DIRECT_VALUE );
292 Reference< XContentProvider > xConfProvider
293 ( xSMgr->createInstanceWithArguments( OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" ), aConfArgs), UNO_QUERY );
297 // Create unconfigured Ucb:
298 /* Sequence< Any > aArgs(1);
299 aArgs[1] = makeAny ( xConfProvider );*/
300 Sequence< Any > aArgs;
301 ::ucb::ContentBroker::initialize( xSMgr, aArgs );
302 Reference< XContentProviderManager > xUcb =
303 ucb::ContentBroker::get()->getContentProviderManagerInterface();
305 Reference< XContentProvider > xFileProvider
306 ( xSMgr->createInstance( OUString::createFromAscii( "com.sun.star.ucb.FileContentProvider" ) ), UNO_QUERY );
307 xUcb->registerContentProvider( xFileProvider, OUString::createFromAscii( "file" ), sal_True );
310 /* Reference< XContentProvider > xPackageProvider
311 ( xSMgr->createInstance( OUString::createFromAscii( "com.sun.star.ucb.PackageContentProvider" ) ), UNO_QUERY );
312 xUcb->registerContentProvider( xPackageProvider, OUString::createFromAscii( "vnd.sun.star.pkg" ), sal_True );
314 globalUcb = xUcb;
315 return xSMgr;
318 int TestMetaData(Reference< ::com::sun::star::sdbc::XConnection> &pConnection)
320 // Test some metadata
321 Reference< XDatabaseMetaData > xDmd = pConnection->getMetaData();
322 if ( xDmd.is() ) {
323 printf(": got DatabaseMetaData \n");
325 OUString sQuoteStr = xDmd->getIdentifierQuoteString();
326 printf( "Quote String : '%s'\n", OUtoCStr( sQuoteStr ) );
328 OUString sSQLCmds = xDmd->getSQLKeywords();
329 printf( "SQL Commands : '%s'\n", OUtoCStr( sSQLCmds ) );
331 printf("Testing getColumns() : START\n");
333 Reference<XResultSet> xRes = xDmd->getColumns(
334 makeAny(OUString::createFromAscii("")), // Catalog
335 OUString::createFromAscii("%"), // Schema
336 OUString::createFromAscii("%"), // TabName
337 OUString::createFromAscii("%")
339 printXResultSets( xRes );
341 printf("Testing getColumns() : END\n");
343 printf("Testing getTypeInfo() : START\n");
345 Reference<XResultSet> xRes = xDmd-> getTypeInfo();
346 printXResultSets( xRes );
348 printf("Testing getTypeInfo() : END\n");
350 printf("Testing getTables() : START\n");
352 Reference<XResultSet> xRes = xDmd->getTables(
353 makeAny(OUString::createFromAscii("")), // Catalog
354 OUString::createFromAscii("%"), // Schema
355 OUString::createFromAscii("%"), // TabName
356 Sequence<rtl::OUString>()
358 printXResultSets( xRes );
360 printf("Testing getTables() : END\n");
362 } else {
363 printf(": FAILED to get DatabaseMetaData \n");
366 return 0;
368 int TestBookMark(Reference<XResultSet> &xRes);
369 int TestRowUpdate(Reference<XResultSet> &xRes);
371 Reference<XResultSet> TestQuery(Reference< ::com::sun::star::sdbc::XConnection> &pConnection,sal_Int32 choice)
373 // Try a query
374 printf("Testing createStatement() & executeQuery() : START\n");
375 Reference<XStatement> xStmt = pConnection->createStatement();
376 Reference<XResultSet> xRes;
377 if(xStmt.is())
379 printf(": got statement\n");
380 printf(": excuteQuery() : START \n");
381 // SELECT "First Name", "Display Name", "E-mail" FROM "addr" "addr"
382 char sql[256]="SELECT \"First Name\", \"Display Name\", \"E-mail\" FROM \"addr\"";
383 if (choice!=-1)
385 printf("Please input a query,end by \";\" and less then 256 char plz:\n");
386 char ch=0;
387 int index=0;
388 while (ch != ';')
390 scanf("%c",&ch);
391 sql[index++] = ch;
393 sql[index]= 0;
394 printf("SQL:%s\n",sql);
398 sal_Int32 times=0;
399 for (times = 0;times< 100;times ++)
401 Reference<XResultSet> tmpRes =
402 //xStmt->executeQuery(OUString::createFromAscii("SELECT * FROM \"addr\""));
403 xStmt->executeQuery(OUString::createFromAscii(sql));
404 // xStmt->executeQuery(OUString::createFromAscii("SELECT * FROM \"Personal Address Book\" WHERE ( PrimaryEmail IS NULL )"));
405 // xStmt->executeQuery(OUString::createFromAscii("SELECT * FROM \"Personal Address Book\" WHERE ( PrimaryEmail LIKE \"Darren\" )"));
406 // xStmt->executeQuery(OUString::createFromAscii("SELECT * FROM \"Personal Address Book\""));
407 // xStmt->executeQuery(OUString::createFromAscii("SELECT * FROM \"myldap\" WHERE ( PrimaryEmail LIKE \"%Darren%\" OR DisplayName LIKE \"%Darren%\" )"));
409 autoTest( tmpRes );
410 Reference<XCloseable> clsRes(tmpRes,UNO_QUERY);
411 clsRes->close();
412 printf("Current Times:%d\n",times);
414 TestBookMark(xRes);
415 TestRowUpdate(xRes);
416 } catch ( Exception &e ) {
417 printf( "Exception caught : %s\n", OUtoCStr( e.Message) );
418 } catch (...) {
419 printf( "Non-UNO Exception caught\n" );
421 printf(": excuteQuery() : END \n");
423 else
425 printf(": FAILED to get statement\n");
427 printf("Testing createStatement() & executeQuery() : END\n");
428 return xRes;
430 Reference< ::com::sun::star::sdbc::XConnection> TestConnected
431 (Reference< ::com::sun::star::sdbc::XDriver> &pDriver,sal_Int32 choice)
433 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> pConnection;
434 printf("Begin Connect!\n");
435 OUString url;
436 Sequence<PropertyValue> aValue;
438 switch (choice)
440 case -1:
441 case 1: //mozilla
442 url=OUString::createFromAscii("sdbc:address:mozilla://");
443 break;
444 case 2:
445 url=OUString::createFromAscii("sdbc:address:ldap://");
446 char hostname[40],basedn[40];
447 scanf("%s %s",hostname,basedn);
448 aValue.realloc(2);
449 aValue[0].Name = ::rtl::OUString::createFromAscii("HostName");
450 aValue[0].Value <<= rtl::OUString::createFromAscii(hostname);
451 aValue[1].Name = ::rtl::OUString::createFromAscii("BaseDN");
452 aValue[1].Value <<= rtl::OUString::createFromAscii(basedn);
453 break;
454 case 3:
455 case 4:
456 break;
457 case 5:
458 //Default LDAP AB
459 url=OUString::createFromAscii("sdbc:address:ldap://");
460 aValue.realloc(2);
461 aValue[0].Name = ::rtl::OUString::createFromAscii("HostName");
462 aValue[0].Value <<= rtl::OUString::createFromAscii("sun-ds");
463 aValue[1].Name = ::rtl::OUString::createFromAscii("BaseDN");
464 aValue[1].Value <<= rtl::OUString::createFromAscii("dc=sun,dc=com");
465 break;
466 default:
467 return pConnection;
468 break;
470 pConnection =
471 pDriver->connect(url,aValue);
472 return pConnection;
475 void menuBookmark()
477 PRINTSTR("0 Exit\n")
478 PRINTSTR("1 Show Max rowcount\n")
479 PRINTSTR("2 Move First\n")
480 PRINTSTR("3 Record bookmark 1\n")
481 PRINTSTR("4 Record bookmark 2\n")
482 PRINTSTR("5 Move to bookmark. Usage: 5 bookid\n")
483 PRINTSTR("6 moveRelativeToBookmark, follow bookid rows plz\n")
484 PRINTSTR("7 compareBookmark\n")
485 PRINTSTR("8 print boomark hash. Usage: 8 bookid\n")
486 PRINTSTR("9 print current row\n")
487 PRINTSTR("10 Auto test\n")
489 PRINTSTR("Please Input you choice:")
491 int autoTest(Reference<XResultSet> &xRes)
493 sal_Int32 nRows = 0;
494 printColumns(xRes);
495 if(xRes.is()) {
496 while( xRes.is() && xRes->next())
498 nRows++;
500 printf( "%d Row(s)\n", nRows);
501 sal_Int32 times;
502 sal_Int32 pos;
503 for(times = 1;times < 100; times ++)
505 pos= rand() % nRows+1;
506 printf("pos:%d\n",pos);
507 xRes->absolute(pos);
508 printXResultSet(xRes);
510 } else {
511 printf(": FAILED to get a ResultSet \n");
513 return 0;
515 int TestBookMark(Reference<XResultSet> &xRes)
517 Reference<XResultSet> mRes(xRes);
518 if (!mRes.is() || !mRes->first())
520 return sal_False;
523 Reference<XRow> mRow(xRes,UNO_QUERY);
524 Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(mRes,UNO_QUERY)->getMetaData();
525 printXResultSet(mRes);
526 Reference< ::com::sun::star::sdbcx::XRowLocate> xRowLocate(xRes, UNO_QUERY);
527 ::com::sun::star::uno::Any xBookMark[2];
528 int index;
529 if (xRowLocate.is())
531 int choice=-1;
532 while (choice)
534 menuBookmark();
536 scanf("%d",&choice);
537 printf("Your choice is:%d\n",choice);
538 switch (choice)
540 case 1:
541 printf("Rowcount:Current don't know\n");
542 break;
543 case 2:
544 if (!mRes->isFirst()) mRes->first();
545 break;
546 case 3:
547 xBookMark[0] = xRowLocate->getBookmark();
548 break;
549 case 4:
550 xBookMark[1] = xRowLocate->getBookmark();
551 break;
552 case 5:
553 scanf("%d",&index);
554 if (index == 1 || index == 2)
555 xRowLocate->moveToBookmark(xBookMark[index-1]);
556 break;
557 case 6:
558 int rows;
559 scanf("%d %d",&index,&rows);
560 if (index == 1 || index == 2)
561 xRowLocate->moveRelativeToBookmark(xBookMark[index-1],rows);
562 break;
563 case 7:
564 printf("compareBookmarks:%d\n",xRowLocate->compareBookmarks(xBookMark[0],xBookMark[1]));
565 break;
566 case 8:
567 scanf("%d",&index);
568 printf("HashBookmark[%d]:%d\n",index,xRowLocate->hashBookmark(xBookMark[index-1]));
569 break;
570 case 9:
571 printXResultSet(mRes);
572 break;
573 case 10:
574 autoTest(mRes);
575 break;
576 default:
577 break;
581 return 0;
583 void menuRowUpdate()
585 PRINTSTR("0 Exit\n")
586 PRINTSTR("1 Print Columns\n")
587 PRINTSTR("2 Move to row. Usage:2 rowid\n")
588 PRINTSTR("3 Print Row values\n")
589 PRINTSTR("4 Change Column Value: 4 columnid newvalue\n")
590 PRINTSTR("5 Commit changes\n")
591 PRINTSTR("6 Delete Current Row\n")
592 PRINTSTR("Please Input Your choice:")
594 int TestRowUpdate(Reference<XResultSet> &xRes)
596 if (!xRes.is() || !xRes->first())
598 return sal_False;
600 printf("Test XRowUpdate START\n");
601 Reference< ::com::sun::star::sdbc::XRowUpdate> xRowUpdate(xRes, UNO_QUERY);
602 Reference< ::com::sun::star::sdbc::XResultSetUpdate> xResultSetUpdate(xRes, UNO_QUERY);
603 int index;
604 if (xRowUpdate.is())
606 int choice=-1;
607 char newString[256];
608 while (choice)
610 menuRowUpdate();
612 scanf("%d",&choice);
613 printf("Your choice is:%d\n",choice);
614 switch (choice)
616 case 1:
617 printColumns(xRes);
618 break;
619 case 2:
620 scanf("%d",&index);
621 xRes->absolute(index);
622 break;
623 case 3:
624 printXResultSet(xRes);
625 break;
626 case 4:
627 scanf("%d %s",&index,newString);
628 xRowUpdate->updateString(index,OUString::createFromAscii(newString));
629 printXResultSet(xRes);
630 break;
631 case 5:
632 if (xResultSetUpdate.is())
634 xResultSetUpdate->updateRow();
635 printXResultSet(xRes);
637 else
638 printf("Can't update!\n");
639 break;
640 case 6:
641 if (xResultSetUpdate.is())
643 xResultSetUpdate->deleteRow();
644 printXResultSet(xRes);
646 else
647 printf("Can't update!\n");
648 break;
650 default:
651 break;
655 printf("Test XRowUpdate END\n");
656 return 0;
659 void menuMain()
661 PRINTSTR("0 Exit\n")
662 PRINTSTR("1 Open Mozilla Address Book\n")
663 PRINTSTR("2 Open LDAP. Pleae follow hostname and base dn.\n")
664 PRINTSTR("3 Open Outlook Address Book\n")
665 PRINTSTR("4 Open OE Address Book\n")
666 PRINTSTR("Please Input your choice:")
668 #if (defined UNX) || (defined OS2)
669 int main( int argc, char * argv[] )
670 #else
671 int _cdecl main( int argc, char * argv[] )
672 #endif
675 Reference< XMultiServiceFactory > xMgr = InitializeFac();
676 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> m_xConnection;
679 Reference< ::com::sun::star::sdbc::XDriver>
680 m_xDriver(xMgr->createInstance(
681 OUString::createFromAscii("com.sun.star.comp.sdbc.MozabDriver")),
682 UNO_QUERY);
683 if(m_xDriver.is())
685 int choice=-1;
686 if (argc > 1 )
688 menuMain();
689 scanf("%d",&choice);
692 while (choice)
695 m_xConnection = TestConnected(m_xDriver,choice);
696 if(m_xConnection.is())
698 if (!TestMetaData(m_xConnection))
700 Reference<XResultSet> xRes=TestQuery(m_xConnection,choice);
701 if (xRes.is())
705 }else printf("Can't connected!\n");
707 if (argc > 1)
709 menuMain();
710 scanf("%d",&choice);
712 else
713 choice = 0;
716 } else {
717 printf("No driver!\n");
720 catch(...)
722 printf("Exception thrown!\n");
724 printf("Exiting...\n");
725 return 0;