commands/sql/sqlcmd_open.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // sqlcmd_open.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include "sqlcmd_open.h"
       
    14 #include "sqlsrv.h"
       
    15 
       
    16 /////////////////////////////////////////////////////////////////////////////////////////
       
    17 _LIT(KCommandName, "open");
       
    18 
       
    19 CServerCommandBase* CSqlCmdOpen::NewLC()
       
    20 	{
       
    21 	CSqlCmdOpen* self = new(ELeave) CSqlCmdOpen();
       
    22 	CleanupStack::PushL(self);
       
    23 	self->ConstructL();
       
    24 	return self;
       
    25 	}
       
    26 
       
    27 CSqlCmdOpen::~CSqlCmdOpen()
       
    28 	{
       
    29 	delete iFileName;	
       
    30 	}
       
    31 
       
    32 const TDesC& CSqlCmdOpen::NameS()
       
    33 	{
       
    34 	return KCommandName;
       
    35 	}
       
    36 
       
    37 void CSqlCmdOpen::ConstructL()
       
    38 	{
       
    39 	BaseConstructL();
       
    40 	}
       
    41 
       
    42 const TDesC& CSqlCmdOpen::Name() const
       
    43 	{
       
    44 	return KCommandName;
       
    45 	}
       
    46 
       
    47 const TDesC& CSqlCmdOpen::Description() const
       
    48 	{
       
    49 	_LIT(KDescription, "open an existing SQL database file");
       
    50 	return KDescription;
       
    51 	}
       
    52 
       
    53 //virtual 
       
    54 void CSqlCmdOpen::ArgumentsL(RCommandArgumentList& aArguments)
       
    55 {
       
    56 	_LIT(KName, "filename");
       
    57 	_LIT(KDescription, "filename of the SQL database file. Should contain path.");
       
    58 	aArguments.AppendStringL(iFileName, KName, KDescription, KValueTypeFlagOptional);
       
    59 }
       
    60 
       
    61 void CSqlCmdOpen::DoRunL()
       
    62 	{
       
    63 	if (iFileName==NULL || iFileName->Length()==0 )
       
    64 		{
       
    65 		LeaveIfErr(KErrArgument, _L("Database filename unspecified."));
       
    66 		}
       
    67 	
       
    68 	CCmdSqlSrv* pSrv = CCmdSqlSrv::GetServer(); 
       
    69 	pSrv->SqlOpenL(*iFileName, this);
       
    70 	}
       
    71 
       
    72 /////////////////////////////////////////////////////////////////////////////////////
       
    73 _LIT(KCommandExit, "exit");
       
    74 
       
    75 CServerCommandBase* CSqlCmdExit::NewLC()
       
    76 	{
       
    77 	CSqlCmdExit* self = new(ELeave) CSqlCmdExit();
       
    78 	CleanupStack::PushL(self);
       
    79 	self->ConstructL();
       
    80 	return self;
       
    81 	}
       
    82 
       
    83 CSqlCmdExit::~CSqlCmdExit()
       
    84 	{
       
    85 	}
       
    86 
       
    87 const TDesC& CSqlCmdExit::NameS()
       
    88 	{
       
    89 	return KCommandExit;
       
    90 	}
       
    91 
       
    92 void CSqlCmdExit::ConstructL()
       
    93 	{
       
    94 	BaseConstructL();
       
    95 	}
       
    96 
       
    97 const TDesC& CSqlCmdExit::Name() const
       
    98 	{
       
    99 	return KCommandExit;
       
   100 	}
       
   101 
       
   102 const TDesC& CSqlCmdExit::Description() const
       
   103 	{
       
   104 	_LIT(KDescription, "Shut down amsrv.");
       
   105 	return KDescription;
       
   106 	}
       
   107 
       
   108 void CSqlCmdExit::DoRunL()
       
   109 	{
       
   110 	CCmdSqlSrv* pSrv = CCmdSqlSrv::GetServer(); 
       
   111 	pSrv->Exit(KErrNone);
       
   112 
       
   113 	}
       
   114 
       
   115 /////////////////////////////////////////////////////////////////////////////////////
       
   116 _LIT(KCommandClose, "close");
       
   117 
       
   118 CServerCommandBase* CSqlCmdClose::NewLC()
       
   119 	{
       
   120 	CSqlCmdClose* self = new(ELeave) CSqlCmdClose();
       
   121 	CleanupStack::PushL(self);
       
   122 	self->ConstructL();
       
   123 	return self;
       
   124 	}
       
   125 
       
   126 CSqlCmdClose::~CSqlCmdClose()
       
   127 	{
       
   128 	}
       
   129 
       
   130 const TDesC& CSqlCmdClose::NameS()
       
   131 	{
       
   132 	return KCommandClose;
       
   133 	}
       
   134 
       
   135 void CSqlCmdClose::ConstructL()
       
   136 	{
       
   137 	BaseConstructL();
       
   138 	}
       
   139 
       
   140 const TDesC& CSqlCmdClose::Name() const
       
   141 	{
       
   142 	return KCommandClose;
       
   143 	}
       
   144 
       
   145 const TDesC& CSqlCmdClose::Description() const
       
   146 	{
       
   147 	_LIT(KDescription, "close a SQL database file");
       
   148 	return KDescription;
       
   149 	}
       
   150 
       
   151 void CSqlCmdClose::DoRunL()
       
   152 	{
       
   153 	CCmdSqlSrv* pSrv = CCmdSqlSrv::GetServer(); 
       
   154 	pSrv->SqlClose(this);
       
   155 
       
   156 	}
       
   157 
       
   158 /////////////////////////////////////////////////////////////////////////////////////
       
   159 _LIT(KCommandCreate, "create");
       
   160 
       
   161 CServerCommandBase* CSqlCmdCreate::NewLC()
       
   162 	{
       
   163 	CSqlCmdCreate* self = new(ELeave) CSqlCmdCreate();
       
   164 	CleanupStack::PushL(self);
       
   165 	self->ConstructL();
       
   166 	return self;
       
   167 	}
       
   168 
       
   169 CSqlCmdCreate::~CSqlCmdCreate()
       
   170 	{
       
   171 	delete iFileName;
       
   172 	}
       
   173 
       
   174 const TDesC& CSqlCmdCreate::NameS()
       
   175 	{
       
   176 	return KCommandCreate;
       
   177 	}
       
   178 
       
   179 void CSqlCmdCreate::ConstructL()
       
   180 	{
       
   181 	BaseConstructL();
       
   182 	}
       
   183 
       
   184 const TDesC& CSqlCmdCreate::Name() const
       
   185 	{
       
   186 	return KCommandCreate;
       
   187 	}
       
   188 
       
   189 const TDesC& CSqlCmdCreate::Description() const
       
   190 	{
       
   191 	_LIT(KDescription, "Create a SQL database");
       
   192 	return KDescription;
       
   193 	}
       
   194 
       
   195 //virtual 
       
   196 void CSqlCmdCreate::ArgumentsL(RCommandArgumentList& aArguments)
       
   197 	{
       
   198 	_LIT(KName, "filename");
       
   199 	_LIT(KDescription, "filename of the SQL database file. Should contain path.");
       
   200 	aArguments.AppendStringL(iFileName, KName, KDescription, KValueTypeFlagOptional);
       
   201 	}
       
   202 
       
   203 void CSqlCmdCreate::DoRunL()
       
   204 	{
       
   205 	if (iFileName==NULL || iFileName->Length()==0 )
       
   206 		{
       
   207 		LeaveIfErr(KErrArgument, _L("Database filename unspecified."));
       
   208 		}
       
   209 	
       
   210 	CCmdSqlSrv* pSrv = CCmdSqlSrv::GetServer(); 
       
   211 	pSrv->SqlCreateL(*iFileName, this);
       
   212 	}
       
   213 
       
   214 ///////////////////////////////////////////////////////////////////////////////
       
   215 
       
   216 _LIT(KCommandExec, "exec");
       
   217 
       
   218 CServerCommandBase* CSqlCmdExec::NewLC()
       
   219 	{
       
   220 	CSqlCmdExec* self = new(ELeave) CSqlCmdExec();
       
   221 	CleanupStack::PushL(self);
       
   222 	self->ConstructL();
       
   223 	return self;
       
   224 	}
       
   225 
       
   226 CSqlCmdExec::~CSqlCmdExec()
       
   227 	{
       
   228 	delete iExec;
       
   229 	}
       
   230 
       
   231 const TDesC& CSqlCmdExec::NameS()
       
   232 	{
       
   233 	return KCommandExec;
       
   234 	}
       
   235 
       
   236 void CSqlCmdExec::ConstructL()
       
   237 	{
       
   238 	BaseConstructL();
       
   239 	}
       
   240 
       
   241 const TDesC& CSqlCmdExec::Name() const
       
   242 	{
       
   243 	return KCommandExec;
       
   244 	}
       
   245 
       
   246 const TDesC& CSqlCmdExec::Description() const
       
   247 	{
       
   248 	_LIT(KDescription, "Execute a SQL statement without parameter and response.");
       
   249 	return KDescription;
       
   250 	}
       
   251 
       
   252 void CSqlCmdExec::ArgumentsL(RCommandArgumentList& aArguments)
       
   253 	{
       
   254 	_LIT(KName, "statement");
       
   255 	_LIT(KDescription, "The SQL statement to execute");
       
   256 	aArguments.AppendStringL(iExec, KName, KDescription, KValueTypeFlagOptional|KValueTypeFlagLast);
       
   257 	}
       
   258 
       
   259 void CSqlCmdExec::DoRunL()
       
   260 	{
       
   261 	if (iExec==NULL || iExec->Length()==0 )
       
   262 		{
       
   263 		LeaveIfErr(KErrArgument, _L("SQL statement unspecified."));
       
   264 		}
       
   265 	CCmdSqlSrv::StripWrapDoubleQuote(*iExec);
       
   266 	
       
   267 	CCmdSqlSrv* pSrv = CCmdSqlSrv::GetServer(); 
       
   268 	pSrv->SqlExecL(*iExec, this);
       
   269 	}
       
   270 /////////////////////////////////////////////////////////////////////////////////////////////
       
   271 
       
   272 _LIT(KCommandState, "state");
       
   273 
       
   274 CServerCommandBase* CSqlCmdState::NewLC()
       
   275 	{
       
   276 	CSqlCmdState* self = new(ELeave) CSqlCmdState();
       
   277 	CleanupStack::PushL(self);
       
   278 	self->ConstructL();
       
   279 	return self;
       
   280 	}
       
   281 
       
   282 CSqlCmdState::~CSqlCmdState()
       
   283 	{
       
   284 	delete iExec;
       
   285 	
       
   286 	delete iOptFileName;
       
   287 	
       
   288 	//delete optional multiple parameter file
       
   289 		{
       
   290 		TInt optParamCnt = iOptParamFile.Count();
       
   291 		if (optParamCnt)
       
   292 			{
       
   293 			for (TInt i=0; i<optParamCnt; i++)
       
   294 				{
       
   295 				HBufC* pEle = iOptParamFile[i];
       
   296 				delete pEle;			
       
   297 				}		
       
   298 			}
       
   299 		iOptParamFile.Close();
       
   300 		}
       
   301 		
       
   302 /*	
       
   303 	//release resource for command-specific arguments 
       
   304 	TInt cmdArguCnt = iCmdArgu.Count();
       
   305 	if (cmdArguCnt)
       
   306 		{
       
   307 		for (TInt i=0; i<cmdArguCnt; i++)
       
   308 			{
       
   309 			HBufC* pEle = iCmdArgu[i];
       
   310 			delete pEle;			
       
   311 			}		
       
   312 		}
       
   313 	iCmdArgu.Close();
       
   314 */			
       
   315 	}
       
   316 
       
   317 const TDesC& CSqlCmdState::NameS()
       
   318 	{
       
   319 	return KCommandState;
       
   320 	}
       
   321 
       
   322 void CSqlCmdState::ConstructL()
       
   323 	{
       
   324 	BaseConstructL();
       
   325 	}
       
   326 
       
   327 const TDesC& CSqlCmdState::Name() const
       
   328 	{
       
   329 	return KCommandState;
       
   330 	}
       
   331 
       
   332 const TDesC& CSqlCmdState::Description() const
       
   333 	{
       
   334 	_LIT(KDescription, "Execute a SQL statement that may come with parameter and response.");
       
   335 	return KDescription;
       
   336 	}
       
   337 
       
   338 void CSqlCmdState::ArgumentsL(RCommandArgumentList& aArguments)
       
   339 	{
       
   340 	_LIT(KName, "statement");
       
   341 	_LIT(KDescription, "The SQL statement to execute");
       
   342 	aArguments.AppendStringL(iExec, KName, KDescription, KValueTypeFlagOptional|KValueTypeFlagLast);	
       
   343 	}
       
   344 
       
   345 void CSqlCmdState::OptionsL(RCommandOptionList& aOptions)
       
   346 	{
       
   347 	_LIT(KOptFile, "temp");
       
   348 	_LIT(KOptFileDescription, "Specify TEMP file template(used to dump large binary content to file)");
       
   349 	aOptions.AppendStringL(iOptFileName, TChar('t'), KOptFile, KOptFileDescription);
       
   350 	
       
   351 	_LIT(KOptParam, "param");
       
   352 	_LIT(KOptParamDescription, "Specify file names, of which the content will be used to fill parameters in SQL statement");
       
   353 	aOptions.AppendStringL(iOptParamFile, TChar('p'), KOptParam, KOptParamDescription);
       
   354 	}
       
   355 
       
   356 
       
   357 void CSqlCmdState::DoRunL()
       
   358 	{
       
   359 	//this command requires at least one argument
       
   360 	//first argument is a SQL statement, 
       
   361 	//and remaining arguments are optional parameters
       
   362 	
       
   363 	TInt paramCnt = iOptParamFile.Count();
       
   364 	if (iExec==0 || iExec->Length()==0 )
       
   365 		{
       
   366 		LeaveIfErr(KErrArgument, _L("SQL statement unspecified."));
       
   367 		}
       
   368 	
       
   369 	CCmdSqlSrv::StripWrapDoubleQuote(*iExec);
       
   370 	
       
   371 	CCmdSqlSrv* pSrv = CCmdSqlSrv::GetServer(); 
       
   372 	pSrv->SqlStateL(*iExec, iOptParamFile, this, iOptFileName);
       
   373 	}
       
   374 
       
   375 ///////////////////////////////////////////////////////////////////////////////
       
   376 /////////////////////////////////////////////////////////////////////////////////////
       
   377 _LIT(KCommandAttach, "attach");
       
   378 
       
   379 CServerCommandBase* CSqlCmdAttach::NewLC()
       
   380 	{
       
   381 	CSqlCmdAttach* self = new(ELeave) CSqlCmdAttach();
       
   382 	CleanupStack::PushL(self);
       
   383 	self->ConstructL();
       
   384 	return self;
       
   385 	}
       
   386 
       
   387 CSqlCmdAttach::~CSqlCmdAttach()
       
   388 	{
       
   389 	delete iOptFileName;
       
   390 	delete iOptDBName;
       
   391 	}
       
   392 
       
   393 const TDesC& CSqlCmdAttach::NameS()
       
   394 	{
       
   395 	return KCommandAttach;
       
   396 	}
       
   397 
       
   398 void CSqlCmdAttach::ConstructL()
       
   399 	{
       
   400 	BaseConstructL();
       
   401 	}
       
   402 
       
   403 const TDesC& CSqlCmdAttach::Name() const
       
   404 	{
       
   405 	return KCommandAttach;
       
   406 	}
       
   407 
       
   408 const TDesC& CSqlCmdAttach::Description() const
       
   409 	{
       
   410 	_LIT(KDescription, "Attach additional database onto main database file");
       
   411 	return KDescription;
       
   412 	}
       
   413 
       
   414 //virtual 
       
   415 void CSqlCmdAttach::ArgumentsL(RCommandArgumentList& /*aArguments*/)
       
   416 	{
       
   417 	}
       
   418 
       
   419 void CSqlCmdAttach::OptionsL(RCommandOptionList& aOptions)
       
   420 	{
       
   421 	_LIT(KOptFile, "file");
       
   422 	_LIT(KOptFileDescription, "Specify additional database file.");
       
   423 	aOptions.AppendStringL(iOptFileName, TChar('f'), KOptFile, KOptFileDescription);
       
   424 
       
   425 	_LIT(KOptDB, "name");
       
   426 	_LIT(KOptDBDescription, "Specify additional database name.");
       
   427 	aOptions.AppendStringL(iOptDBName, TChar('n'), KOptDB, KOptDBDescription);
       
   428 	}
       
   429 
       
   430 void CSqlCmdAttach::DoRunL()
       
   431 	{
       
   432 	if (iOptFileName==NULL || iOptFileName->Length()==0 )
       
   433 		{
       
   434 		LeaveIfErr(KErrArgument, _L("Database filename unspecified."));
       
   435 		}
       
   436 	if (iOptDBName==NULL || iOptDBName->Length()==0 )
       
   437 		{
       
   438 		LeaveIfErr(KErrArgument, _L("Database name unspecified."));
       
   439 		}
       
   440 	
       
   441 	CCmdSqlSrv* pSrv = CCmdSqlSrv::GetServer(); 
       
   442 	pSrv->SqlAttachL(*iOptFileName, *iOptDBName, this);
       
   443 	}
       
   444 
       
   445 //////////////////////////////////////////////////////////////////////////////////////
       
   446 
       
   447 _LIT(KCommandDetach, "detach");
       
   448 
       
   449 CServerCommandBase* CSqlCmdDetach::NewLC()
       
   450 	{
       
   451 	CSqlCmdDetach* self = new(ELeave) CSqlCmdDetach();
       
   452 	CleanupStack::PushL(self);
       
   453 	self->ConstructL();
       
   454 	return self;
       
   455 	}
       
   456 
       
   457 CSqlCmdDetach::~CSqlCmdDetach()
       
   458 	{
       
   459 	delete iOptDBName;
       
   460 	}
       
   461 
       
   462 const TDesC& CSqlCmdDetach::NameS()
       
   463 	{
       
   464 	return KCommandDetach;
       
   465 	}
       
   466 
       
   467 void CSqlCmdDetach::ConstructL()
       
   468 	{
       
   469 	BaseConstructL();
       
   470 	}
       
   471 
       
   472 const TDesC& CSqlCmdDetach::Name() const
       
   473 	{
       
   474 	return KCommandDetach;
       
   475 	}
       
   476 
       
   477 const TDesC& CSqlCmdDetach::Description() const
       
   478 	{
       
   479 	_LIT(KDescription, "Detach additional database which is previously attached onto main database file.");
       
   480 	return KDescription;
       
   481 	}
       
   482 
       
   483 void CSqlCmdDetach::ArgumentsL(RCommandArgumentList& /*aArguments*/)
       
   484 	{
       
   485 	}
       
   486 
       
   487 void CSqlCmdDetach::OptionsL(RCommandOptionList& aOptions)
       
   488 	{
       
   489 	_LIT(KOptDB, "name");
       
   490 	_LIT(KOptDBDescription, "Specify additional database name.");
       
   491 	aOptions.AppendStringL(iOptDBName, TChar('n'), KOptDB, KOptDBDescription);
       
   492 	}
       
   493 
       
   494 void CSqlCmdDetach::DoRunL()
       
   495 	{
       
   496 	if (iOptDBName==NULL || iOptDBName->Length()==0 )
       
   497 		{
       
   498 		LeaveIfErr(KErrArgument, _L("Database name unspecified."));
       
   499 		}
       
   500 	
       
   501 	CCmdSqlSrv* pSrv = CCmdSqlSrv::GetServer(); 
       
   502 	pSrv->SqlDetachL(*iOptDBName, this);
       
   503 	}
       
   504 
       
   505 ///////////////////////////////////////////////////////////////////////////////
       
   506 /////////////////////////////////////////////////////////////////////////////////////
       
   507 #ifdef SQL_COMPACT
       
   508 
       
   509 _LIT(KCommandCompact, "compact");
       
   510 
       
   511 CServerCommandBase* CSqlCmdCompact::NewLC()
       
   512 	{
       
   513 	CSqlCmdCompact* self = new(ELeave) CSqlCmdCompact();
       
   514 	CleanupStack::PushL(self);
       
   515 	self->ConstructL();
       
   516 	return self;
       
   517 	}
       
   518 
       
   519 CSqlCmdCompact::~CSqlCmdCompact()
       
   520 	{
       
   521 	delete iOptDBName;
       
   522 	}
       
   523 
       
   524 const TDesC& CSqlCmdCompact::NameS()
       
   525 	{
       
   526 	return KCommandCompact;
       
   527 	}
       
   528 
       
   529 void CSqlCmdCompact::ConstructL()
       
   530 	{
       
   531 	BaseConstructL();
       
   532 	}
       
   533 
       
   534 const TDesC& CSqlCmdCompact::Name() const
       
   535 	{
       
   536 	return KCommandCompact;
       
   537 	}
       
   538 
       
   539 const TDesC& CSqlCmdCompact::Description() const
       
   540 	{
       
   541 	_LIT(KDescription, "Compacts the database.(RSqlDatabase::Compact)");
       
   542 	return KDescription;
       
   543 	}
       
   544 
       
   545 //virtual 
       
   546 void CSqlCmdCompact::ArgumentsL(RCommandArgumentList& aArguments)
       
   547 {
       
   548 }
       
   549 
       
   550 void CSqlCmdCompact::OptionsL(RCommandOptionList& aOptions)
       
   551 	{
       
   552 	_LIT(KOptDB, "name");
       
   553 	_LIT(KOptDBDescription, "Specify database name, if unspecified, then main database will be compacted");
       
   554 	aOptions.AppendStringL(iOptDBName, TChar('n'), KOptDB, KOptDBDescription);
       
   555 	}
       
   556 
       
   557 void CSqlCmdCompact::DoRunL()
       
   558 	{
       
   559 	CCmdSqlSrv* pSrv = CCmdSqlSrv::GetServer(); 
       
   560 	pSrv->SqlCompactL(iOptDBName, this);
       
   561 	}
       
   562 #endif