Adds a grant to the MySQL server.

    For database, make sure you specify database.table or database.*

    CLI Example:

    .. code-block:: bash

        salt '*' mysql.grant_add \
            'SELECT,INSERT,UPDATE,...' 'database.*' 'frank' 'localhost'
546134
def grant_add(grant,
              database,
              user,
              host='localhost',
              grant_option=False,
              escape=True,
              ssl_option=False,
              **connection_args):
    '''
    
    '''
    dbc = _connect(**connection_args)
    if dbc is None:
        return False
    cur = dbc.cursor()

    # Avoid spaces problems
    grant = grant.strip()
    try:
        qry = __grant_generate(grant, database, user, host, grant_option, escape, ssl_option)
    except Exception:
        log.error('Error during grant generation')
        return False
    try:
        _execute(cur, qry['qry'], qry['args'])
    except (MySQLdb.OperationalError, MySQLdb.ProgrammingError) as exc:
        err = 'MySQL Error {0}: {1}'.format(*exc.args)
        __context__['mysql.error'] = err
        log.error(err)
        return False
    if grant_exists(
            grant, database, user, host, grant_option, escape,
            **connection_args):
        log.info(
            'Grant \'%s\' on \'%s\' for user \'%s\' has been added',
            grant, database, user
        )
        return True

    log.info(
        'Grant \'%s\' on \'%s\' for user \'%s\' has NOT been added',
        grant, database, user
    )
    return False
1179717
def grant_admin_privileges(name, **client_args):
    '''
    
    '''
    client = _client(**client_args)
    client.grant_admin_privileges(name)

    return True
124887
function insertIntoDB() {
                    lastQry = connection.query('INSERT INTO ?? SET ?', [req.params.table , insertJson] , function (err, rows) {
                        if (err) {
                            console.error(err);
                            res.statusCode = 500;
                            res.send({
                                result: 'error',
                                err: err.code
                            });
                        } else {
                            sendSuccessAnswer(req.params.table , res, rows.insertId);
                        }

                    });
                }
508706
public function install()
    {
        $build = $this('mysql',
            $this->databases['default']['host'],
            '',
            $this->databases['default']['user'],
            $this->databases['default']['pass']);

        $main = $this('mysql',
            $this->databases['default']['host'],
            $this->databases['default']['name'],
            $this->databases['default']['user'],
            $this->databases['default']['pass']);

        $build->query('DROP DATABASE IF EXISTS `'.$this->databases['default']['name'].'`');
        $build->query('CREATE DATABASE `'.$this->databases['default']['name'].'`');

        //get schema
        $schema = $this('file', $this->cwd.'/schema.sql')->getContent();

        //add queries
        $queries = explode(';', $schema);

        $queries[] = "INSERT INTO `app` (
            `app_id`,
            `app_name`,
            `app_domain`,
            `app_token`,
            `app_secret`,
            `app_permissions`,
            `app_website`,
            `app_active`,
            `app_type`,
            `app_flag`,
            `app_created`,
            `app_updated`
        ) VALUES (
            1,
            'Main Application',
            '*.openovate.com',
            '986e7ce6bec660838491c1cd0a1f4ef6',
            'ba0d2fc7aab09dfa3463943c0aaa8551',
            '".implode(',', array(
                'public_profile',
                'public_sso',
                'personal_profile',
                'user_profile'
            ))."',
            'http://openovate.com/',
            1, NULL, 0, '2015-08-21 00:00:00', '2015-08-21 00:00:00'
        )";

        $queries[] = "INSERT INTO `auth` (
            `auth_id`,
            `auth_slug`,
            `auth_password`,
            `auth_token`,
            `auth_secret`,
            `auth_permissions`,
            `auth_facebook_token`,
            `auth_facebook_secret`,
            `auth_linkedin_token`,
            `auth_linkedin_secret`,
            `auth_twitter_token`,
            `auth_twitter_secret`,
            `auth_google_token`,
            `auth_google_secret`,
            `auth_active`,
            `auth_type`,
            `auth_flag`,
            `auth_created`,
            `auth_updated`
        ) VALUES (
            1,
            'admin@openovate.com',
            MD5('admin'),
            '986e7ce6bec660838491c1cd0a1f4ef6',
            'ba0d2fc7aab09dfa3463943c0aaa8551',
            '".implode(',', array(
                'public_profile',
                'public_sso',
                'personal_profile',
                'user_profile'
            ))."',
            NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, 0,
            '2015-09-11 23:05:17', '2015-09-11 23:05:17'
        )";

        $queries[] = "INSERT INTO `profile` (
            `profile_id`,
            `profile_name`,
            `profile_email`,
            `profile_phone`,
            `profile_detail`,
            `profile_company`,
            `profile_job`,
            `profile_gender`,
            `profile_birth`,
            `profile_website`,
            `profile_facebook`,
            `profile_linkedin`,
            `profile_twitter`,
            `profile_google`,
            `profile_active`,
            `profile_type`,
            `profile_flag`,
            `profile_created`,
            `profile_updated`
        ) VALUES (
            1,
            'Admin',
            'admin@openovate.com',
            '+63 (2) 654-5110',
            NULL, NULL, NULL, NULL, NULL,
            NULL, NULL, NULL, NULL, NULL, 1, NULL,
            0, '2015-09-11 23:05:16', '2015-09-11 23:05:16')";

        $queries[] = "INSERT INTO `app_profile` (`app_profile_app`, `app_profile_profile`) VALUES (1, 1)";
        $queries[] = "INSERT INTO `auth_profile` (`auth_profile_auth`, `auth_profile_profile`) VALUES (1, 1)";

        //now call the queries
        foreach($queries as $query) {
            $lines = explode("\n", $query);

            foreach($lines as $i => $line) {
                if(strpos($line, '--') === 0 || !trim($line)) {
                    unset($lines[$i]);
                    continue;
                }
            }

            $query = trim(implode("\n", $lines));

            if(!$query) {
                continue;
            }

            $main->query($query);
        }
    }
