1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include "clicommanduse.h"
#include "cli.h"
#include "services/config.h"
#include "../cli_config.h"
#include "services/dbmanager.h"
void CliCommandUse::execute()
{
if (!syntax.isArgumentSet(DB_NAME))
{
if (!cli->getCurrentDb())
{
println(tr("No current database selected."));
return;
}
println(tr("Current database: %1").arg(cli->getCurrentDb()->getName()));
return;
}
Db* db = DBLIST->getByName(syntax.getArgument(DB_NAME));
if (!db)
{
println(tr("No such database: %1").arg(syntax.getArgument(DB_NAME)));
return;
}
cli->setCurrentDb(db);
CFG_CLI.Console.DefaultDatabase.set(db->getName());
println(tr("Current database: %1").arg(db->getName()));
}
QString CliCommandUse::shortHelp() const
{
return tr("changes default working database");
}
QString CliCommandUse::fullHelp() const
{
return tr(
"Changes current working database to <name>. If the <name> database is not registered in the application, "
"then the error message is printed and no change is made.\n"
"\n"
"What is current working database?\n"
"When you type a SQL query to be executed, it is executed on the default database, which is also known as "
"the current working database. Most of database-related commands can also work using default database, if no database was "
"provided in their arguments. The current database is always identified by command line prompt. "
"The default database is always defined (unless there is no database on the list at all).\n"
"\n"
"The default database can be selected in various ways:\n"
"- using %1 command,\n"
"- by passing database file name to the application startup parameters,\n"
"- by passing registered database name to the application startup parameters,\n"
"- by restoring previously selected default database from saved configuration,\n"
"- or when default database was not selected by any of the above, then first database from the registered databases list "
"becomes the default one."
).arg(cmdName("use"));
}
void CliCommandUse::defineSyntax()
{
syntax.setName("use");
syntax.addArgument(DB_NAME, tr("name", "CLI command syntax"), false);
}
|