new_database._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2005 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  */
18 class new_database {
19 public:
20 
21 
22 
23 int main(int argc, array argv)
24 {
25  Sql.Sql handle;
26  mapping conf = ([ "rootpw": "", "password": "steam", "user":"steam",
27  "db":"steam",]);
28  for ( int i = 1; i < argc; i++ ) {
29  string val;
30 
31  if ( sscanf(argv[i], "--newroot=%s", val) == 1 ) {
32  Process.system("mysqladmin -u root password " + val);
33  }
34  else if ( sscanf(argv[i], "--password=%s", val) == 1 )
35  conf["password"] = val;
36  else if ( sscanf(argv[i], "--user=%s", val) == 1 )
37  conf["user"] = val;
38  else if ( sscanf(argv[i], "--rootpw=%s", val) == 1 )
39  conf["rootpw"] = val;
40  else if ( sscanf(argv[i], "--db=%s", val) == 1 )
41  conf["db"] = val;
42 
43  }
44  handle = Sql.Sql("mysql://root:"+conf->rootpw+"@localhost/mysql");
45  handle->big_query("create database " + conf->db);
46  handle->big_query("use mysql");
47  handle->big_query("grant all privileges on " + conf->db + ".* to "+
48  conf->user + " @localhost identified by '" + conf->password+
49  "' with grant option;");
50  return 0;
51 }
52 
53 
54 };