def main(argv): parser = optparse.OptionParser(usage=USAGE) parser.add_option('-e', '--output_encoding', dest='output_encoding', default=DEFAULT_ENCODING, help='Output encoding. Defaults to %s.' % DEFAULT_ENCODING) (options, args) = parser.parse_args(argv[1:]) if len(args) < 1 or len(args) > 2: parser.print_help(sys.stderr) sys.exit(1) instance = args[0] database = None if len(args) == 2: database = args[1] _CreateConfigDir() database = DatabaseConfig(instance, database) db.add_driver(GoogleSqlDriver.NAME, GoogleSqlDriver) sql_cmd_config = config.SQLCmdConfig(None) sql_cmd_config.add('__googlesql__', instance, None, None, database, GoogleSqlDriver.NAME, None, None) sql_cmd = GoogleSqlCmd(sql_cmd_config) sql_cmd.set_output_encoding(options.output_encoding) sql_cmd.set_database(instance) sql_cmd.cmdloop()
def main(argv): parser = optparse.OptionParser(usage=USAGE) parser.add_option( '-u', '--username', dest='username', help='MySQL username to use when connecting to the server.') parser.add_option( '-p', '--password', dest='password', help='MySQL password to use when connecting to the server.') parser.add_option('-e', '--output_encoding', dest='output_encoding', default=DEFAULT_ENCODING, help='Output encoding. Defaults to %s.' % DEFAULT_ENCODING) (options, args) = parser.parse_args(argv[1:]) if len(args) != 1: parser.print_help(sys.stderr) return 1 if not options.username or not options.password: print >> sys.stderr, 'Error: username or password is missing.\n' return 1 if args[0].startswith(DEFAULT_SAE_MYSQL_DB_PREFIX): database_name = args[0] else: database_name = DEFAULT_SAE_MYSQL_DB_PREFIX + args[0] instance_alias = database_name _create_config_dir() db.add_driver(CloudSqlDriver.NAME, CloudSqlDriver) sql_cmd_config = config.SQLCmdConfig(None) sql_cmd_config.add('__cloudsql__', instance_alias, DEFAULT_SAE_MYSQL_HOST, DEFAULT_SAE_MYSQL_PORT, database_name, CloudSqlDriver.NAME, options.username, options.password) sql_cmd = CloudSqlCmd(sql_cmd_config) sql_cmd.set_output_encoding(options.output_encoding) sql_cmd.set_database(instance_alias) sql_cmd.cmdloop() return 0
def main(argv): args = argv[1:] if len(args) < 1 or len(args) > 2: Exit(2, 'Usage: google_sql.py instance [database]') instance = args[0] database = None if len(args) == 2: database = args[1] _CreateConfigDir() database = DatabaseConfig(instance, database) db.add_driver(GoogleSqlDriver.NAME, GoogleSqlDriver) sql_cmd_config = config.SQLCmdConfig(None) sql_cmd_config.add('__googlesql__', instance, None, None, database, GoogleSqlDriver.NAME, None, None) sql_cmd = GoogleSqlCmd(sql_cmd_config) sql_cmd.set_database(instance) sql_cmd.cmdloop()