737728
def setPermissions(self, dbName, access) :
        """"""
        import json

        if not self.URL :
            raise CreationError("Please save user first", None, None)

        rights = []
        if access :
            rights.append("rw")

        rights = ''.join(rights)

        if not self.connection.hasDatabase(dbName) :
            raise KeyError("Unknown database: %s" % dbName)

        url = "%s/database/%s" % (self.URL, dbName)
        r = self.connection.session.put(url, data = json.dumps({"grant": rights}, default=str))
        if r.status_code < 200 or r.status_code > 202 :
            raise CreationError("Unable to grant rights", r.content)
896400
public function add()
    {
        $this->request->allowMethod(['get', 'post']);

        $menu = $this->Menus->newEntity();
        if ($this->request->is('post') && !empty($this->request->data)) {
            $this->Menus->patchEntity($menu, $this->request->data);
            if ($this->Menus->save($menu)) {
                $this->Flash->success(__d('wasabi_core', 'The menu <strong>{0}</strong> has been created.', $this->request->data['name']));
                $this->redirect(['action' => 'index']);
                return;
            } else {
                $this->Flash->error($this->formErrorMessage);
            }
        }
        $this->set('menu', $menu);
    }
530404
def add_server(self, name, ip, port):
        """"""
        new_server = {
            'key': name,  # Zeroconf name with both hostname and port
            'name': name.split(':')[0],  # Short name
            'ip': ip,  # IP address seen by the client
            'port': port,  # TCP port
            'username': 'glances',  # Default username
            'password': '',  # Default password
            'status': 'UNKNOWN',  # Server status: 'UNKNOWN', 'OFFLINE', 'ONLINE', 'PROTECTED'
            'type': 'DYNAMIC'}  # Server type: 'STATIC' or 'DYNAMIC'
        self._server_list.append(new_server)
        logger.debug("Updated servers list (%s servers): %s" %
                     (len(self._server_list), self._server_list))
1055065
def add_grant(self, grant):
        """"""
        if not isinstance(grant, AccessTokenGrant):
            raise ValueError('Grant must be an instance of AccessTokenGrant.')
        self.grants.append(grant)
6092
def insertSQL(conn, sql, args=None):
    '''
    
    '''
    with doCursor(conn) as cursor:
        cursor.execute(sql, args)
        id = conn.insert_id()
        return id
602294
def set_mysql_connection(host='localhost', user='pyctd_user', password='pyctd_passwd', db='pyctd', charset='utf8'):
    """"""
    set_connection('mysql+pymysql://{user}:{passwd}@{host}/{db}?charset={charset}'.format(
        host=host,
        user=user,
        passwd=password,
        db=db,
        charset=charset)
    )
1088362
def add(self, key):
        '''
        
        '''
        encodedKey = json.dumps(key)
        with self.connect() as conn:
            with doTransaction(conn):
                sql = 'INSERT IGNORE INTO ' + self.table + ' (name) VALUES (%s)'
                return insertSQL(conn, sql, args=[encodedKey])
