37 #include "vtkSQLQuery.h"
38 #include <QFormLayout>
39 #include <QMessageBox>
41 #include <QInputDialog>
43 #include <QDialogButtonBox>
45 #include <QTextLayout>
58 setSubTitle(
tr(
"Create a user for MySQL Database local Server:") );
83 if (
field(
"User").toString() ==
""
84 ||
field(
"Password").toString() ==
"" )
87 tr(
"Please fill all the fields.") );
100 tr(
"There is a problem with the creation of your database,check the password for your user.") );
116 vtkMySQLDatabase *DataBaseConnector = vtkMySQLDatabase::New();
118 DataBaseConnector->SetHostName( this->
m_ServerName.c_str() );
119 DataBaseConnector->SetUser(
"root");
122 "Root Password for MySQL:", QLineEdit::Password,
128 DataBaseConnector->SetPassword(
"");
132 DataBaseConnector->SetPassword( text.
toStdString().c_str() );
134 if ( !DataBaseConnector->Open() )
138 tr(
"There is a problem with the connection to your root.") );
151 tr(
"Do you want to create this new user with a new database?") ) )
164 tr(
"The user you entered already exists, \ndo you want to create a database for this user?") );
173 vtkMySQLDatabase *DatabaseConnector, std::string iLogin,
174 std::string iServerName, std::string iPassword)
176 vtkSQLQuery * query = DatabaseConnector->GetQueryInstance();
177 std::stringstream queryScript;
179 queryScript <<
"CREATE USER '";
180 queryScript << iLogin;
181 queryScript <<
"'@'";
182 queryScript << iServerName;
183 queryScript <<
"' IDENTIFIED BY '";
184 queryScript << iPassword;
186 query->SetQuery( queryScript.str().c_str() );
190 vtkSQLQuery * queryPrivileges = DatabaseConnector->GetQueryInstance();
191 std::stringstream PrivilegesScript;
192 PrivilegesScript <<
"GRANT ALL PRIVILEGES ON *.* TO '";
193 PrivilegesScript << iLogin;
194 PrivilegesScript <<
"'@'";
195 PrivilegesScript << iServerName;
196 PrivilegesScript <<
"';";
197 queryPrivileges->SetQuery( PrivilegesScript.str().c_str() );
198 if ( !queryPrivileges->Execute() )
200 DatabaseConnector->Close();
201 DatabaseConnector->Delete();
202 queryPrivileges->Delete();
205 tr(
"Sorry, there is a problem with the creation of your user.") );
209 queryPrivileges->Delete();
210 DatabaseConnector->Close();
211 DatabaseConnector->Delete();
222 vtkSQLQuery * queryUserExist = DatabaseConnector->GetQueryInstance();
223 std::stringstream UserExistScript;
225 UserExistScript <<
"SELECT USER FROM mysql.user WHERE user = '";
226 UserExistScript << iLogin;
227 UserExistScript <<
"';";
228 queryUserExist->SetQuery( UserExistScript.str().c_str() );
229 if ( !queryUserExist->Execute() )
233 tr(
"There is a problem to check your existing users.") );
235 queryUserExist->Delete();
236 DatabaseConnector->Close();
237 DatabaseConnector->Delete();
238 queryUserExist->Delete();
241 if ( queryUserExist->NextRow() )
243 queryUserExist->Delete();
244 DatabaseConnector->Close();
245 DatabaseConnector->Delete();
249 queryUserExist->Delete();
259 | QDialogButtonBox::Cancel);
270 int Result = Dialog->
exec();
std::string toStdString() const
void registerField(const QString &name, QWidget *widget, const char *property, const char *changedSignal)
void setSubTitle(const QString &subTitle)
void setEchoMode(EchoMode)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool CreateGofigureUserWithDatabaseConnector(vtkMySQLDatabase *DatabaseConnector, std::string iLogin, std::string iServerName, std::string iPassword)
void setBold(bool enable)
QGoDBInitCreateUserPage(QWidget *iparent=0)
void UserAndDatabaseCreated()
void setText(const QString &text)
QVariant field(const QString &name) const
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, QFlags< Qt::WindowType > flags, QFlags< Qt::InputMethodHint > inputMethodHints)
bool QuestionToUser(QString iQuestion)
create a dialog with OK and Cancel button asking iquestion to the user, return true if the user press...
bool UserNameAlreadyExits(vtkMySQLDatabase *DatabaseConnector, std::string iLogin)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool CreateGoFigureDataBase(std::string ServerName, std::string login, std::string Password, std::string DBName)