1090294
public function Add() {
      $this->Permission('Garden.Users.Add');
      
      // Page setup
      $this->AddJsFile('user.js');
      $this->Title(T('Add User'));
      $this->AddSideMenu('dashboard/user');
      
      $RoleModel = new RoleModel();
      $AllRoles = $RoleModel->GetArray();
      
      // By default, people with access here can freely assign all roles
      $this->RoleData = $AllRoles;
      
      $UserModel = new UserModel();
      $this->User = FALSE;

      // Set the model on the form.
      $this->Form->SetModel($UserModel);
      
      try {
         // These are all the 'effective' roles for this add action. This list can
         // be trimmed down from the real list to allow subsets of roles to be edited.
         $this->EventArguments['RoleData'] = &$this->RoleData;

         $this->FireEvent("BeforeUserAdd");

         if ($this->Form->AuthenticatedPostBack()) {

            // These are the new roles the creating user wishes to apply to the target
            // user, adjusted for his ability to affect those roles
            $RequestedRoles = $this->Form->GetFormValue('RoleID');

            if (!is_array($RequestedRoles)) $RequestedRoles = array();
            $RequestedRoles = array_flip($RequestedRoles);
            $UserNewRoles = array_intersect_key($this->RoleData, $RequestedRoles);

            // Put the data back into the forum object as if the user had submitted 
            // this themselves
            $this->Form->SetFormValue('RoleID', array_keys($UserNewRoles));

            $NewUserID = $this->Form->Save(array('SaveRoles' => TRUE, 'NoConfirmEmail' => TRUE));
            if ($NewUserID !== FALSE) {
               $Password = $this->Form->GetValue('Password', '');
               $UserModel->SendWelcomeEmail($NewUserID, $Password, 'Add');
               $this->InformMessage(T('The user has been created successfully'));
               $this->RedirectUrl = Url('dashboard/user');
            }

            $this->UserRoleData = $UserNewRoles;
         } else {
            // Set the default roles.
            $this->UserRoleData = C('Garden.Registration.DefaultRoles', array());
         }

      } catch (Exception $Ex) {
         $this->Form->AddError($Ex);
      }
      $this->Render();
   }
691582
def mysql(host, user, passwd, db, charset):
    """"""
    connection_string = database.set_mysql_connection(host=host, user=user, passwd=passwd, db=db, charset=charset)
    test_connection(connection_string)
1065124
public function grant() {
        $aro_id = isset($this->request->params['named']['aro_id']) ? $this->request->params['named']['aro_id'] : null;
        $aco_id = isset($this->request->params['named']['aco_id']) ? $this->request->params['named']['aco_id'] : null;

        if (!$aro_id || !$aco_id) {
            throw new BadRequestException(__d('admin', 'Invalid ARO/ACO IDs'));
        }

        $aro = $this->Aro->getById($aro_id);
        $aco = $this->Aco->getById($aco_id);

        if (!$aro || !$aco) {
            throw new NotFoundException(__d('admin', 'Invalid ARO/ACO Records'));
        }

        $aroAlias = $aro['RequestObject']['alias'];
        $acoAlias = $aco['ControlObject']['alias'];

        if (!empty($aro['Parent']['alias'])) {
            $aroAlias = $aro['Parent']['alias'] . '/' . $aroAlias;
        }

        if ($this->Acl->allow($aroAlias, $acoAlias)) {
            $this->AdminToolbar->logAction(ActionLog::CREATE, $this->Permission, $this->Acl->adapter()->Permission->id, sprintf('Granted %s access to %s', $aroAlias, $acoAlias));
            $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully granted %s permission to %s', array($aroAlias, $acoAlias)));
        } else {
            $this->AdminToolbar->setFlashMessage(__d('admin', 'Failed to grant %s permission to %s', array($aroAlias, $acoAlias)), 'is-error');
        }

        $this->redirect(array('action' => 'index'));
    }
1051354
def add_to_inventory(self):
        """"""
        host = self.db_attrs.pop(A.database.HOST)
        self.stack.add_host(
                host,
                self.groups,
                self.db_attrs
                )
550699
def grantTablePermission(self, login, user, table, perm):
    
    self.send_grantTablePermission(login, user, table, perm)
    self.recv_grantTablePermission()
204525
def connect_to_database_odbc_mysql(self,
                                       database: str,
                                       user: str,
                                       password: str,
                                       server: str = "localhost",
                                       port: int = 3306,
                                       driver: str = "{MySQL ODBC 5.1 Driver}",
                                       autocommit: bool = True) -> None:
        """"""
        self.connect(engine=ENGINE_MYSQL, interface=INTERFACE_ODBC,
                     database=database, user=user, password=password,
                     host=server, port=port, driver=driver,
                     autocommit=autocommit)